本文共 1629 字,大约阅读时间需要 5 分钟。
CSS提供三种方式设置样式:
<style>属性指定CSS代码。 hello css
<head>标签内定义<style>标签,包含CSS代码。 选择器分为基础选择器和复合选择器。
div { margin: 10px; } .red { color: red; } #标识唯一ID。 #header { background: black; } *表示所有元素。 * { margin: 0; } div > p { color: blue; } div > p { color: blue; } div, p { color: blue; } a:hover { color: red; } body { font-family: Arial, sans-serif; font-size: 16px; } font属性。 body { font: 14px Arial, sans-serif; } p { color: #000; } .text-center { text-align: center; } .underline { text-decoration: underline; } div { background-color: #fff; } div { background: url('image.jpg') repeat; } 盒子模型包括边框、内边距、外边距和实际内容。常用的属性有:
box-shadow: 2px 2px 5px rgba(0,0,0,0.3);
padding: 10px;
margin: 20px;
浮动是布局中常用的技术,适用于水平排列多个块级元素。
.float-left { float: left; } .clearfix { clear: both; } 定位是布局中高级技术,常用于固定元素位置。
.absolute { position: absolute; } .relative { position: relative; } li { cursor: pointer; } input { outline: none; } .vertical-align { vertical-align: middle; } .text-overflow { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } 通过以上知识,您可以更好地掌握CSS的使用和高级技巧,实现更复杂的网页布局和样式设计。
转载地址:http://pufj.baihongyu.com/