CSS常见样式
文本样式
块级元素居中
.layout{
width: 600px;
margin: 0 auto;
}
⽂字样式
.text {
color: brown;
font-size: 20px;
line-height: 1.5;
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
font-style: italic;
text-decoration: underline;
text-align: center;
text-indent: 2em;
letter-spacing: 3px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
应用实例
.notice {
text-align: center;
}
.notice h2 {
font-size: 40px;
}
.notice p {
font-size: 14px;
}
.notice a {
color: #ea4c89;
text-decoration: none;
}
.notice h3 {
font-size: 16px;
}
列表样式
<style>
ol,ul{
list-style: none;
}
</style>
<body>
<ul>
<li>好名字</li>
<li>好名字</li>
<li>好名字</li>
</ul>
</body>
背景图片设置
<style>
.item{
width: 100px;
height: 200px;
border: 1px solid #000;
background: #ccc
url(https://cdn.dribbble.com/users/2367860/screenshots/16337130/media/1a80f8e0a5ed85adcbd72e34e9cccac2.png) center no-repeat;
background-size: contain;
}
</style>
<body>
<div class="item"></div>
</body>
边框圆角
<style>
.item{
border: 1px solid #000;
border-radius: 20px;
}
</style>
<body>
<div class="item"></div>
</body>
常见特效
.box{
width: 100px;
height: 100px;
border: 1px solid #ccc;
border-radius: 50%;
transition: all 0.3s;
cursor: pointer;
}
.box:hover{
box-shadow:inset -10px -10px 10px #aaa,
2px 5px 10px rgba(0, 0, 0, 0.2);
opacity: 0.5;
transform:translate(13px,13px);
}
两栏布局
<style>
.container{
display: flex;
border: 1px solid #000;
}
.container .aside{
border: 1px solid red;
width: 100px;
}
.container .main{
border: 1px solid blue;
flex: 1;
}
</style>
<body>
<div class="container">
<div class="main">haomingzi haomingzi haomingzi haomingzi haomingzi haomingzi haomingzi haomingzi</div>
<div class="aside">aside</div>
</div>
</body>
垂直水平居中
.box {
display: flex;
align-items: center;
justify-content: center;
}
均匀分布
<style>
.ct{
display: flex;
flex-wrap: wrap;
justify-content: space-between;
border: 1px solid #000;
}
.child{
width: calc(25% - 8px);
height: 100px;
border: 1px solid red;
padding: 10px;
margin-top: 10px;
}
</style>
<body>
<div class="ct">
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
</div>
</body>
展示隐藏
<style>
.child:hover .lable{
opacity: 1;
}
.child .lable{
font-style: 12px;
background: #aaa;
color: #ccc;
padding: 0 20px;
border-radius: 4px;
opacity: 0;
transition: all .3s;
}
</style>
<body>
<div class="child">
<span class="lable">前端</span>
<span class="lable">Java</span>
</div>
</body>
绝对定位
<style>
.item span{
position: absolute;
right: 20px;
bottom: 20px;
color: #000;
background: red;
font-size: 14px;
border-radius: 14px;
padding: 2px 4px;
}
</style>
<body>
<div class="item">
<span>在线</span>
</div>
</body>