CSS学习笔记(一)

CSS学习笔记(一)

1. 参考网址

菜鸟教程

2. CSS的创建

2.1 插入样式表的三种方式
  • 外部样式表(External style sheet)
  • 内部样式表(Internal style sheet)
  • 内联样式(Inline style)
/*外部样式表*/
<head>
	<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>

/*内部样式表,当单个文档需要特殊的样式时,就应该使用内部样式表*/
<head> 
    <style> 
        hr {
            color:sienna;
        }
        p {
            margin-left:20px;
        }
        body {
            background-image:url("images/back40.gif");
        }
    </style> 
</head>

/*内联样式*/
<p style="color:sienna;margin-left:20px">这是一个段落。</p>
2.2 多重样式优先级

(内联样式)Inline style > (内部样式)Internal style sheet >(外部样式)External style sheet > 浏览器默认样式

2.3 几个注意点
  • 不要在属性值与单位之间留有空格(如:“margin-left: 20 px” ),正确的写法是 “margin-left: 20px” 。
  • 如果外部样式放在内部样式的后面,则外部样式将覆盖内部样式。
2.4 CSS中颜色的定义
  • 十六进制 - 如:"#ff0000"
  • RGB - 如:“rgb(255,0,0)”
  • 颜色名称 - 如:“red”

3. CSS background(背景)

3.1 CSS 属性定义背景效果
  • background-color
  • background-image
  • background-repeat
  • background-attachment
  • background-position
3.2 背景颜色
  • background-color 属性定义了元素的背景颜色.
/*背景颜色*/
body {
    background-color:#999;
}

image-20210830155416082

3.3 背景图像
  • background-image 属性描述了元素的背景图像.
  • 默认情况下,背景图像进行平铺重复显示,以覆盖整个元素实体.
/*背景图像*/
body {
    background-image:url('https://img0.baidu.com/it/u=1296489273,320485179&fm=26&fmt=auto&gp=0.jpg');
}

image-20210830155206159

3.4 背景图像 - 水平或垂直平铺
/*水平平铺*/
body {
    background-image:url('https://img0.baidu.com/it/u=1296489273,320485179&fm=26&fmt=auto&gp=0.jpg');
    background-repeat:repeat-x;
}

image-20210830160104910

/*垂直平铺*/
body {
    background-image:url('https://img0.baidu.com/it/u=1296489273,320485179&fm=26&fmt=auto&gp=0.jpg');
    background-repeat:repeat-y;
}

image-20210830160204262

3.5 背景图像- 设置定位与不平铺
/*不平铺*/
body {
    background-image:url('https://img0.baidu.com/it/u=1296489273,320485179&fm=26&fmt=auto&gp=0.jpg');
    background-repeat:no-repeat;
}

image-20210830160554051

/*设置定位*/
body
{
    background-image:url('https://img0.baidu.com/it/u=1296489273,320485179&fm=26&fmt=auto&gp=0.jpg');
    background-repeat:no-repeat;
    background-position:right top;
}

image-20210830161720488

3.6 背景-简写属性

当使用简写属性时,属性值的顺序为::

  • background-color
  • background-image
  • background-repeat
  • background-attachment
  • background-position
/*简写属性*/
body {
    background:#ffffff url('https://img0.baidu.com/it/u=1296489273,320485179&fm=26&fmt=auto&gp=0.jpg') no-repeat right top;
}

image-20210830162553164

4. CSS Text(文本)

4.1 文本颜色
/*文本颜色*/
body {
    color:yellow;
}
h1 {
    color:#00ff00;
}
h2 {
    color:rgb(255,0,0);
}

image-20210830163449738

4.2 文本的对齐方式
  • 文本排列属性是用来设置文本的水平对齐方式。
  • 文本可居中或对齐到左或右,两端对齐.
  • 当text-align设置为"justify",每一行被展开为宽度相等,左,右外边距是对齐(如杂志和报纸)。
/*文本的对齐方式*/
h1 {text-align:right;}
p.date {text-align:left;}
p.main {text-align:justify;}

image-20210830164224022

image-20210830164256385

4.3 文本修饰
  • text-decoration 属性用来设置或删除文本的装饰
/*删除链接的下划线*/
a {text-decoration:none;}

image-20210830164835487

/*上划线、删除线、下划线*/
h1 {text-decoration:overline;}
h2 {text-decoration:line-through;}
h3 {text-decoration:underline;}

image-20210830165014310

4.4 文本转换
  • 文本转换属性是用来指定在一个文本中的大写和小写字母。
  • 可用于所有字句变成大写或小写字母,或每个单词的首字母大写。
/*大写、小写、首字母大写*/
p.uppercase {text-transform:uppercase;}
p.lowercase {text-transform:lowercase;}
p.capitalize {text-transform:capitalize;}

image-20210830165843078

4.5 文本缩进
  • 文本缩进属性是用来指定文本的第一行的缩进。
/*文本缩进*/
p {text-indent:100px;}

image-20210830170612397

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值