【问题标题】:<hr/> tag should increase size dynamically based on text<hr/> 标签应该根据文本动态增加大小
【发布时间】:2019-12-18 19:26:59
【问题描述】:

我有&lt;hr/&gt; 标签,应该根据下面的文本动态增加其大小到&lt;hr/&gt; 标签。

<div class="outer">
<hr class="line"/>
The above line should be match with this sentence.
</div>

请提出建议。

【问题讨论】:

    标签: css dynamic width


    【解决方案1】:

    您可以通过将width: fit-content 添加到outer 类来实现。

    .outer {
      width: fit-content;
    }
    <div class="outer">
    <hr class="line"/>
    The above line should be match with this sentence.
    </div>

    编辑:为了获得更好的浏览器支持,您可以改用display: table

    .outer {
      display: table;
    }
    <div class="outer">
    <hr class="line"/>
    The above line should be match with this sentence.
    </div>

    【讨论】:

    • 请注意,我们最好的朋友 Edge 和 Internet Explorer 目前不支持此功能
    • @MatthiasSeifert 没有前缀的 Firefox 甚至不支持它
    • 太棒了。谢谢。
    【解决方案2】:

    inline-block添加到外部div

    示例 1:

    .outer {
      display: inline-block;
    }
    <div class="outer">
              <hr class="line"/>
              The above line should be with this sentence.
          </div>

    示例 2:

    .outer {
      display: inline-block;
    }
    <div class="outer">
              <hr class="line"/>
              short text
          </div>

    【讨论】:

    • 太棒了。谢谢
    • 欢迎,如果您在其中找到解决方案,请不要忘记通过勾选投票下的复选标记来接受答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-17
    • 1970-01-01
    • 2022-01-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多