断字使div中的空白区域

时间:2018-11-08 12:27:07

标签: html css css-position

我有以下html和CSS

<html>
<body>
<div class="a" style="
    background-color: black;
    color: #fff;
    max-width: calc(65% - 75px);
    width: 21%;
    display: inline-block;
    float: right;
    position: relative;
    padding: 3px 5px;
">
<span class="message" style="
    width: auto;
    position: relative;
    text-align: right;
    display: inline-block;
    width: auto;
    word-break: break-word;
">let's check this one now for asd4ffdsa sassfhkloitrf.</span>
</div>

</body></html>

,它输出以下布局 enter image description here

但是问题是我无法摆脱此处显示的空白区域 enter image description here

我已经尝试过使用位置,宽度自动,显示属性进行所有可能的修复,但是我无法摆脱此处的多余空间。

2 个答案:

答案 0 :(得分:0)

我已经测试了您的代码,并且要删除空白区域,应该删除 width 属性或将其设置为auto,因为它将强制页面的 21%作为其宽度。 所以应该像这样:

<html><body>
    <div class="a" style="
      background-color: black;
      color: #fff;
      max-width: calc(65% - 75px);
      display: inline-block;
      float: right;
      position: relative;
      padding: 3px 5px; ">
    <span class="message" style="
      width: auto;
      position: relative;
      text-align: right;
      display: inline-block;
      width: auto;
      word-break: break-word; ">let's check this one now for asd4ffdsa sassfhkloitrf.</span> </div>

</body></html>

希望这会有所帮助。

答案 1 :(得分:-1)

使用此:

word-break: break-all;

代替断词