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>
<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.
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
section pOne 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
header
headerFor 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
.heroWe'll probably want to use a larger 'lorem picsum' image, and we could increase the height or .hero to 40vh, etc.
main
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:
Last updated