内容的宽度

时间:2018-06-18 09:45:03

标签: html css

如何使div只取内容的宽度?

.modal {
  position: fixed;
  top: 63px;
  z-index: 20;
  left: 0;
  right: 0;
  margin: auto;
  background: gold;
  text-align: center;
}
<div class='modal'>
lorem ipsum<br>and<br>lorem ipsum
</div>

1 个答案:

答案 0 :(得分:4)

&#13;
&#13;
.modal {
  position: fixed;
  top: 63px;
  z-index: 20;
  left: 50%;
  transform: translateX(-50%);
  background: gold;
}
&#13;
<div class='modal'>
  lorem ipsum<br>and<br>lorem ipsum
</div>
&#13;
&#13;
&#13;