简体   繁体   中英

Fixed width div pushes floated text off the screen

jsfiddle: http://jsfiddle.net/4wayP/

<div style="position:fixed;width:100%;">
    <p style="float:right;">Hello World</p>
</div>

What gives? Is there a clean way to ensure this doesn't happen? Or is it just margin-right til it looks acceptable.

Don't forget to specify top: 0; left: 0 top: 0; left: 0 .

jsFiddle Demo

Otherwise it will be placed whereever it would be if it had position: static . In your case, the body has default margin, so it would be placed according to that margin.

This fiddle will help illustrate what happened actually.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM