Basic Responsive Design Techniques. Let’s take a look at this basic layout. It has a header and two columns of text, in a box that is centered on the.

Slides:



Advertisements
Similar presentations
Coding a Responsive HTML
Advertisements

Use Tables for Layout Control Day 7. You will learn to: Understand Tables Create a Simple Table Modify Your Tables Appearance Create Page Layouts with.
15 LAYOUT Controlling the position of elements Creating site layouts Designing for different sized screens.
CSS Layout Crash Course An Advance CSS Tutorial. Inline vs. Block Many HTML elements have a default display setting of Block. Block elements take up the.
Cascading Style Sheets
Basic use of columns is to organize a list of navigation links down the left or right side of the page next to a main content area. (Fig. 1) Another common.
Tutorial 6 Creating Fixed-Width Layouts
XP 1 Working with Cascading Style Sheets Creating a Style for Online Scrapbooks Tutorial 7.
MORE Cascading Style Sheets (The Positioning Model)
Working with Cascading Style Sheets. 2 Objectives Introducing Cascading Style Sheets Using Inline Styles Using Embedded Styles Using an External Style.
Responsive Web Design Design websites so that they can adapt to different devices seamlessly. Image by Muhammed RafizeldiMuhammed Rafizeldi.
LEARN THE QUICK AND EASY WAY! VISUAL QUICKSTART GUIDE HTML and CSS 8th Edition Chapter 12: Building Responsive Webpages.
TUTORIAL 8: Enhancing a Web Site with Advanced CSS
CIT 256 Mobile Web Development Dr. Beryl Hoffman.
CSS Box Model. What is the CSS Box Model? The “Box Model” is a tool we use to lay out our web pages in a number of individual "boxes" or "containers".
Tutorial 6 Creating Tables and CSS Layouts. Objectives Session 6.1 – Create a data table to display and organize data – Modify table properties and layout.
Working with Cascading Style Sheets. Introducing Cascading Style Sheets Style sheets are files or forms that describe the layout and appearance of a document.
XP Tutorial 7New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with Cascading Style Sheets Creating a Style for Online Scrapbooks.
Layouts with CSS Web Design – Section 4-12 Part or all of this lesson was adapted from the University of Washington’s “Web Design & Development I” Course.
ITP 104.  While you can do things like this:  Better to use styles instead:
CSS Sprites. What are sprites? In the early days of video games, memory for graphics was very low. So to make things load quickly and make graphics look.
CONCEPTS FOR FLUID LAYOUT Web Page Layout. Website Layouts Most websites have organized their content in multiple columns (formatted like a magazine or.
CSS Netcentric. What is CSS O CSS stands for Cascading Style Sheets O Styles define how to display HTML elements O Styles were added to HTML 4.0 to solve.
CSS = Cascading Style Sheet CSS consists of rules to display, style and decorate HTML elements Why CSS ? – Separate decoration from HTML markup (Ex :,,…)
WEB DESIGN AND PROGRAMMING Advanced CSS Techniques.
Tutorial #6 – Creating Fixed Width Layouts. Tutorial #5 Review – Box Model Every html element is surround by a box Content, Padding, Border, Margin Can.
THE BOX MODEL Putting layouts together with CSS. The Box Model  How would you describe a box?  Container?  Tags or elements are “containers”  puts.
11/12/2015 Box Model Reed Crouch. 11/12/2015  HTML elements can be considered as boxes. In CSS, the term "box model" is used when referring to layout.
CNIT 132 – Week 4 Cascading Style Sheets. Introducing Cascading Style Sheets Style sheets are files or forms that describe the layout and appearance of.
Advanced Topics Lecture 8 Rachel A Ober
CONTROLLING Page layout
Page Layout CHAPTER 5 1 CHARLES WYKE-SMITH: STYLIN’ WITH CSS: A DESIGNER’S GUIDE (3 ND EDITION)
- WE’LL LOOK AT THE POSITION PROPERTY AND HOW CSS RESOLVES CONFLICTS BETWEEN STYLING INSTRUCTIONS The position property; CSS specificity hierarchy.
HTML and Dreamweaver November 11th. Agenda Box Model Displaying and positioning elements – Padding – Margin – Float – Display – Position HTML Demo.
XP Tutorial 7New Perspectives on HTML and XHTML, Comprehensive 1 Working with Cascading Style Sheets Creating a Style for Online Scrapbooks Tutorial 7.
>> CSS Layouts. Recall Properties of Box – Border (style, width, color) – Padding – Margin – Display – Background – Dimension Welcome Padding Area Border.
CHAPTER 15 Floating and Positioning. FLOAT VS. POSITION  Floating an element moves it to the left or right, allowing the following text to wrap around.
CONCEPTS FOR FLUID LAYOUT Web Page Layout. Essential Questions What challenges do mobile devices present to Web designers? What are the basic concepts.
Mimi Opkins.  One of the major benefits of using CSS is that you’re not forced to lay your sites out in tables.  The layout possibilities of CSS give.
Cascading Style Sheets for layout
CSS.
Laying out Elements with CSS
Working with Cascading Style Sheets
Cascading Style Sheets Layout
CSCI 1720 W3.CSS – Part 1 East Tennessee State University Department of Computing CSCI 1720 Intermediate Web Design.
CSS Box Model.
The Box Model in CSS Web Design – Sec 4-8
Cascading Style Sheets Boxes
CSS Layouts: Grouping Elements
Concepts for fluid layout
CS1220 Web Programming Saloni Chacha.
Advanced CSS BIS1523 – Lecture 20.
Cascading Style Sheets for layout
Cascading Style Sheets (Layout)
Creating a Baseline Grid
Objectives Create a reset style sheet Explore page layout designs
Responsive Web Design (RWD)
Styles and the Box Model
Controlling Layout with Style Sheets
MORE Cascading Style Sheets (The Positioning Model)
Responsive Web Design (RWD)
Responsive Framework.
SEEM4570 Tutorial 3: CSS + CSS3.0
Floating and Positioning
Web Page Layout Imran Rashid CTO at ManiWeber Technologies.
Laying out Elements with CSS
Concepts for fluid layout
CSS Box Model.
CSS Box Model.
Positioning Boxes Using CSS
Presentation transcript:

Basic Responsive Design Techniques

Let’s take a look at this basic layout. It has a header and two columns of text, in a box that is centered on the screen. The two columns are in divs that float left and are 48% wide. There is 4% gutter (right side margin) on the first div. Overflow:hidden is set on the article containing the two columns, because we want it to contain the two floated elements. You should be pretty familiar with this technique by now.

Setting widths of elements as percentages, rather than specific pixel widths is the key to creating flexible grids. media queries are the key to most of responsive design. If you add the code above to the bottom of your stylesheet, it will make the #page element 90% as wide as the screen, if the screen is less than 800 pixels wide. If you size the browser window down, you will see the page container pop into place when you get to less than 800 pixels.

Media queries are part of CSS3, and are not supported by old browsers. However, since the purpose of using them is to make websites work properly on mobile devices, and none of the mobile devices are running IE8 or older, it is a non-issue. Also note, that media queries introduce conditional coding into CSS for the first time... (If this is true, apply this rule…)

Media queries are particularly useful when the layout starts to break because the percentage widths no longer make sense. If you make this page narrow enough, then two columns just don’t work. If we add this media query at the bottom, it will remove the float from the columns, making one long column, and get rid of the space for the gutter, if the screen is less than 500px wide.

Now, at a small screen size, we have a one column layout that is easy to read. Media queries can be used in all sorts of creative ways to adjust layouts so that they make sense for different screen sizes. However, working with percentages for widths of everything can be a pain. What if, for example, we want to put a border around those two columns? Notice what happens if we put a 5 pixel border around each column...

We have lost our two column layout entirely. This is because our two columns are 48% wide with a 4% gutter. That totals 100%. Adding the border adds to the width, but that puts us over 100%, and now the column is wrapping down. I could subtract from the 48%, but how much would I subtract? Mixing different types of units becomes really tricky. I could set the border width as a percent, but that could look really dumb at some sizes. and if I want to get padding in there, it gets even worse. So what can you do?

Here is the content inside the box. Blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah Defined width Margin Border Padding Content If we add this box-sizing declaration and set it to border-box, it changes the default box model for this element. Normally, padding, border and margin add to the width of any given box (block level element). This effectively changes the model to what it should have been to begin with. Now the width will include the padding and the border, but margin is outside.

Now I can go ahead and add padding and borders in pixels if I want. Note that the box-sizing property is part of CSS3 and won’t work on older browsers. You only have to go a few versions back in Firefox to need the prefix, so I recommend adding them.

This box-sizing declaration is so useful, many designers are simply changing the box model for all elements on the page with a rule like this. You can put this at the top of your stylesheet, or even inside the reset script and all elements will change their box model. Then I can remove it from my.half rule. Please note that you should be careful with this technique. It is not recommended that you go back through old sites and add it, as it can really mess up relationships between elements on those pages that were designed with the old box model.

Now, before we get too excited about all this, we need something else to make it work properly on our mobile devices. Here is what it would look like right now if you were to access it on your mobile phone. How come it is showing the full width version? By default, the mobile browsers zoom out, and show the whole page, making all our careful work for small screens for nothing. Luckily, there is an easy fix. Add this meta-tag in the of your document and it will force the browser to not zoom out.

Next, I am going to add this div to the top of the page, and another one at the bottom of the page. Notice they have unique ID’s Then I will add these two rules to the stylesheet (before the media queries at the bottom). Notice, the bottom one will be hidden by default. Then, inside the media query, I will add these two rules, essentially hiding the top content and showing the bottom content on small screen sizes.

When the screen is full size, you see the content at the top; when the screen is small, you see the content at the bottom. You can imagine that this can be useful when the hierarchy of a page needs to change for the mobile version, however, it comes at a cost. Both the content in the top AND bottom are being downloaded for every browser, even though the user will not even see one of them. In this case, we are just talking a about a few bytes of information, but if there are images, it could be a lot more. You can see this page for yourself at example2example2 There is plenty more to get into, but setting max-width on images, working with media queries, using percentages for widths, and changing the box model for elements are the major techniques used in responsive web design. Just keep in mind the performance issues that come along with these techniques.