{ "name": "Responsive Web Design Principles", "order": 4, "time": "5 hours", "helpRoom": "Help", "challenges": [ { "id": "587d78b0367417b2b2512b07", "title": "Introduction to the Responsive Web Design Challenges", "description": [ [ "", "", "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.", "" ] ], "releasedOn": "", "challengeSeed": [], "tests": [], "type": "Waypoint", "challengeType": 7, "isRequired": false, "titleEs": "", "descriptionEs": [ [] ], "titleFr": "", "descriptionFr": [ [] ], "titleDe": "", "descriptionDe": [ [] ] }, { "id": "587d78b0367417b2b2512b08", "title": "Create a Media Query", "description": [ "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 smaller than 100px:", "@media (max-width: 100px) { /* CSS Rules */ }", "Remember, the CSS inside the media query is applied only if the media type matches that of the device being used.", "
", "Add a media query, so that the p tag has a font-size of 10px when the device's height is smaller than 800px." ], "challengeSeed": [ "", "", "

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus quis tempus massa. Aenean erat nisl, gravida vel vestibulum cursus, interdum sit amet lectus. Sed sit amet quam nibh. Suspendisse quis tincidunt nulla. In hac habitasse platea dictumst. Ut sit amet pretium nisl. Vivamus vel mi sem. Aenean sit amet consectetur sem. Suspendisse pretium, purus et gravida consequat, nunc ligula ultricies diam, at aliquet velit libero a dui.

" ], "tests": [ "assert($('p').css('font-size') == '10px', 'message: Your p tag should have the font-size of 10px when the device height is smaller than 800px.');", "assert(code.match(/@media \\(max-height:\\s*?800px\\)/g), 'message: Declare an @media query for devices with height less than 800px.');" ], "type": "waypoint", "solution": [], "hints": [], "challengeType": 0, "translations": {} }, { "id": "587d78b1367417b2b2512b09", "title": "Make an Image Responsive", "description": [ "Making images responsive with CSS is actually very simple. Instead of applying an absolute width to an element:", "img { width: 720px; }", "You can use:", "
img {
max-width: 100%;
display: block;
height: auto;
}
", "The max-width property of 100% scales the image to fit the width of its container, but the image won't stretch wider than its original width. Setting the display property to block changes the image from an inline element (its default), to a block element on its own line. The height property of auto keeps the original aspect ratio of the image.", "
", "Add style rules for the img tag to make it responsive to the size of its container. It should display as a block-level element, it should fit the full width of its container without stretching, and it should keep its original aspect ratio." ], "challengeSeed": [ "", "", "\"freeCodeCamp" ], "tests": [ "assert(code.match(/max-width:\\s*?100%;/g), 'message: Your img tag should have a max-width set to 100%.');", "assert($('img').css('display') == 'block', 'message: Your img tag should have a display set to block.');", "assert(code.match(/height:\\s*?auto;/g), 'message: Your img tag should have a height set to auto.');" ], "type": "waypoint", "challengeType": 0, "solutions": [], "hints": [], "translations": {} }, { "id": "587d78b1367417b2b2512b0a", "title": "Use a Retina Image for Higher Resolution Displays", "description": [ "The simplest way to make your images appear \"retina\" (and optimize them for retina displays) is to define their width and height values as only half of what the original file is.", "Here is an example of an image that is only using half of the original height and width:", "
<style>
img { height: 250px; width: 250px; }
</style>
<img src="coolPic500x500" alt="A most excellent picture">
", "
", "Set the width and height of the img tag to half of their original values. In this case, both the original height and the original width are 200px." ], "challengeSeed": [ "", "", "\"freeCodeCamp" ], "tests": [ "assert($('img').css('width') == '100px', 'message: Your img tag should have a width of 100 pixels.');", "assert($('img').css('height') == '100px', 'message: Your img tag should have a height of 100 pixels.');" ], "type": "waypoint", "challengeType": 0, "solutions": [], "hints": [], "translations": {} }, { "id": "587d78b1367417b2b2512b0c", "title": "Make Typography Responsive", "description": [ "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:", "", "
", "Set the width of the h2 tag to 80% of the viewport's width and the width of the paragraph as 75% of the viewport's smaller dimension." ], "challengeSeed": [ "", "", "

Importantus Ipsum

", "

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus quis tempus massa. Aenean erat nisl, gravida vel vestibulum cursus, interdum sit amet lectus. Sed sit amet quam nibh. Suspendisse quis tincidunt nulla. In hac habitasse platea dictumst. Ut sit amet pretium nisl. Vivamus vel mi sem. Aenean sit amet consectetur sem. Suspendisse pretium, purus et gravida consequat, nunc ligula ultricies diam, at aliquet velit libero a dui.

" ], "tests": [ "assert(code.match(/h2\\s*?{\\s*?width:\\s*?80vw;\\s*?}/g), 'message: Your h2 tag should have a width of 80vw.');", "assert(code.match(/p\\s*?{\\s*?width:\\s*?75vmin;\\s*?}/g), 'message: Your p tag should have a width of 75vmin.');" ], "type": "waypoint", "solutions": [], "hints": [], "challengeType": 0, "translations": {} } ] }