1. 垂直对齐 vertical-align
基线(baseline):浏览器文字类型元素排版中存在用于对齐的基线
<style>
.text {
border-bottom: 1px solid #ccc;
}
.text-baseline {
vertical-align: baseline;
}
.text-top {
vertical-align: top;
}
.text-middle {
vertical-align: middle;
}
.text-bottom {
vertical-align: bottom;
}
</style>
<div>
<span class="text text-baseline">绝知此事要躬行</span>
<span class="text text-top">绝知此事要躬行</span>
<span class="text text-middle">绝知此事要躬行</span>
<span class="text text-bottom">绝知此事要躬行</span>
</div>
<style>
input {
height: 50px;
}
input[type="button"] {
height: 30px;
}
.middle input {
vertical-align: middle;
}
</style>
<div>
<input type="text" />
<input type="button"
value="搜索" />
</div>
<style>
.box {
border: 1px solid #ccc;
width: 500px;
}
img {
height: 200px;
width: 200px;
}
.middle-box {
margin-top: 20px;
}
.middle-box img {
vertical-align: middle;
}
</style>
<div>
<div class="box">
<img src="https://api.isoyu.com/bing_images.php" /><input type="button"
value="搜索" /></div>
<div class="box middle-box">
<img src="https://api.isoyu.com/bing_images.php" /><input type="button"
value="搜索" /></div>
</div>
<style>
.box {
width: 400px;
height: 400px;
background-color: skyblue;
/* 水平居中 */
text-align: center;
}
.box::after {
height: 100%;
content: '';
display: inline-block;
vertical-align: middle;
}
img {
height: 200px;
width: 200px;
/* 垂直居中 */
/*方式一*/
vertical-align: middle;
/*方式二*/
/* display: block; */
}
</style>
<div class="box">
<img src="https://api.isoyu.com/bing_images.php" />
</div>
2. 光标类型 cursor
<style>
.cursor--pointer {
cursor: pointer;
}
.cursor--text {
cursor: text;
}
.cursor--move {
cursor: move;
}
</style>
<div class="box">
<div>默认,箭头</div>
<div class="cursor--pointer">小手,提示可点击</div>
<div class="cursor--text">工字型,提示可选择</div>
<div class="cursor--move">十字光标,提示可移动</div>
</div>
3. 边框圆角 border-radius
/* 单值 4个角一样*/
border-radius: 数字px/百分比;
/* 多值 左上角开始,顺时针赋值,没有赋值看对角*/
border-radius: 左上 右上 右下 左下;
<style>
.box {
width: 200px;
height: 200px;
border-radius: 50%;
background-color: skyblue;
}
</style>
<div class="box"></div>
/* 最大值 50% */
border-radius: 50%;
<style>
.box {
width: 100px;
height: 50px;
border-radius: 25px;
background-color: skyblue;
}
</style>
<div class="box"></div>
4. 溢出部分效果 overflow
<style>
.box {
width: 100px;
height: 100px;
background-color: skyblue;
overflow: hidden;
}
</style>
<div class="box">
江夏赠韦南陵冰
李白〔唐代〕
胡骄马惊沙尘起,胡雏饮马天津水。
君为张掖近酒泉,我窜三色九千里。(三色 一作:三巴)
天地再新法令宽,夜郎迁客带霜寒。
西忆故人不可见,东风吹梦到长安。
宁期此地忽相遇,惊喜茫如堕烟雾。
玉箫金管喧四筵,苦心不得申长句。
昨日绣衣倾绿尊,病如桃李竟何言。
昔骑天子大宛马,今乘款段诸侯门。
赖遇南平豁方寸,复兼夫子持清论。
有似山开万里云,四望青天解人闷。
人闷还心闷,苦辛长苦辛。
愁来饮酒二千石,寒灰重暖生阳春。
山公醉后能骑马,别是风流贤主人。
头陀云月多僧气,山水何曾称人意。
不然鸣笳按鼓戏沧流,呼取江南女儿歌棹讴。
我且为君槌碎黄鹤楼,君亦为吾倒却鹦鹉洲。
赤壁争雄如梦里,且须歌舞宽离忧。
</div>
5. 元素本身隐藏
/* 占位隐藏 */
visibility: hidden;
/* 不占位隐藏(常用) */
display: none;
<style>
.box-1 {
width: 100px;
height: 100px;
visibility: hidden;
}
.box-2 {
width: 100px;
height: 100px;
display: none;
}
</style>
<div class="box-1"></div>
<div class="box-2"></div>
<style>
.box {
width: 100px;
height: 100px;
background-color: skyblue;
position: relative;
}
.box:hover .box-qrcode {
display: block;
}
.box-qrcode {
position: absolute;
top: 100px;
width: 100px;
height: 100px;
background-color: pink;
display: none;
}
</style>
<div class="box">
<div class="box-qrcode"></div>
</div>
6. 元素整体透明 opacity
<style>
.box {
width: 100px;
height: 100px;
background-color: skyblue;
opacity: .5;
}
</style>
<div class="box"></div>
7.半透明
<style>
.box {
/* width: 100px; */
height: 100px;
background-color: rgba(0, 0, 0, 0.4);
}
</style>
<div class="box"></div>
精灵图(雪碧图, sprite)
<style>
.box {
background-image: url('./img/jd-sprite.png');
background-repeat: no-repeat;
background-size: 113px 86.5px;
width: 36px;
height: 42px;
display: inline-block;
margin-right: 50px;
}
.box-1 {
background-position: 0 0;
}
.box-2 {
background-position: -38.5px 0;
}
.box-3 {
background-position: -77px 0;
}
.box-4 {
background-position: 0 -44.5px;
}
</style>
<div class="box box-1"></div>
<div class="box box-2"></div>
<div class="box box-3"></div>
<div class="box box-4"></div>
背景图片大小 background-size
盒子阴影 box-shadow
<style>
.box {
width: 100px;
height: 100px;
box-shadow: 0 10px 50px 8px #ccc;
}
</style>
<div class="box"></div>
过渡 transition
<style>
.box {
width: 100px;
height: 100px;
background-color: skyblue;
transition: all 2s;
}
.box:hover {
width: 200px;
background-color: pink;
}
</style>
<div class="box"></div>