【发布时间】:2014-04-25 15:25:24
【问题描述】:
我有一条错误消息要显示
如果没有背景,我可以使用 text-align center 将其居中。但现在可以清楚地看到它占据了容器的整个宽度,它是 <p>。
所以我给了宽度和边距:0 auto; 但我不能将它的类赋予所有其他错误消息,因为宽度会发生变化。 那么有没有办法在不给宽度的情况下将其居中。
这是我目前拥有的JSFIDDLE
HTML:
<p class="error"><b>Error:</b> Dont select corners, select edges!</p>
CSS:
.error{
padding:15px;
border:1px solid #ebccd1;
border-radius:4px;
background-color: #f2dede;
margin:0 auto;
font-family:consolas;
font-size:17px;
color:#a94442;
width:370px;
}
【问题讨论】: