开发者

position the right hand edge of a string a certain distance from the centre of a page in CSS

name says it all, but I want to be able to position an element based on a defined di开发者_开发知识库stance from the page centre, but the measurement must be between the centre and right hand edge of the element.

is this possible?


I believe this is what you want (if i understand correctly)

position:absolute;
right:50%;
margin-right:-<distance_you_want>px;

parent element should be positioned as well (absolute or relative)

demo at http://jsfiddle.net/gaby/jD443/ (vertical line at center of box for illustration)


See example of the following →

You'll need an extra wrapper, but hit can be accomplished with a child that has position:relative; margin:0 auto; width:1px and a grandchild that has position:absolute; right:XXpx; where XX is the distance to the right of the center that you desire.

<div id="parent">
    <div id="child">
        <div id="kid">40px right of center ==&gt;</div>
    </div>
</div>

#parent { 
    width:400px; height:200px;
}
#child {
    margin:0 auto;
    position:relative;
    width:1px; height:200px;
}
#kid {
    text-align:right;
    position:absolute; right:-40px;
    width:180px;
}

See example →

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜