freeCodeCamp 响应式网页设计的认证课程第十一章。响应式设计使得你的网页适应不同屏幕尺寸的显示。在通过创建一架钢琴来学习响应式网页设计的课程中,围绕一架钢琴编写代码学习 CSS 响应式设计,同时学会媒体条件和伪选择器的知识。以下为我在学习和实战练习过程中所做的笔记,可供参考。
一、重点 CSS 代码
Browsers can apply default margin and padding values to specific elements. To make sure your piano looks correct, you need to reset the box model:
1 | html { |
You have reset the html
box model, you need to pass that on to the elements within as well.
The ::before
selector creates a pseudo-element which is the first child of the selected element, while the ::after
selector creates a pseudo-element which is the last child of the selected element:
1 | *, ::before, ::after { |
钢琴、琴键轮廓 🎹:
1 | #piano { |
To create the black keys, add a new .key.black--key::after
selector. This will target the elements with the class key black--key
, and select the pseudo-element after these elements in the HTML.
The content
property is used to set or override the content of the element. By default, the pseudo-elements created by the ::before
and ::after
pseudo-selectors are empty, and the elements will not be rendered to the page:
1 | .key.black--key::after { |
Styling the logo:
1 | <div style="position: relative; width: 100%; height: 0; padding-bottom: 75%;"> |
@media 属性 Make it responsive:
1 | @media (max-width: 768px) { |