1、标签居中样例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=Google Chrome">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div{
height: 30px;
width: 30px;
background-color: rgb(130, 24, 24);
/*这里使盒子相较于body居中*/
margin: 0 auto;
}
/* 当行高等于块高时文本可以居中 */
a{
width: 300px;
height: 58px;
/* 控制垂直居中 */
line-height: 58px;
background: rgb(141, 107, 107);
/* 控制水平居中 */
text-align: center;
color: aliceblue;
display: inline-block;
}
body{
margin: 0px;
padding: 0px;
}
</style>
</head>
<body>
<!-- 需要让div,p,h,(大盒子居中),可以通过margin:0 auto实现(0为盒子上边距距离,auto为盒子内容居中)
margin:0 auto 一般针对固定宽度的盒子,如果没有限定盒子宽度 ,则会默认占满父元素宽度 -->
<div>
</div>
<a href="#">链接文本居中</a>
<a href="#">链接文本居中</a>
</body>
</html>