2012-07-04 155 views
0

我怎样才能达到这个观点与CSS:CSS水平居中行

------------------ TITLE

标题 - -----------------

<div id="titleBlock"> 
    <div id="title">Some text</div> 
    <div id="titleLine"></div> 
</div> 

而我的风格是:

#titleLine { 
    border-top: 1px solid black; 
    width: 84%; 
    clear: both; 
    height: 20px; 
} 

#title { 
    height: 10px; 
    float: right; 
} 

我的做法是在这里:jsFiddle

但是线宽与百分比定义,我需要它与CSS自动调整。

回答

0

希望这有助于

<div id="titleBlock"> 
    <div id="title">Some text</div> 
    <div id="titleLine"></div> 
</div>​ 

#titleLine { 
    border-top: 1px solid black; 
    width: 84%; 
    float:left; 
    height: 20px; 
    margin-top:8px; 
} 

#title { 
    height: 10px; 
    float: right; 
}​ 

http://jsfiddle.net/sY2SV/1

<div id="titleBlock"> 
    <div id="title">Some text</div> 
    <div id="titleLine"></div> 
</div>​ 

#titleLine { 
    border-top: 1px solid black; 
    width: 84%; 
    float:right; 
    height: 20px; 
    margin-top:8px; 
} 

#title { 
    height: 10px; 
    float: left; 
}​ 

http://jsfiddle.net/sY2SV/2

-1

对于文本,最好使用text-align

0

这里是一个解决方案:

#titleBlock { 
    width:100%; 
} 


#titleLine { 
    background:black; 
    position:absolute; 
    z-index:1; 
    left:0px; 
    top:14px; 
    width:100%; 
    height: 1px; 
} 

#title { 
    display:inline-block; 
    padding:4px; 
    background:white; 
    position:relative; 
    z-index:2; 
    /* Only variable to change... Just say left and it woulb be title------- */ 
    float:right; 
}​​​​ 

DEMO

0

嘿,现在你可以使用这个

HTML

<div class="hello"><span>Hello i m sony</span></div> 

的CSS

.hello{ 
background:green; 
    text-align:left; 
    position:relative; 

} 
.hello span{ 
    padding-right:10px; 
background:green; 
    display:inline-block; 
    position:relative; 
    z-index:1 
} 
.hello:after{ 
content:''; 
    border-top:solid 5px red; 
    position:absolute; 
right:0; 
    left:0; 
    top:7px 
} 

现场演示

http://tinkerbin.com/1guJzKcI

0

检查我在Horizontal Line in Background using Css3

答案您可以用1%的坡度这样

.datedAside { 
    background: linear-gradient(0deg, transparent 49%, #000 50%, transparent 51%); 
} 
.datedAside span{ 
    background: #FFF; 
    padding: 0 0.5rem; 
} 

你办nedd额外的温泉n与组件背景的背景颜色相同,使其看起来像已经“删除”了文本后面的行。