Slide 1
Mobile Web Basics
Joan Boone
jpboone@email.unc.edu
Mobile Web Basics Joan Boone jpboone@email.unc.edu Slide 1 Topics - - PowerPoint PPT Presentation
INLS 573 Mobile Web Development Mobile Web Basics Joan Boone jpboone@email.unc.edu Slide 1 Topics Part 1: Viewports Part 2: Responsive Web Design Patterns Part 3: CSS Media Queries Part 4: Breakpoints, Best Practices Slide 2 What is a
Slide 1
Joan Boone
jpboone@email.unc.edu
Slide 2
Slide 3
the screen
small screens
same readability and accuracy on screens of different sizes
Viewport Sizer: What is a Viewport?
Slide 4
Source: Vexing Viewports (2012, dated but historically useful) 320x480 pixels 640x960 pixels
In addition to different screen sizes (or viewports), devices often have different screen resolutions. Both devices have the same 2” wide screens, but different resolutions
4 times as many pixels into the same space as the one on the left
text that is small and difficult to read without zooming
Slide 5
By default, mobile browsers will scale down an entire web page to fit the viewport of the device.
w3schools: The Viewport
Without viewport meta tag With viewport meta tag
Recall Hillsborough BBQ...
Solution: viewport meta tag
Slide 6
<meta name=”viewport” content=”initial-scale=1.0, width=device-width” />
Handles the resolution problem by setting the zoom level when page is first loaded. Defines a 1:1 relationship between CSS pixels and device-independent pixels. Handles the screen size problem by telling the browser to set the width of the page to the screen width of the device in device-independent pixels. Source: web.dev: Responsive Web Design Basics
A pixel is not a pixel...
the screen resolution (or pixel density). These pixels allow for UI elements to look uniform on screens with different resolutions
The ratio of CSS pixels to device independent pixels is the page's scale factor, or zoom.
Slide 7
Several ways...
Chrome/Firefox Developer Tools
More information on setting the viewport
Slide 8
Avoid usability issues
Additional rules
– screen dimensions and widths vary widely across devices
else, e.g., the container for an element. Examples include em, rem, and percentages. Use the PX to EM conversion tool.
Slide 9
Slide 10
Source: Media Queries
Slide 11
Source: Media Queries
Slide 12
Slide 13
Slide 14
device has the characteristics specified by the query, then change the style rules used to render the content.
specified in media queries is min-width. Many other media features: Media Queries specification (Level 4)
width are defined first, followed by one or more media queries for progressively larger screen widths.
defined in the style sheet.
will apply to any screen width.
Responsive Web Design by Ethan Marcotte “Fluid grids, flexible images, and media queries are the three technical ingredients for responsive web design”
Slide 15
no-layout.html
Without any responsive layout rules, elements are laid out in the normal source order defined by the HTML. In other words, they are laid out in the same order as specified in the HTML.
Slide 16
In a responsive layout, we want our content to be
“no layout” example. For the larger screen, we want to spread the same content across 3 columns. To do this, add a media query to the style sheet that modifies the layout when the min-width is 64em (or 1024px). In other words, when the screen (or browser window) is wider than 64 em, change the layout to 3 columns.
Slide 17
The style sheet is mobile-first because the first set of style rules are for the small screen, and the media query that follows these rules handles the layout for the larger screen.
@media (min-width: 64em) { /* style rules go here */ }
Slide 18
<div class="wrapper"> <aside class="side1"> <p>ASIDE1: Sed ut perspiciatis ...</p> </aside> <section> <p>MAIN SECTION: Lorem ipsum ...</p> </section> <aside class="side2"> <p>ASIDE2: Sed ut perspiciatis ...</p> </aside> </div>
Slide 19
/* mobile-first */ .wrapper { display: flex; flex-direction: column; } responsive-flex-layout.html @media (min-width: 64em) { /* 1024px */ .wrapper { flex-direction: row } }
Slide 20
In this example, the content appears evenly distributed – both <asides> are the same size and the middle section takes up the remaining space
But, the browser will allocate as much space as needed to ensure your content is readable, unless you override the proportions.
Slide 21
Slide 22
Media queries define breakpoints – points at which you want the style rules for presentation and/or layout of your page to change based on device characteristics. How to set breakpoints? Not based on device characterstics!
the experience as more screen real estate becomes available
web.dev: How to choose breakpoints
screen first, then expand the screen until a breakpoint becomes
Slide 23
Do you need a media query at all?
Media Queries Best Practices
a more consistent result if the user has larger text than you expected.
zoom level, resulting in better readability and accessibility.
follow the document source order, so it may be confusing for those with poor vision Sources:
Slide 24
Source: Mobile first (Zurb University)
The Woes of Developing from the Top-Down The Smartness
the Bottom-Up Book: Mobile First by Luke Wroblewski (2011) Too much content, too many images, hero images, too much text,...