CSS基础之常见修饰效果
一、垂直对齐方式:
1、背景:
浏览器在处理行内元素和行内块元素的时候都是将这些元素当作是文字处理的,比如图片和表单元素都是当作文字来进行展示的。而浏览器对文字类型元素是用基线对齐的。
(1)基线:类似于小时候写拼音用的四线格
(2)场景及问题:当图片和文字在一行时,或者行内元素和行内块元素在一行时,他们的底部其实是不对其的,有的会显示在基线的下面,所以底部是不对齐的。
2、解决方式:
代码:vertical-align
3、常见问题及解决方案:
有图片的随便放一张自己的图片即可。
案例一:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
input {
height: 50px;
box-sizing: border-box;
/* 解决方案:将他们进行中部对齐 */
/* vertical-align: middle; */
}
</style>
</head>
<body>
<input type="text"><input type="button" value="搜索">
</body>
</html>
案例二:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
img{
/* 解决方案 */
/* vertical-align: middle; */
}
</style>
</head>
<body>
<img src="./images/1.jpg" alt=""><input type="text">
</body>
</html>
案例三:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.father {
width: 400px;
height: 400px;
background-color: pink;
text-align: center;
}
input{
/* 解决方案 */
/* vertical-align: top; */
}
</style>
</head>
<body>
<div class="father">
<input type="text">
</div>
</body>
</html>
案例四:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.father {
width: 400px;
background-color: pink;
}
img{
/* 解决方案 */
/* vertical-align: middle; */
}
</style>
</head>
<body>
<div class="father">
<img src="./images/1.jpg" alt="">
</div>
</body>
</html>
案例五:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.father {
width: 600px;
height: 600px;
background-color: pink;
line-height: 600px;
}
img{
/* 解决方案 */
/* vertical-align: middle; */
}
</style>
</head>
<body>
<div class="father">
<img src="./images/1.jpg" alt="">
</div>
</body>
</html>
二、光标类型
在浏览别人网页的时候,经常会遇到点击一些图片或者某些地方,鼠标就会变形,提示用户可以点击。
1、代码:curse
举个栗子:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="GB 2312">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.cursor{
width: 300px;
height: 300px;
background-color: pink;
}
.cursor:hover{
cursor: pointer;
}
</style>
</head>
<body>
<div class="cursor"></div>
</body>
</html>
2、注意:这个只是改变了光标的样式,并没有实际的效果,添加效果需要配合JS。
三、边框圆角
1、代码:border-radius
赋值为一个的时候是将四个角统一设置,当然也可以单独设置,顺序是左上、右上、右下、左下的顺序,如果是两个值,那么值会赋给对角。
2、扩展:当取值为50%以上的时候,就是圆了。
举个栗子:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="GB 2312">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.radius{
width: 300px;
height: 300px;
/* 四个角统一赋值 */
/* border-radius: 20px; */
/* 按照左上,右上,右下,左下赋值 */
/* border-radius: 10px 20px 30px 70px; */
/* 对角赋值 */
/* border-radius: 20px 100px; */
/* 圆 */
border-radius: 50%;
background-color: pink;
}
</style>
</head>
<body>
<div class="radius"></div>
</body>
</html>
四、overflow溢出部分显示效果
1、使用背景:当内容超出了盒子的大小,就需要控制溢出部分的显示效果。
2、代码:overflow
五、元素本身隐藏
1、常见方式:
(1)visibilitu:hidden;隐藏元素本身,但是仍然占着位置。再显示:visibility: visible;
(2)display:none ;隐藏元素本身,且不占位置。再显示:display:block/display:inline-block;
举个栗子:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="GB 2312">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
padding: 0;
margin: 0;
}
.box{
height: 40px;
border-bottom: 1px solid #cfcfcf;
}
ul{
list-style: none;
margin: 0 auto;
width: 1400px;
}
a{
text-decoration: none;
}
ul li{
float: left;
width: 20%;
height: 40px;
box-sizing: border-box;
border-right: 1px solid #cfcfcf;
}
ul li:last-child{
border-right: none;
}
ul li a{
display: block;
height: 100%;
line-height: 40px;
text-align: center;
}
ul li:nth-child(4){
position: relative;
}
ul li img{
position: absolute;
display: none;
top: 41px;
left: 50%;
transform: translate(-50%);
}
ul li a:hover img{
display: inline-block;
}
</style>
</head>
<body>
<div class="box">
<ul>
<li><a href="">我要投资</a></li>
<li><a href="">平台介绍</a></li>
<li><a href="">新手专区</a></li>
<li>
<a href="">手机微金所 <img src="../images/erweima.jpg" alt=""></a>
</li>
<li><a href="">个人中心</a></li>
</ul>
</div>
</body>
</html>