Div自动获取最大宽度

时间:2016-11-12 20:03:15

标签: html css

问题是无论chat_ttc内部是什么,它总是300px。

段:



.chat_ttc {
  max-width: 300px;
  word-break: break-word;
  background: #e5e5e5;
  margin-left: 70px;
  position: relative;
  border-radius: 15px;
  border-bottom-left-radius: 0px;
  padding: 4px;
  padding-left: 6px;
  letter-spacing: 0.6;
}

<div class="froma_tc">
  <div class="chat_ttc">D</div>
</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:2)

yaa因为div是块元素,它占用宽度的100% 因为你给出的最大宽度为300px,宽度总是300px

如果你想把一些有效的宽度make div作为inline-block

检查此代码段

&#13;
&#13;
.chat_ttc {
  max-width: 300px;

  display:inline-block;
  word-break: break-word;
  background: #e5e5e5;
  margin-left: 70px;
  position: relative;
  border-radius: 15px;
  border-bottom-left-radius: 0px;
  padding: 4px;
  padding-left: 6px;
  letter-spacing: 0.6;
}
&#13;
<div class="froma_tc">
  <div class="chat_ttc">D</div>
</div>
&#13;
&#13;
&#13;

希望这有帮助