演示代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" type="text/css" href="reset.css"/>
<style type="text/css">
#box{
width: 50%;
height: 300px;
margin: 100px auto;
background-color: aqua;
/* 行级元素、行内块级元素水平居中就可以使用这种方案,写在需要居中的父元素中 */
text-align: center;
}
.wyzx{
background-color: #ff0000;
width: 50%;
/* 块级元素居中,写在需要剧中的元素中 */
margin: 0 auto;
}
</style>
</head>
<body>
<div id="box">
<!-- <span class="wyzx">我要自学</span> -->
<!-- <img src="bj.jpg" > -->
<!-- <input type="text" id="" value="请输入......" /> -->
<p class="wyzx">我要自学</p>
</div>
</body>
</html>