div style 常用属性

https://wenku.baidu.com/view/471e23210722192e4536f615.html
一、常用属性:
1、Height:设置div的高度
2、Width:设置div的宽度
例如:

<div style="width:200px;height:200px;background-color:Black;"> 
    我是高度,宽度测试
</div> 

在这里插入图片描述
px就是一个单位,指定固定值。
% 是相对的,比如父容器宽度为100px的话,如果它里面标签定义了宽度为50%,那么这个标签的宽度折算就是50px,当前单位不止px,其实px跟%没有什么联系

3、margin:用于设置div的外延边距,也就是到父容器的距离
可以用%也可以用px
例如:

<div style="width:500px;height:500px;background-color:Black;"> 
    <div style="margin-left: 50px;margin-top: 5px;width: 200px;height: 200px;background-color: white">
        </div>
        </div> 

说明:margin:后面跟有四个距离分别为到父容器的上右下左边的距离,可以看例子中白色的div到黑色的div的边距离效果,还可以分别设置这四个边的距离,用到的属性如下:
4、margin-left
5、margin-right
6、margin-top
7、margin-bottom

8、padding:用于设置div的内边距:
例如

在这里插入代码片

猜你喜欢

转载自blog.csdn.net/old_man31/article/details/86476220