首页 / CSS / css中关于几个小tip的示例详解
css中关于几个小tip的示例详解
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了css中关于几个小tip的示例详解,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2152字,纯文字阅读大概需要4分钟。
内容图文
![css中关于几个小tip的示例详解](/upload/InfoBanner/zyjiaocheng/414/df73ac04dcf143f98d3a74ecd240fe32.jpg)
<style type="text/css"> .parent{ outline: 1px solid orange; width: 200px; height: 300px; padding: 10px; margin: 10px; } .child{ outline: 1px solid purple; width: 200px; height: 80px; padding-top: 10%; /*20px = 父容器的width值200px * 10% */ padding-bottom: 5%; /*10px = 200px * 5% */ margin-top: 20%; /*40px = 200px * 20%*/ margin-bottom: 15%; /*30px = 200px * 15%*/ }<body> <p class="parent"> <p class="child"></p> </p> </body>
子盒子参数如下:
2.含有定位属性的元素,其top、bottom单位为百分比时,该百分比是相对父元素的高度height。left、right则是相对父元素的宽度width.
.parent{
outline: 1px solid orange;
width: 200px;
height: 300px;
padding: 0px;
margin: 0px;
position: relative;
}
.child{
outline: 1px solid purple;
width: 200px;
height: 80px;
position: absolute;
top: 5%; /* 15px = 300px * 5% 上边框离父盒子上边框15px的距离*/
left: 20%; /* 40px = 200px * 20% 左边框离父盒子左边框40px的距离
也就是子盒子左上角的坐标为x=15,y=40(父盒子左上角为原点) */
}
3.边框宽度不能用百分比表示
4.width:100%
4.1当父容器里有绝对定位的子元素时,子元素设置width:100%实际上指的是相对于父容器的padding+content的宽度。
r如图:
<style type="text/css"> .parent{ outline: 1px solid orange; width: 200px; height: 300px; padding: 10px; margin: 10px; position: relative; } .child{ outline: 1px solid purple; width: 100%; /* width = 220px = 父容器的padding+content*/ height: 80px; position: absolute; top: 0; left: 0; } </style>
4.2 当子元素是非绝对定位的元素时(可以是相对定位),或者如果都没有定位,width:100%才是指子元素的 content ,其等于父元素的 content宽度。
.parent{ outline: 1px solid orange; width: 200px; height: 300px; padding: 10px; margin: 10px; } .child{ outline: 1px solid purple; width: 100%; /* width:200px = 父盒子的content*/ height: 80px; }
.parent{ outline: 1px solid orange; width: 200px; height: 300px; padding: 10px; margin: 10px; position: relative; } .child{ outline: 1px solid purple; width: 100%; height: 80px; position: relative; }
以上就是css中关于几个小tip的示例详解的详细内容,更多请关注Gxl网其它相关文章!
内容总结
以上是互联网集市为您收集整理的css中关于几个小tip的示例详解全部内容,希望文章能够帮你解决css中关于几个小tip的示例详解所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。