我试图给一个包装在div中的标题添加一个底部边框,但它会影响整个块。
<div class="title">I'm a title</div>和我的CSS
.title {border-bottom: 2px solid #000; padding-bottom: 3px;}将此边框应用于文本的最佳方式是什么?
在文本周围环绕一个跨度将是理想的。但是我不能访问HTML。
<div class="title">
<span class="border">I'm a title</span>
</div>如何使用Jquery使用span包装文本。
我在努力
$(".title").wrap('<span></span>');或者,有没有其他方法来添加这个CSS?
谢谢
发布于 2012-04-04 11:38:39
"...How我会使用Jquery用跨度包装文本吗?“
这应该会回答你的问题:
<html>
<head runat="server">
<title></title>
<style>
.border {border-bottom: 2px solid #000; padding-bottom: 3px;}
</style>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.title').each(function(index) {
$(this).html("<span class='border'>" + $(this).html() + "</span>");
});
});
</script>
</head>
<body runat="server">
<div class="title" style="text-align: center">I'm a title</div>
</body>
</html>发布于 2012-04-04 11:13:37
.title {border-bottom: 2px solid #000; padding-bottom: 3px; display: inline;}发布于 2012-04-04 11:14:14
根据您想要获得的效果,您可以通过设置text-decoration:underline (MDN)来获得您想要的效果
这本身并不是一个真正的边框,但是如果你不能修改html,这可能是你唯一的选择
https://stackoverflow.com/questions/10004418
复制相似问题