HTML:
<div class="line"></div>
<div class="text">TEXT</div>
<div class="line"></div>
CSS:
.line {
width: 100px;
padding-top: 15px; /* font-size / 2 = (30/2=15) */
border-bottom: solid 1px #000;
float: left;
}
.text {
font-size: 30px;
font-weight: bold;
color: #000;
float: left;
}
现场演示:jsFiddle
jQuery方法:
HTML:
<div id="container">
<div class="line"></div>
<div class="text">TEXT</div>
<div class="line"></div>
</div>
CSS:
#container
{
width: 1000px;
}
.line {
padding-top: 15px; /* font-size / 2 = (30/2=15) */
border-bottom: solid 1px #000;
float: left;
}
.text {
font-size: 30px;
font-weight: bold;
color: #000;
float: left;
}
JavaScript:
var text_width = parseInt($(".text").css("width"));
var container_width = parseInt($("#container").css("width"));
var line_width = (container_width - text_width) / 2;
$("div").find(".line").css("width", line_width+"px");