FreeCodeCamp: Responsive Web Design

Walk-through and solutions. This article will walk you through freecodecamp.org “Responsive Web Design” challenges.

Responsive Web Design — FreeCodeCamp

Today, there are many types of devices that can access the web. They range from large desktop computers to small mobile phones. These devices have different screen sizes, resolutions, and processing power. Responsive Web Design is an approach to designing web content that responds to the constraints of different devices. The page structure and CSS rules should be flexible to accommodate these differences. In general, design the page’s CSS to your target audience. If you expect most of your traffic to be from mobile users, take a ‘mobile-first’ approach. Then add conditional rules for larger screen sizes. If your visitors are desktop users, then design for larger screens with conditional rules for smaller sizes. CSS gives you the tools to write different style rules, then apply them depending on the device displaying the page. This section will cover the basic ways to use CSS for Responsive Web Design. — By FreeCodeCamp

Let’s start!

You can also watch this video where I solve the Responsive Web Design Challenges.

Responsive Web Design — FreeCodeCamp

💡Media Queries are a new technique introduced in CSS3 that change the presentation of content based on different viewport sizes. The viewport is a user’s visible area of a web page, and is different depending on the device used to access the site.

Media Queries consist of a media type, and if that media type matches the type of device the document is displayed on, the styles are applied. You can have as many selectors and styles inside your media query as you want.

Here’s an example of a media query that returns the content when the device’s width is less than or equal to 100px:

@media (max-width: 100px) { /* CSS Rules */ }

and the following media query returns the content when the device’s height is more than or equal to 350px:

@media (min-height: 350px) { /* CSS Rules */ }

Remember, the CSS inside the media query is applied only if the media type matches that of the device being used.

Solution →

@media (max-height: 800px) {
p { font-size: 10px; }
}

💡Making images responsive with CSS is actually very simple. Instead of applying an absolute width to an element:

img { width: 720px; }

Solution →

img{
max-width: 100%;
display: block;
height:auto;
}

💡With the increase of internet connected devices, their sizes and specifications vary, and the displays they use could be different externally and internally. Pixel density is an aspect that could be different on one device from others and this density is known as Pixel Per Inch(PPI) or Dots Per Inch(DPI). The most famous such display is the one known as a “Retina Display” on the latest Apple MacBook Pro notebooks, and recently iMac computers. Due to the difference in pixel density between a “Retina” and “Non-Retina” displays, some images that have not been made with a High-Resolution Display in mind could look “pixelated” when rendered on a High-Resolution display.

The simplest way to make your images properly appear on High-Resolution Displays, such as the MacBook Pros “retina display” is to define their width and height values as only half of what the original file is.

Solution → img{ height:100px;width:100px;}

💡Instead of using em or px to size text, you can use viewport units for responsive typography. Viewport units, like percentages, are relative units, but they are based off different items. Viewport units are relative to the viewport dimensions (width or height) of a device, and percentages are relative to the size of the parent container element.

The four different viewport units are:

  • vw: 10vw would be 10% of the viewport's width.
  • vh: 3vh would be 3% of the viewport's height.
  • vmin: 70vmin would be 70% of the viewport's smaller dimension (height vs. width).
  • vmax: 100vmax would be 100% of the viewport's bigger dimension (height vs. width).

Solution →

h2 {width: 80vw;}
p {width: 75vmin;}

Are you still here?! Well, if you are, congratulations! You just finished the “Responsive Web Design” by freecodecamp!

If you are interested for more freeCodeCamp challenges and solutions you can check the articles in my profile.

Disclaimer: Definitions, instructions and examples are by freeCodeCamp.org

Would you like to get me a coffee?!☕️

You can do that here → paypal.me/eleftheriabatsou

But If you can’t, that’s ok too 😍.

It would be nice to subscribe to my YouTube channel. It’s free and it helps creating more content.

Thanks for reading, have an awesome day!

Youtube | Codepen | GitHub | Twitter | Site | Instagram

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Eleftheria Batsou

Hi, I’m a community manager and an app developer/UX researcher by passion. I love learning, teaching and sharing. My passions are tech, UX, arts & working out.