宽度已知:
<body>
<div>
<div id="content">
居中蓄力中
</div>
</div>
</body>
#content {
position: absolute;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
width: 100px; /* 要设定宽度 */
}
宽度未知:
<div class="outer">
<div class="inner">居中<br/>蓄力中</div>
</div>
.outer {
position: relative; /* or absolute */
/* unnecessary styling properties */
margin: 5%;
width: 80%;
height: 500px;
border: 1px solid red;
}
.inner {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
/* unnecessary styling properties */
max-width: 50%;
text-align: center;
border: 1px solid blue;
}
选择除了第一个以外的其他元素:
p:not(:first-child) {
}