简体   繁体   English

在标题标签上显示内联块

[英]Display inline-block on title tag

  1. So i would like to add a border to a h3 tag. 所以我想为h3标签添加边框。
  2. This border needs to span the width of the longest part of the visible text and no futher. 此边框需要跨越可见文本最长部分的宽度,而不是进一步。
  3. Currently this border seems to span the entire width of the wrapping div. 目前,这个边框似乎跨越了包装div的整个宽度。

Seems weird to me that adding display inline block to ah tag doesn't provide me with the results I was after. 对我来说似乎很奇怪,向ah标签添加显示内联块并不能提供我所追求的结果。

 div { max-width: 180px; } h3 { display: inline-block; border-bottom: 2px solid green; } 
 <div> <h3>Lorem Ipsum Dolar.....</h3> </div> 

EDIT: Seems that some of you don't get that the max-width is required. 编辑:似乎有些人没有得到最大宽度是必需的。

This is how it sould line up. 这就是它排队的方式。

在此输入图像描述

Hmmm... Seems that a perfect solution isn't possible with CSS. 嗯......似乎用CSS无法实现完美的解决方案。 But I've used @Muhammad Usman example and added bottom: -120%; 但是我使用了@Muhammad Usman的例子并添加了bottom: -120%; and replaced the height and background with border properties. 并用边框属性替换了高度和背景。 which works for 2 lines of text. 适用于2行文字。

 div { max-width: 200px; border: dashed 1px grey; } h3 { display: inline; font-size: 1.6em; position: relative; } h3::after { border-bottom: 4px solid green; bottom: -120%; content: ""; left: 0; position: absolute; right: 0; } 
 <div> <h3>Lorem Ipsum Dolar</h3> <p>Lorem ipsum dolar set ammet Lorem ipsum dolar set ammet Lorem ipsum dolar set ammet Lorem ipsum dolar set ammet Lorem ipsum dolar set ammet</p> </div> 

Just erase the max-width and only use display: inline-block 只需擦除最大宽度,只使用display: inline-block

 div { } h3 { display: inline-block; border-bottom: 2px solid green; } 
 <div> <h3>Lorem Ipsum Dolar.....</h3> </div> 

Is that what you want? 那是你要的吗?

 div { max-width: 180px; width:111px; } h3 { display: inline-block; border-bottom: 2px solid green; } 
 <div> <h3>Lorem Ipsum Dolar.....</h3> </div> 

Add Display:inline property for your "div" 添加显示:“div”的内联属性

 div {
        max-width: 180px;
        display: inline;
    }

 div { max-width: 180px; } h3 { position: relative; display: inline; } h3:before { position: absolute; background: green; content: ''; height: 2px; left: 0; right: 0; bottom: -4px; } 
 <div> <h3>Lorem Ipsum Dolar Lorem Ipsum Dolar gnhhjkui abc .....</h3> </div> 

So I thought I would update this question as no one else has found the answer. 所以我想我会更新这个问题,因为没有其他人找到答案。

It is possible when using flexbox, just wrap the title tag with a div and apply flex to it. 使用flexbox时可以使用div包装title标签并对其应用flex。

 div { max-width: 200px; border: dashed 1px grey; } div.flex { display: flex; flex-flow:row wrap; } h3 { display: inline; font-size: 1.6em; border-bottom: 4px solid green; } 
 <div class="flex"> <h3>Lorem Ipsum <br>Dolar</h3> <p>Lorem ipsum dolar set ammet Lorem ipsum dolar set ammet Lorem ipsum dolar set ammet Lorem ipsum dolar set ammet Lorem ipsum dolar set ammet</p> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM