Home > Web Front-end > HTML Tutorial > padding对于元素position定位的影响_html/css_WEB-ITnose

padding对于元素position定位的影响_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:28:33
Original
1739 people have browsed it

padding对于元素position定位的影响:
关于padding和position的基本用法这里不多介绍了,可以参阅相关阅读。
相关阅读:
1.padding可以参阅CSS的padding用法详解一章节。
2.position可以参阅CSS的position属性一章节。
下面进入正题,介绍一下padding属性对于定位的影响。
代码实例:
实例一:

<!DOCTYPE html><html><head><meta charset=" utf-8"><meta name="author" content="http://www.softwhy.com/" /><title>蚂蚁部落</title><style type="text/css">.box{  width:300px;  height:150px;  background-color:#CCC;  padding:20px;}.inner{  width:50px;  height:50px;  background-color:red;  position:relative;  left:10px;  top:20px;}</style></head><body><div class="box">  <div class="inner"></div></div></body></html>
Copy after login

相对定位的参考对象由于是自身,所以不会受padding的影响。
实例二:

<!DOCTYPE html><html><head><meta charset=" utf-8"><meta name="author" content="http://www.softwhy.com/" /><title>蚂蚁部落</title><style type="text/css">.box{  width:300px;  height:150px;  background-color:#CCC;  padding:20px;  position:relative;}.inner{  width:50px;  height:50px;  background-color:red;  position:absolute;}</style></head><body><div class="box">  <div class="inner"></div></div></body></html>
Copy after login

对于绝对定位,如果没有设置left或者top属性值,那么相应方位就不会忽略padding值。
实例三:

<!DOCTYPE html><html><head><meta charset=" utf-8"><meta name="author" content="http://www.softwhy.com/" /><title>蚂蚁部落</title><style type="text/css">.box{  width:300px;  height:150px;  background-color:#CCC;  padding:20px;  position:relative;}.inner{  width:50px;  height:50px;  background-color:red;  position:absolute;  left:5px;}</style></head><body><div class="box">  <div class="inner"></div></div></body></html>
Copy after login

对于绝对定位相应方位设置了left和top属性值,那么就会忽略相应方位的padding。

原文地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=15476

更多内容可以参阅:http://www.softwhy.com/divcss/

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template