盒子模型

盒子模型 *****
    1、框模型
     框:页面上所有的元素都可以称之为"框"
    框模型:(Box Model),又称为盒子模型,定义框处理元素内容、内边距padding、外边距margin、边框的样式border
    尺寸
    边框
    内边距
    外边距
1、外边距
    属性:margin
    margin-方向:
        margin-left:
        margin-right:
        margin-top:
        margin-bottom:

    取值:
    px

    负值
    auto
    
    margin取值:
    margin:value; /*四个方向的外边距统一设置*/
    margin:v1 v2; /*v1:上下 v2:左右*/
    margin-left:5px;
    margin-right:5px;
    margin-top:10px;
    margin-bottom:10px;
    margin:v1 v2 v3;/*v1:上 v2:左右 v3:下*/
    margin:v1 v2 v3 v4;/*上右下左*/
    margin取值为auto:
    左右外边距设置为auto时,当前的块级元素会居中显示
注意:
1、有些块级元素会存在默认外边距
body
h1~h6
p

2、垂直外边距合并
    两个垂直外边距相遇时,将会合成一个外边距。最终外边距的值是两者中 边距较大的的值。
    
3、如果给子元素设置margin-bottom,默认会被识别成是父元素的margin-bottom
解决方案:
1、给父元素加边框
2、通过父元素的 padding解决

2、内边距
    1、什么是内边距
    内容区域和边框之间的空白
    内边距会扩大元素边框所占用的区域
    2、属性
    padding
    取值:
    px
    %
    没有 auto和负数
    padding-top/bottom/left/right:
    padding:value; /*四个方向的内边距*/
    padding:v1 v2;上下 左右
    
    padding:v1 v2 v3 v4;
有些元素,默认是有内边距的

2、背景   *****
    1、背景色
    属性:background-color
    取值:合法颜色值
    transparent
    注意:背景颜色会填充到元素的边框、内边距、内容区域

    2、背景图片
    属性:background-image
    取值:url(图像路径)
        background-image:url("");
        

    3、背景重复
        默认情况,背景图会在水平和垂直两个方向都出现重复的效果(平铺)
        属性:background-repeat
        取值:
        repeat :默认值,水平垂直平铺
        repeat-x : 水平平铺
        repeat-y : 垂直平铺
        no-repeat : 不平铺(用的最多)


    4、背景图片固定
    属性:background-attachment
    取值:

    fixed,背景图像固定
    6、背景定位
    改变背景图像在元素中的位置
    属性:background-position
    取值:
    x y :x表示水平方向移动距离,+向右,-向左,y表示垂直方向移动距离,+向下,-向上
    x% y% :
    0% 0% : 显示在元素的左上方
    100% 100% : 显示在元素的右下方
    50% 50% : 居中
    left :靠左
    right:靠右
    center :将元素显示在水平或垂直方向的中间
    top:靠上
    bottom:靠下
    background-position:left top;
    background-position:top left;
    background-position:center;

3、文本格式化       ***
    
    1、指定字体
    font-family:选择字体格式
    font-family:"microsoft yahei","arial","verdana";
    2、字体大小
    font-size:value;   *****
    
    font-size:12px;
    3、字体加粗      normal正常    *****
    font-weight:normal / bold ;  
    400 - 900
    4、字体样式(斜体)   i
    font-style:normal/italic;
    5、小型大写字母   font-variant字体型状
    font-variant:normal/small-caps;
    6、字体属性
    font:font-style font-variant font-weight font-size font-family;
    常用方式:
    font:font-size font-family;
    font:12px "微软雅黑",arial,verdana;

posted @ 2019-02-21 14:31  Zs夏至  阅读(122)  评论(0编辑  收藏  举报