四十一、CSS相关属性

CSS属性相关

宽和高

width属性可以为元素设置宽度。

height属性可以为元素设置高度。

块级标签才能设置宽度,内联标签的宽度由内容来决定。

 <style>
        div {
            height: 50px;
            width: 100px;
        }
        /*给行内标签设置长宽没有任何影响*/
        span {
                height: 50px;
                width: 100px;
            }
    </style>

字体属性

文字字体

font-family可以把多个字体名称作为一个“回退”系统来保存。如果浏览器不支持第一个字体,则会尝试下一个。浏览器会使用它可识别的第一个值。
 
简单实例:
 <style>
        p {
            font-family: "Microsoft Yahei", "微软雅黑", "Arial", sans-serif;
            font-size: 24px;
            font-weight: lighter;
            /*color: red;*/
            /*color: #4e4e4e;*/
            /*color: rgb(128,128,128);*/
            /*color: rgba(0,0,0,1.0);  最后一个参数只能调节颜色的透明度 不能调节文本*/
        }
    </style>

字体大小

p {
  font-size: 14px;
}

如果设置成inherit表示继承父元素的字体大小值。

字重(粗细) 

font-weight用来设置字体的字重(粗细)。

描述
normal 默认值,标准粗细
bold 粗体
bolder 更粗
lighter 更细
100~900 设置具体粗细,400等同于normal,而700等同于bold
inherit 继承父元素字体的粗细值

文本颜色

颜色属性被用来设置文字的颜色。

颜色是通过CSS最经常的指定:

  • 十六进制值 - 如: FF0000
  • 一个RGB值 - 如: RGB(255,0,0)
  • 颜色的名称 - 如:  red

还有rgba(255,0,0,0.3),第四个值为alpha, 指定了色彩的透明度/不透明度,它的范围为0.0到1.0之间。

文字属性

文字对齐

text-align 属性规定元素中的文本的水平对齐方式。

描述
left 左边对齐 默认值
right 右对齐
center 居中对齐
justify 两端对齐
文字属性
     <style>
                                              对齐排列
        p {
            font-size: 16px;                  字体大小
            text-indent: 32px;                缩进多少
            /*text-align: center;*/           居中对齐
            /*text-align: left;*/             左对齐
            /*text-align: right;*/            右对齐
            /*text-align: justify;*/
                                               字体装饰

            /*text-decoration: underline;*/    下划线
            /*text-decoration: overline;*/     上划线
            /*text-decoration: line-through;*/ 删除线
        }
        a {
            text-decoration: none;             消除装饰(如下划线)
            color: orange;
        }
        a:hover {                               鼠标触碰
            color: blue;
        }
    </style>

文字装饰

text-decoration 属性用来给文字添加特殊效果。

描述
none 默认。定义标准的文本。
underline 定义文本下的一条线。
overline 定义文本上的一条线。
line-through 定义穿过文本下的一条线。
inherit 继承父元素的text-decoration属性的值。

常用的为去掉a标签默认的自划线:

a {
  text-decoration: none;
}

首行缩进

将段落的第一行缩进 32像素:

p {
  text-indent: 32px;
}

猜你喜欢

转载自www.cnblogs.com/wukai66/p/11480149.html
今日推荐