css

作者: 余亚伟_强化班 | 来源:发表于2019-08-25 19:35 被阅读0次

    css基本语法及页面引用

    css基本语法
    css的定义方法:
    选择器{属性:值;属性:值;属性:值;}
    选择器是将样式和页面元素关联起来的名称,属性是希望设置的格式样式每一个属性有一个或多个值。
    css页面引入方法:
    1、外联样式:通过link标签,链接到外部样式表到页面中。

    <link rel="stylesheet" type="text/css" href="css/main.css">  
    

    2、嵌入式:通过style标签,在网页上创建嵌入的样式表。

    <style type="text/css">
        div{ width:100px; height:100px; color:red }
    </style>
    

    3、内朕式:通过标签的style属性,在标签上直接写样式式。

    <div style="width:100px; height:100px; color:red ">...</div>
    

    CSS属性

    布局常用样式属性:

    ●width 设置元素(标签)的宽度如:width 10x
    
    ●height 设置元素(标签)的高度如; height 2px;
    
    ●background设置元素背景色或者背景图片,如; background gold设置元素背景色为金色,url()添加 图片路径
    
    ●border设置元素四周的边框;如: boder:1px solid black;设置元素四周边框是1像素宽的黑色实践
    
    以上也可以拆分成四个边的写法分别设置四个边的: 
    
    ●border-top 设置顶边边框,如: border-top: 10px solid red
    
    ●borde-left设置左边边框如: boder-left 10px solid blue
    
    ●border-right设置右地边框↑如: boder-right 10px solid green;,
    
    ●border-bottom设置底边边框,如: bodrer-bottom:10px solid pink,
    
    ●padding设置元素包含的下容和元素边差的距离,也叫内边距,如padding 20px;padding是同时设置4个边的,也可以像border一样拆分成分别设置四个边padding-top , padding-left: padding-right.pading-bottom:
    
    ●margin设置元素和外界的距离,也叫外边距, 如margin 20px.margin是同时设置4个边的,也可以像border一样拆分成分别设置四个边padding-top , padding-left: padding-right.pading-bottom:
    
    ●float设置元素浮动, 浮动可以让块元素排列在一行,浮动分为左浮动: float:left,右浮动: float:right
    

    附:边框属性示意图:

    页面边框属性图.jpg

    文本常用样式属性一:

    ●color设置文字的颜色,如: color:red;
    
    ●font-size 设置文字的大小,如: font-size: 12px;
    
    ●font-famil 设置文字的字体,如: font-amily:微软雅黑,为了避免中文字不兼容,一般写成: font-family,"Microsoft Yaheil;
    
    ●font-weight 设置文字是否加粗,如; font-weight: bold;设置加粗 font-weight:normal设置不加粗
    
    ●line-neight设置文字的行高,如; line-height:24px; 表示文字高度加上文字上下的间距是24px,也就是每一行占有的高度是24px
    
    ●text-decoration 设置文字的下划线,如: text-decoration:none;将文字下划线去掉
    
    ●text-align设置文字水平对齐方式,如text-alin:center设置文字水平居中
    
    ●text-indent设置文字首行缩进I如; text-indent 24px;设置文字首行缩进24px
    

    相关文章

      网友评论

          本文标题:css

          本文链接:https://www.haomeiwen.com/subject/vlekectx.html