css - 如何把一个视图放在左浮动定位的视图的上面?
问题描述
我想把一个红色的视图放在左浮动视图的上面,但是看不见了这个红色视图,下面是我的代码,多谢指导。
<!DOCTYPE html><html lang='en'><head> <title>Heors - How To Convert a PSD Template TO HTML5/CSS3</title> <meta charset='utf-8'> <meta name='author' content='pixelhint.com'> <meta name='description' content='Heros - Learn How To Convert a PSD Template TO HTML5/CSS3'/><style media='screen'> .red {width: 300px;position: absolute;text-align: center;bottom: 80px;z-index: 9999;background-color: red; } .wrapper {width: 300px;height: auto;position: relative; } .yellow{width: 300px;float: left; height: 600px; background-color: yellow; }</style></head><body> <p class='wrapper'><p class='yellow'> 左浮动</p><p class='red'> <p>绝对定位距底部80px</p></p> </p></body></html>
问题解答
回答1:楼主,你仔细看看你父元素wrapper的高度为多少?这是为什么呢?因为你yellow左浮动了,脱离文档流,red绝对定位也已经脱离文档流了,所以你red定位在bottom:80px没什么屌用,因为父元素高度都没有,它上哪去找80px的底部来定位。所以,你要解决的方法就是,动用你勤劳的小手,给父元素wrapper加上overflow:hidden;(溢出隐藏)
回答2:.red {width: 300px;position: absolute;text-align: center;bottom: 80px;z-index: 9999;background-color: red; } 改成: .red {width: 300px;position: absolute;text-align: center;top: 0;z-index: 9999;background-color: red; }
相关文章:
1. vue计算属性怎么样与for结合使用2. javascript - windows编辑器代码片段3. javascript - 有没有类似高铁管家的时间选择插件4. javascript - webpack打包问题5. android - 类似微信朋友圈或者QQ空间说说那种点击图片放大,并且有放大缩小手势,左右滑动图片手势效果6. node.js - Vue+Webpack在dev环境下没有问题build后出现莫名错误7. node.js - vue-cli安装出错8. 前端 - CSS3 box-shadow如何设置,或者用什么方法可以产生图中这样阴影的效果。9. error_log 指定不能生存错误日志的地址10. 自学,刚编了helloworld就失败了
