<title>css的引入方式</title>
<!-- 外部样式表 -->
<!-- <link rel="stylesheet" href="css/first.css"> -->
<style>
/* 引入其他的css样式 */
@import url("css/second.css");
/* 内部样式表 */
div{
width: 100px;
height: 100px;
background-color: red;
}
</style>
</head>
<body>
<div></div>
<p>11111</p>
<!-- 内联样式表 -->
<div style="width: 200px;background-color:cyan"></div>
</body>
<title>背景色</title>
<!-- 网页三原色:红 绿 蓝 -->
<style>
div{
width: 200px;
height: 100px;
/* background-color: gold; */
/* background-color: rgba(255,0,0,1); */
background-color: #ff0000;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
<!-- 三种方式来表示颜色:单词 rgba(红 绿 蓝 透明度) rgb 十六进制 -->
</html>
<!-- 内部样式表和外部样式表取决于哪个后引入 内联样式表的优先级是最高的 -->
<title>背景图</title>
<style>
img{
width: 180px;
height: 100px;
}
div{
width: 400px;
height: 400px;
background-color: red;
background-image: url(img/dm.png);
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
}
</style>
</head>
<body>
<img src="img/dm.png" alt="">
<div>
<p>这是一只瑞希</p>
</div>
</body>
</html>
<!-- background-size:w(宽度) h(高度);
如果只给其中一个,另一边会等比例变化
两个特殊的值:contain:图片的场边占满父级
cover: 图片的短边占满父级-->
<title>文本</title>
<style>
*{
margin: 0;
padding:0;
}
html{
font-size:16px;
}
p{
color: skyblue;
/* height: 50px; */
background-color: pink;
font-size: 30px;
/* 14px是一般浏览器允许的最小像素,16px是浏览器的默认像素 */
/* font-size: 4em; */
font-family: 'Courier New', Courier, monospace ;
/* 文本对齐方式 */
text-align: left;
line-height: 50px;
/* 首行缩进 */
text-indent: 2em;
/* text-indent: 100px; */
/* 字体间距 */
letter-spacing: 5px;
/* 单词间距 */
word-spacing: 10px;
/* 文本大小写 */
text-transform: uppercase;
}
a{
/* 文本装饰线 */
font-size: 40px;
text-decoration:none;
}
}
</style>
</head>
<body>
<p>巴卫这只狐狸很帅气,巴卫这只狐狸很帅气,巴卫这只狐狸很帅气,巴卫这只狐狸很帅气</p>
<p>welcome to csdn</p>
<a href="http://ac.csdn.net">csdn</a>
</body>
</html>
<!-- em是相对单位 1em等于父级标签的字体大小 -->
<!-- 当line-height的值等于height的值,文本垂直居中 -->
<title>常用的选择器</title>
<style>
*{
margin: 0px;
padding: 0px;
list-style: none;
}
h1,p{
/* 群组选择器 */
color: red;
}
.c{
/* class选择器 */
color: green;
}
#big{
font-size: 30px;
color: blue;
}
div p{
/* 后代选择器 */
color: cyan;
}
div>p{
/* 子代:直接子集 */
color: pink;
}
/* 属性选择器 */
[class="ok"]{
/* 最好具体带上之后的名称,哪个标签有class */
color: gold;
}
</style>
</head>
<body>
<p>123</p>
<h1>welcome to csdn</h1>
<p class="c">csdn</p>
<p class="c" id="big">天天向上</p>
<ul>
<li class="ok">一二三四</li>
<li>以而散思</li>
<li>怡尔叁斯</li>
</ul>
<div>
<p>人生若只如初见</p>
<span><p>何事秋风悲画扇</p></span>
</div>
</body>
</html>
<!-- 一个id名,在同一个html文件中只能出现一次 -->
<!-- 优先级:id(权重100)>class(10)>tag(1) -->
<!-- 内联样式权重1000 -->
<!-- 后代选择器权重相加(权重越高数字越小) -->
@import url("second.css");
/* 在css里面引入其他的css文件 */
first.css
div{
width: 200px;
height: 200px;
background-color: pink;
}
second.css
目录
css的引入方式
背景色
背景图
文本
常用的选择器