Css Units: REM, VH & VW Adrian Horsham.

Slides:



Advertisements
Similar presentations
LIS650 lecture 4 Thomas Krichel today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors.
Advertisements

Copenhagen, 6 December 2004 Modern CSS Principles Miruna Bădescu Finsiel Romania.
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.
Web Pages and Style Sheets Bert Wachsmuth. HTML versus XHTML XHTML is a stricter version of HTML: HTML + stricter rules = XHTML. XHTML Rule violations:
CSS Basics LIS Webteam April 8, Why CSS? What’s wrong with HTML? Structure vs Style Early web design used hacks to style webpages with HTML – like.
The Power of Tables They aren't just for sitting stuff on anymore...
RESPONSIVE DESIGN Sources: Kadlec, T. (2012). Implementing responsive design. Berkeley, California: New Riders Publishing. MarcotteMarcotte, E. (2010).
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.
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.
CONCEPTS FOR FLUID LAYOUT Web Page Layout. Website Layouts Most websites have organized their content in multiple columns (formatted like a magazine or.
The Missing Manual MARGINS, PADDING, & BORDERS—CHAPTER 7.
Chapter 12 Cascading Style Sheets: Part II The Web Warrior Guide to Web Design Technologies.
 This presentation introduces the following: › 3 types of CSS › CSS syntax › CSS comments › CSS and color › The box model.
Page Layout with CSS Learning Web Design: Chapter 16.
CSS. HTML: Looking Back HTML dictates order, structure, and function Does very little to specify layout or visual rendering.
WEB DESIGN AND PROGRAMMING Advanced CSS Techniques.
Lesson 05 // Web Design, Layout & Structure 1.Web Design/Designer-Coder Relationship 2.Fixed vs Fluid Website Layouts 3.Screen Resolutions.
Cascading Style Sheets Level 2. Course Objectives, Session 1 Level 1 Quick Review Chapter 8: Adding Graphics to Web Pages Chapter 9: Sprucing Up Your.
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.
Cascading Style Sheets Positioning Controls Visibility.
CSU - DCE Introduction to CSS CSS Length - Fort Collins, CO Copyright © XTR Systems, LLC Cascading Style Sheets - Specifying Length Instructor:
Today’s objectives  Announcements  Positioning  Measurement units.
CS 120: Introduction to Web Programming Lecture 10: Extra Features and Website Design Part 1 Tarik Booker CS 120 California State University, Los Angeles.
>> CSS Layouts. Recall Properties of Box – Border (style, width, color) – Padding – Margin – Display – Background – Dimension Welcome Padding Area Border.
CONCEPTS FOR FLUID LAYOUT Web Page Layout. Essential Questions What challenges do mobile devices present to Web designers? What are the basic concepts.
CSS.
Laying out Elements with CSS
The Box Model in CSS Web Design – Sec 4-8
4.01 Cascading Style Sheets
The Box Model in CSS Web Design – Sec 4-8
CSS Layouts: Grouping Elements
HTML5 Level II Session V Chapter 8 - How to Use Responsive Web Design (RWD)
Webpage layout using CSS
Concepts for fluid layout
Scrolling Down vs. Multiple Pages
Cascading Style Sheets
The Box Model in CSS Web Design – Sec 4-8
CS 0134 (term 2181) Jarrett Billingsley
Creating a Baseline Grid
RESPONSIVE WEB DESIGN.
>> CSS Layouts.
CSS.
CSS Applications to XML 19-Sep-18.
Cascading Style Sheets
Responsive Web Design (RWD)
Styles and the Box Model
Controlling Layout with Style Sheets
Second CSS Lecture Applications to XML
MORE Cascading Style Sheets (The Positioning Model)
Responsive Web Design (RWD)
Session VI Chapter 8 - How to Use Responsive Web Design (RWD)
Chapter 8 - How to Use Responsive Web Design (RWD)
Cascading Style Sheets
Responsive Web Design (RWD)
More CSS 22-Feb-19.
Floating and Positioning
Positioning.
CSS.
CSS Boxes CS 1150 Fall 2016.
CS3220 Web and Internet Programming More CSS
Concepts for fluid layout
4.01 Cascading Style Sheets
CSS Applications to XML 20-May-19.
The div Element and CSS for layout
CSS Applications to XML 3-Jul-19.
Positioning Boxes Using CSS
Cascading Style Sheets CSS LAYOUT WITH GRID
CS3220 Web and Internet Programming More CSS
Presentation transcript:

Css Units: REM, VH & VW Adrian Horsham

Css unit Basics Many properties use the length values including width, margin, padding, font-size, border-width To set a length you use a number followed by a unit of length ex. 12px, 80% or 2em You cannot leave a space between the number or the unit or css will not read it If you want a value of 0 you can leave it as “0” without the unit

Css units Pixels are not the only units you can use when designing on the web. Other popular units used include ems and percentages which are good for responsive design as they change with a devices size There are many others including vh and vw that depend on a browsers size and REM which relies on the root element

Relative lengths

Putting it in context Lets say we have a viewport of 1000px (width) by 800px (height): vw – Represents 1% of the viewport’s width. In our case 50vw = 500px. vh – 1% percentage of the window’s height. 50vh = 400px. vmin – 1% percentage of the minimum of the two. In our example 50vmin = 400px since we are in landscape mode. vmax – 1% percentage of the bigger dimension. 50vmax = 500px.

Css units For some CSS properties you can use negative lengths, this is useful if you need to move something outside of it box but want to keep it grouped When using length units you also have to keep in mind whether the length is relative or absolute. Elements such a “px” are absolute and will always be the same Elements like “rem” are relative and change depending on another element

Browser support Before using any of the other elements it’s a good idea to check and see if you browser supports it. If you are making a site that will be used by a large group of people it is a good idea to make sure it works on multiple browsers Browsers also have versions so you may want to make sure something important on the site isn't only accessible on something most people don’t have.

Support for css units

Example of VH Relative to 1% of the height of the viewport The vh unit is interesting in that 1 unit reflects 1/100th the height of the viewport To make an element the full height of the viewport, you'd set it to width:100vw. Example- http://codepen.io/24seven/pen/vKkJPd

Example of Vw Relative to 1% of the width of the viewport The vw unit is interesting in that 1 unit reflects 1/100th the width of the viewport. To make an element the full width of the viewport, you'd set it to width:100vw. Example- http://codepen.io/24seven/pen/NAgvkm

Example of vmax/min You can also set things by vmin/ vmax 1vmin = 1vw or 1vh, whichever is smallest 1vmax = 1vw or 1vh, whichever is largest This option gives you more options when resizing your browser to keep things proportional

Example of rem Relative to font-size of the root element If the html font size is 25px, 1rem = 25px. Example- http://codepen.io/24seven/pen/rLwzXV

Is it perfect? The Rem tag by default is 16px which is set by the html tag Once you start dealing with big numbers 16 can be difficult to work with. 59px (target) / 16px (context) = 33.5625 (result) One work around to that is to set the html tag to 62.5% 62.5% of 16= 10px which is a lot easier to work with

Is it perfect? It is a step closer but still has some usability issues. When scaling in relation to a root element or a device width things can become too big or too small at certain sizes. Example- http://codepen.io/chriscoyier/full/tvheK/

Other Uses Other than fonts you can use you can use vw and vh for for layout too. If you use 100% width, it wont fill the browser as the html and body padding sizes are different across browsers If you use 100vw, it will always take up the full width of your browser as it is based on the viewport Example- http://codepen.io/24seven/pen/KrvpWK

Other Uses With the viewpoint lengths child sizes are relative to the browser and not the parent. If you use 100% width in a container, it wont fill the whole width of browsers. Instead it fills the width of its parent If you use 100vw in a container it will break out and take up the full width of your browser Example- http://codepen.io/24seven/pen/yJoNjO