浮动元素和定位元素同级,定位元素消失,代码如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> .box{ width: 400px; height: 400px; position: relative; border:1px solid black; } .content{ width: 300px; height: 300px; background: red; float: left; margin-left: 100px; *display: inline; /*解决双倍边距问题*/ } span{ width: 50px; height: 50px; position: absolute; background: yellow; top: -10px; right: -10px; } </style> </head> <body> <div class="box"> <div class="content"></div> <span></span> </div> </body> </html>
正常显示效果如下:
IE6显示如下:
解决方案:使浮动元素和定位元素不在同一级
<div class="box"> <div class="content"></div> <p> <span></span> <!-- span元素和div不在同一级 --> </p> </div>
时间: 2024-10-08 02:03:22