CSS - Tablet/Desktop View

Tablet Media Queries

Now that we have established our 'baseline' 'mobile-first' styles, it's time to override those styles under certain conditions - namely the 'device width.' We'll do this by querying(asking) our media about some of its characteristics such as it's width. We'll establish rules based on these results. Here's a simple example:

@media screen and (min-width: 768px) {
  header {
    background: red;
  }
}

Using your dev tools, try toggling your device emulator between a phone and tablet. You should see that the background-color of your header is toggling changing. Looking ๐Ÿ‘†๐Ÿพ, we see that if our device is a screen (as opposed to print, etc.), and the device's screen size is more than 768px, the header has a different rule that is being applied. Make sense?

<nav>

Now, let's do something a bit more practical and hide our ๐Ÿ”, whilst showing our navigation horizontally. To accomplish this, let's use a couple more 'state' classes:

  • .is-hidden--tablet / Hide the ๐Ÿ”. /

  • .is-shown--tablet / Show the . /

๐Ÿ‘†๐Ÿพwill be applied inside of a @media query.

Using responsive utility classes.

Finally, just add some flexbox to get that <nav> looking nice.

Note: Don't get married ๐Ÿ’’ to 768px. We are just using that as a quick example. In a 'detail-oriented' design, you would just gauge your @medias by shrinking and expanding your screen and making decisions about when things 'look bad,' etc.

section p

One other thing that we can easily fix for our 'tablet' view is to limit how wide the our <p> tag gets in our <section>s.

Hint: Just include ๐Ÿ‘†๐Ÿพinside that same @media we made earlier.

Desktop Media Queries

For a 'desktop' view, let's just choose 1024px. Again, for a 'real design,' you may want to play with screen widths and be much more particular.

We can simply change our header to use flex-direction: row;, and throw some margin-right on the figure - maybe some padding, etc.

.hero

We'll probably want to use a larger 'lorem picsum' image, and we could increase the height or .hero to 40vh, etc.

main

๐Ÿ™†๐Ÿพโ€โ™‚๏ธHere's where things get interesting. We want to create our '3-column' layout for the sections inside of main. First, we'll need to use a <div> to wrap those 3 <section>s to that .hero doesn't get changed. This <div> serves as a flex 'container,' and just by applying display: flex we get most of our job done!

I've added an extra <p> ๐Ÿ‘†๐Ÿพ. This throws off the alignment of our .btn-reads. To fix that, we'll need to make our <section>s be both 'flex children' and* 'flex parents'. You can review all of the details of this implementation and the other parts of the 'desktop' view in the video below:

Desktop view for responsive design layout.

Last updated