position之absolute中left、bottom、top、right与width、height的关系
2016-12-19 18:00
555 查看
1、在网页设计中我们经常遇到宽度自适应,但有时候可能一种高度自适应的问题。这个时候我们的position之absolute就可以帮你了。
2、position之absolute是脱离文档流。当width、height设置某值后,该元素的值就是该值。那width、height没有设置的时候呢?
3、该元素的witdh、height会根据父元素(需设置position:relative,没有则按浏览器作为父元素)的width、height和该元素left、bottom、top、right而改变。
公式:
该元素的witdh = 父元素的width-top-bottom;
该元素的height= 父元素的height-left-right;
该元素位置(该元素left,该元素top);
废话不多说,上图!
html:
css:
效果:
![](http://images0.cnblogs.com/blog2015/761169/201507/092231510646276.png)
4、假如有一高度自适应的div,父元素高度300px,里面有两个div,一个高度100px,希望另一个填满剩下的高度
html:
css:
效果:
![](http://images0.cnblogs.com/blog2015/761169/201507/092236518774509.png)
就这么简单的完成!
2、position之absolute是脱离文档流。当width、height设置某值后,该元素的值就是该值。那width、height没有设置的时候呢?
3、该元素的witdh、height会根据父元素(需设置position:relative,没有则按浏览器作为父元素)的width、height和该元素left、bottom、top、right而改变。
公式:
该元素的witdh = 父元素的width-top-bottom;
该元素的height= 父元素的height-left-right;
该元素位置(该元素left,该元素top);
废话不多说,上图!
html:
![](http://images0.cnblogs.com/blog2015/761169/201507/092231510646276.png)
4、假如有一高度自适应的div,父元素高度300px,里面有两个div,一个高度100px,希望另一个填满剩下的高度
html:
![](http://images0.cnblogs.com/blog2015/761169/201507/092236518774509.png)
就这么简单的完成!
相关文章推荐
- 设置position:absolute 后 top right bottom left 如何偏移
- css定位position,absolute relative两种情况下,top,left,right,bottom的区别
- position:fixed; top: 0; right: 0; bottom: 0; left: 0;的意思
- (四)学习CSS之position、bottom、left、right和top属性
- absolute,relative,left,right,bottom,top,float,z-index属性的讨论
- DIV绝对定位 position、z-index、top、right、bottom和left属性
- css中定位position、偏移top,bottom,left,right和高宽度设置问题
- absolute同时设置left,right,top,bottom
- position:fixed; top: 0; right: 0; bottom: 0; left: 0;的意思
- position:fixed; top: 0; right: 0; bottom: 0; left: 0;的意思
- position:fixed; top: 0; right: 0; bottom: 0; left: 0;的意思
- position:fixed; top: 0; right: 0; bottom: 0; left: 0;的意思
- 元素position设置为fixed而未指定top、bottom、left、right时的定位
- position:fixed; top: 0; right: 0; bottom: 0; left: 0;的意思
- css中absolute定位的top bottom left right
- position:fixed; top: 0; right: 0; bottom: 0; left: 0;的意思
- position+left+bottom+top+right
- position:fixed; top: 0; right: 0; bottom: 0; left: 0;的意思
- position:fixed; top: 0; right: 0; bottom: 0; left: 0;的意思
- position:fixed; top: 0; right: 0; bottom: 0; left: 0;的意思