CSS 是前端开发中不可或缺的一部分,掌握 CSS 的基础知识和技巧对于前端开发者来说至关重要。本文将通过 20 道常见的 CSS 面试题,帮助你巩固 CSS 知识,准备面试。
box-sizing 属性来设置盒模型为 IE 盒模型。深色版本
1element { 2 box-sizing: border-box; 3} div。.class。#id。[type="text"]。:hover。div p。clear:both 或者 clearfix 技巧。display: flex。display: grid。overflow: auto。深色版本
1.container { 2 display: flex; 3 justify-content: center; 4} 深色版本
1.container { 2 display: flex; 3 align-items: center; 4} 深色版本
1.grid-container { 2 display: grid; 3 grid-template-columns: repeat(3, 1fr); 4 grid-gap: 10px; 5} 深色版本
1.flex-container { 2 display: flex; 3 justify-content: center; 4 align-items: center; 5} 深色版本
1@media screen and (max-width: 600px) { 2 .example { 3 background-color: blue; 4 } 5} 深色版本
1:root { 2 --main-color: red; 3} 4.example { 5 color: var(--main-color); 6} @keyframes 规则来定义动画的关键帧,并使用 animation 属性来应用动画。深色版本
1@keyframes fadeIn { 2 from { opacity: 0; } 3 to { opacity: 1; } 4} 5 6.example { 7 animation-name: fadeIn; 8 animation-duration: 2s; 9} :hover、:focus 等。它们不是真正的类,而是用来表示某种状态。gap 属性。grid-gap 或 row-gap、column-gap。overflow 不为 visible 或使用 display: flex 或 display: grid 来创建 BFC。border-radius 属性来创建圆形按钮。深色版本
1.circle-button { 2 padding: 10px 20px; 3 border-radius: 50%; 4 background-color: blue; 5 color: white; 6}