likes
comments
collection
share

css样式1

作者站长头像
站长
· 阅读数 33

css字体属性:

font-family是字体
font-weight=700(bold),=400(默认:normal)(100-900)相当于strong标签 实际开发中使用数字更好
font-style=normal将倾斜转为正常 =italic变倾斜
font-size 字体大小
#lan {
        font-family: "微软雅黑";
        font-size: 10px;
        font-weight: 700;
        font-style: italic;
        
        /*复合属性使用一行来写 顺序不能颠倒 前2个可以省略,后2个不可以
        font:font-style font-weight font-size/line-height font-family;*/

        /*font-size/line-height: 10px/1.5代表行高是字体的1.5倍*/
        font:italic 700 10px/10px '微软雅黑';
        font: 10px/10px '微软雅黑';
    }

2.文本属性

<p>color:文本颜色</p>
<p>text-align:center/left/right    对齐文本</p>
<p>text-decoration:underline(下划线) line-through(删除线) none(去掉a标签的下划线)</p>
<p>text-indent 段落首行文本缩进x个字符 可以设置2em(当前文字2个距离)</p>
<p>line-height 行间距(文字的高度+上下间距)</p>

.ting {
    color:red;
    /*text-align: center;*/
    /*text-decoration: underline;*/
    text-decoration: none;
    /*text-indent: 20px;*/
    text-indent: 2em;
    line-height: 5px;

}

3.css选择器:

css选择器
1.后代选择器:(ul下所有的li设置样式)
2.子选择器:>
3.并集选择器:,(选中多个标签)
4.伪类型选择器(:hover,:active,:linked,:visited :focus)

<p>块内元素(独占一行 p,div,h1,ul,li)p标签不能放div元素</p>
<p>行内元素(span,a,strong,em,ins.......  不可以直接设置宽度高度)</p>
<p>行块元素(input,td,img可以设置宽度和高度的行内元素)</p>

行内元素:直接设置宽高是不起作用的,行内元素的宽度就是内容的宽度(宽度随内容的增多变大,不能放置块元素)


行内元素可以转化块内元素:display:block;
块内元素可以转化块行元素:display:inline;
块内元素可以转化行内行元素:display:inline-block;<br />

*******************实现文字居中:让文字的高度(line-height)等于盒子(div)的height

4.背景颜色

.group{
    width: 200px;
    height: 40px;
    /*background-color: red;*/
    line-height: 40px;
    /*background-image: url(icon.png);
    background-repeat: no-repeat;

    背景位置可以使用 left center等方位词(left right top center),也可以使用精确的位置,x轴,y轴距离(y轴可以省略,默认居中) 也可以混合写 20px center
    background-position: -35px; 

    /*图片是否固定 scroll(默认)/fixed  
    background-attachment: fixed;*/

    /*background简写: 背景染色 图片地址 是否重复 是否固定 位置*/
    background: green url('icon.png') no-repeat fixed center top

    /* 背景色半透明  rgba前3个是颜色,最后一个是透明度介于0-1*/
    /*background: rgba(0,0,0,0.3);*/

}

4.css三大特性:优先级

!important > style(内联) > id > class > 元素 > 通配符
继承的权重为0,不管你父亲的权重有多高,子元素的权重为0
权重还可以叠加

5.ul li

去掉小圆点
list-style:none