gpt4 book ai didi

html - 显示内联元素上的边框底部

转载 作者:太空宇宙 更新时间:2023-11-04 13:27:37 24 4
gpt4 key购买 nike

我认为这将是一个简单的 CSS 修复,但我似乎无法找到适用于所有情况的解决方案。

我正在尝试使 fiddle 波纹管中的“一些包装的标题”文本带有下划线,而下划线不会超出文本的长度。如果 .title-containerwidth: 200px;,我已经完成了这个,但是现在如果你改变类 .title-container 有一个width: 230px; 我希望下划线继续延伸并在文本“That”结束的地方结束。请看下面的图片了解我的意思。

enter image description here

fiddle :https://jsfiddle.net/bhde0rsq/31/

最佳答案

此代码最初会触发设置宽度,然后每当屏幕发生变化时,宽度始终等于标题宽度。

$(window).resize(function(){
set_width(); // Triggers on resize
})

set_width(); // Initial Trigger

function set_width() {
var title_width = $(".title h1").width();
$(".my-underline").css("width",title_width + "px");
}
.title-container {
width:200px;
background: cyan;
}

.title h1 {
display: inline;
position: relative;
background: yellow;
}

/* hr style */
.my-underline {
height:5px;
background-color:black;
display:table;
position:relative;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="title-container">
<div class="title">
<h1>Some Title That Wraps</h1>
<span class="my-underline"></span>
</div>
</div>

关于html - 显示内联元素上的边框底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51370951/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com