前提
HTML+CSS+JavaScript=结构+表现+交互
如何学习?
css是什么
css怎么用(快速入门)
CSS选择器(重点+难点)
美化网页(文字,阴影,超链接,列表,渐变…)
盒子模型
浮动
定位
网页动画(特效效果)
Cascading Style Sheet 层叠级联样式表
CSS:表现(美化网页)
发展史:
css1.0
css2.0 :DIV(块)+CSS,HTML和CSS结构分离的思想,网页变得简单
css2.1:浮动,定位
css3.0:圆角,阴影,动画… 浏览器兼容性
建议使用内容和表现分离格式!
css的优势
优先级(就近原则):行内样式;内部样式;外部样式
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index.htmltitle>
<style>
h1{
color: green;
}
style>
<link rel="stylesheet" href="css/style.css">
head>
<body>
<h1 style="color: red">我是标题h1>
body>
html>
/* 外部样式*/
h1{
color: yellow;
}
作用:选择页面上的某一个或者某一类元素
基本选择器
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
<style>
/*标签选择器,会选择到页面上所有的这个标签的元素
标签{}*/
h1 {
color: #16f563;
}
p {
font-size: 80px;
}
style>
head>
<body>
<h1>学javah1>
<h1>学javah1>
<p>听kk说p>
body>
html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
<style>
/*类选择器格式
.class的名称{}
好处,可以多个标签归类,是同一个class
*/
.kk{
color: aliceblue;
}
.kk1{
color: aqua;
}
style>
head>
<body>
<h1 class="kk">标题一h1>
<h1 class="kk1">标题二h1>
<h1 class="kk1">标题三h1>
<p class="kk1">P标签p>
body>
html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
<style>
/* id选择器:id必须保证全局唯一!
#id名称{}
不遵循就近原则,固定的
id选择器>class选择器>标签选择器
*/
#kk{
color: red;
}
.kk1{
color: #16f563;
}
h1{
color: blue;
}
style>
head>
<body>
<h1 id="kk">标题一h1>
<h1 class="kk1">标题二h1>
<h1 class="kk1">标题三h1>
<h1 >标题四h1>
<h1 >标题五h1>
body>
html>
/* 后代选择器
body*/
body p{
background: red;
}
/* 后代选择器body*/
body>p{
background: red;
}
/*相邻兄弟选择器*/
.active + p{
background: aquamarine;
}
/*通用兄弟选择器,当前选中向下所有元素*/
.active~p{
background: blueviolet;
}
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
<style>
/* p{*/
/* background: #16f563;*/
/* }*/
/* 后代选择器body*/
/* body>p{
background: red;
}*/
/*相邻兄弟选择器*/
/*.active + p{
background: aquamarine;
}*/
/*通用兄弟选择器,当前选中向下所有元素*/
.active~p{
background: blueviolet;
}
style>
head>
<body>
<p>p0p>
<p class="active">p1p>
<p>p2p>
<p>p3p>
<ul>
<li><p>p4p>li>
<li><p>p5p>li>
<li><p>p6p>li>
ul>
<p class="active">p7p>
<p>p8p>
body>
html>
伪类:条件
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
<style>
/*ul的第一个元素*/
ul li:first-child{
background: antiquewhite;
}
/*ul的最后一个元素*/
ul li:last-child{
background: aqua;
}
/*2代表第二个*/
p:nth-child(2){
background: deeppink;
}
style>
head>
<body>
<p>p0p>
<p class="active">p1p>
<p>p2p>
<p>p3p>
<ul>
<li><p>p4p>li>
<li><p>p5p>li>
<li><p>p6p>li>
ul>
<p class="active">p7p>
<p>p8p>
body>
html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
<style>
.demo a{
float: left;
display: block;
height: 50px;
width: 50px;
border-radius: 10px;
background: blue;
text-align: center;
color: gray;
text-decoration: none;
margin-right: 5px;
font:bold 20px/50px Arial ;
}
/*属性选择器*/
/*属性名=属性值(正则)
= 绝对的等于
*= 包含的元素
*/
/*存在id属性的元素 a[]{}*/
/* a[id]{
background: #16f563;
}*/
/*a[id=first]{
background: #37ff00;
}
a[class*="links"]{
background: #dc3222;
}*/
/*选中href中以http开头的元素
*/
/* a[href^=http]{
background: chocolate;
}*/
/*选中以 pdf结尾的元素*/
a[href$=pdf]{
background: deeppink;
}
*/
style>
head>
<body>
<p class="demo">
<a href="http://www.baidu.com" class="links item first" id="first">1a>
<a href="" class="links item active" target="_blan" title="test">2a>
<a href="images/123.html" class="links item " >3a>
<a href="images/123.png" class="links item ">4a>
<a href="images/123.jpg" class="links item ">5a>
<a href="abc" class="links item ">6a>
<a href="/a.pdf" class="links item ">7a>
<a href="/abc.pdf" class="links item ">8a>
<a href="abc.doc" class="links item ">9a>
<a href="abcd.doc" class="links item last">10a>
p>
body>
html>
为什么要美化网页?
span 标签:重点突出的字用span套起来
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
<style>
#kk{
font-size: 50px;
}
style>
head>
<body>
欢迎学习:<span id="kk">javaspan>
body>
html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
<style>
body{
font-family: "Arial Black",楷体;
color: chocolate;
}
h1{
font-size: 50px;
}
.p1{
font-weight: bold;
}
style>
head>
<body>
<h1>CSS介绍h1>
<p class="p1">层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。CSS不仅可以静态地修饰网页,还可以配合各种脚本语言动态地对网页各元素进行格式化。p>
<p>CSS能够对网页中元素位置的排版进行像素级精确控制,支持几乎所有的字体字号样式,拥有对网页对象和模型样式编辑的能力p>
<p>When your dreams come alive you're unstppablep>
body>
html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
<style>
/*颜色:*/
/*单词*/
/*RGB 0~F*/
/* RGBA A:0-F
text-align:左右居中
段落首行缩进: text-indent: 2em;
行高和块的高度一致就可以上下居中line-height: height:
水平对齐 img span*/
img,span{
vertical-align: middle;
}
h1{
color: red;
text-align:center;
}
.p1{
text-indent: 2em;
}
.p3{
background: blue;
height: 300px;
line-height: 300px;
}
/*下划线*/
.l1{
text-decoration: underline;
}
/*中划线*/
.l2{
text-decoration: line-through;
}
/*上划线*/
.l3{
text-decoration: overline;
}
style>
head>
<body>
<p class="l1">123123p>
<p class="l2">123123p>
<p class="l3">123123p>
<h1>CSS介绍h1>
<p class="p1">层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。CSS不仅可以静态地修饰网页,还可以配合各种脚本语言动态地对网页各元素进行格式化。p>
<p>CSS能够对网页中元素位置的排版进行像素级精确控制,支持几乎所有的字体字号样式,拥有对网页对象和模型样式编辑的能力p>
<p class="p3">When your dreams come alive you're unstoppablep>
<p>
<img src="images/a.jpg" alt="">
<span>123123123span>
p>
body>
html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
<style>
a{
text-decoration: none;
color: black;
}
/* 超链接伪类*/
/*鼠标悬浮颜色(伪类)*/
a:hover{
color: deeppink;
font-size: 50px;
}
/*鼠标按住未释放的颜色*/
a:active{
color: #16f563;
}
style>
head>
<body>
<a href="#">
<img src="images/a.jpg" alt="">
a>
<p>
<a href="#">码出高效:Java开发手册a>
p>
<p>
<a href="ll">作者:孤尽老师a>
p>
<p id="price">
$:99
p>
body>
html>
背景颜色
背景图片
<style>
div{
width: 1000px;
height: 700px;
border: 1px solid red;
background-image: url("images/img.png");
}
/* 默认全部平铺 */
.div1{
background-repeat: repeat-x;
}
.div2{
background-repeat: repeat-y;
}
.div3{
background-repeat: no-repeat;
}
style>
什么是盒子
margin:外边距
border:边框
padding:内边距
1.边框
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
<style>
body{
/*body总有一个默认的外边距maigin:0*/
h1,ul,li,a,body {
maigin: 0;
padding: 0;
text-decoration: none;
}
}
#box{
width: 300px;
/*border 粗细,样式(solid),颜色*/
border:1px solid red;
}
h2{
font-size: 16px;
background-color: #16f563;
line-height: 30px;
color: brown;
}
form{
background: aqua;
}
/*伪类选择器*/
div:nth-of-type(1) input{
border: 3px solid black;
}
div:nth-of-type(2) input{
border: 3px dashed purple;
}
div:nth-of-type(3) input{
border: 3px solid #80a864;
}
style>
head>
<body>
<div id="box">
<h2>会员登陆h2>
<form action="#">
<div>
<span>用户名:span>
<input type="text">
div>
<div>
<span>密码:span>
<input type="text">
div>
<div>
<span>邮箱:span>
<input type="text">
div>
form>
div>
body>
html>
盒子计算方式
margin+border+padding+内容宽度
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
<style>
body{
/*body总有一个默认的外边距maigin:0*/
h1,ul,li,a,body {
maigin: 0;
padding: 0;
text-decoration: none;
}
}
#box{
width: 300px;
/*border 粗细,样式(solid),颜色*/
border:1px solid red;
margin: 0 auto ;
}
h2{
font-size: 16px;
background-color: #16f563;
line-height: 30px;
color: brown;
margin: 0;
}
form{
background: aqua;
}
input{
border: 1px solid black;
}
div:nth-of-type(1)
{
padding: 10px;
}
style>
head>
<body>
<div id="box">
<h2>会员登陆h2>
<form action="#">
<div>
<span>用户名:span>
<input type="text">
div>
<div>
<span>密码:span>
<input type="text">
div>
<div>
<span>邮箱:span>
<input type="text">
div>
form>
div>
body>
html>
四个角
/**/
/* 圆圈:圆角 =半径*/
div{
width: 100px;
height: 100px;
border: 10px solid red;
border-radius: 50px 20px 10px 5px;
}
style>
圆形
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
<style>
div{
width: 100px;
height: 50px;
background-color: red;
border-radius:50px 50px 0px 0px;
margin: 30px;
}
img{
width:100px;
height:100px;
border-radius: 80px;
}
style>
head>
<body>
<div>
div>
<img src="images/a.png" alt="">
body>
html>
盒子阴影
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
<style>
/**/
div{
margin: 0 auto;
width: 100px;
height: 100px;
border-radius: 100px;
box-shadow: 10px 10px 10px 10px yellow;
}
style>
head>
<body>
<div style="width: 300px;height: 300px;display: block;text-align: center ">
<img src="image/a.png" alt="">
div>
body>
html>
源码之家!!!!!!!!!!!!!!!!!!!!!!!!!
模板之家!!!!!!!!!!!!!!!!!!!!!!
vue!!!
块级元素:独占一行
行内元素:不独占一行
行内元素可以被包含在块级元素中;反之不可以!
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
<style>
div{
width: 100px;
height: 100px;
border: 1px solid red;
display: inline;
}
span{
width: 100px;
height: 100px;
border: 1px solid red;
display: inline-block;
/*!*变成块元素block*!*/
/*display: block;*/
}
style>
head>
<body>
<div>div块元素div>
<span>span行内元素span>
body>
html>
div{
margin: 10px;
padding: 5px;
}
#father{
border: 1px #000 solid;
}
.l01{
border: 1px #F00 dashed;
display: inline-block;
float: right;
}
.l02{
border:1px #00F dashed;
display: inline-block;
float: right;
}
.l03{
border:1px #060 dashed;
display: inline-block;
float: right;
}
.l04{
border:1px #666 dashed;
font-size :12px;
line-height :23px;
display: inline-block;
float: right;
}
clear
/* clear: right;
right右侧不允于有浮动元素
left左侧不允于有浮动元素
both两侧不允于有浮动元素
none*/
解决方案
#father{
border: 1px #000 solid;
height:800px;
}
html中
<div class="clear">div>
css中
.clear{
clear: both;
margin: 0;
padding: 0;
3.overflow :hidden
在父级元素中增加overflow
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
<style>
#content{
width: 200px;
height: 150px;
/*overflow: hidden;*/
overflow: scroll;
}
style>
head>
<body>
<div id="content">
<img src="images/images/a.jpg" alt="">
<p>
父级边框塌陷问题父级边框塌陷问题父级边框塌陷问题父级边框塌陷问题父级边框塌陷问题父级边框塌陷问题父级边框塌陷问题
p>
div>
body>
html>
#father:after{
content: '';
display: block;
clear: both;
}
小结:
简单,代码中避免空div
简单,元素假设有了固定高度,就会被现之
下拉的一些场景,不能使用
写法复杂一点,但无副作用!
对比 display和float
display
float
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
<style>
body{
padding: 20px;
}
div{
margin: 10px;
padding: 5px;
font-size: 12px;
line-height: 25px;
}
#father{
border: 1px #666 solid;
padding: 0;
}
#first{
border: 1px #6cd50c dashed;
background-color: #0000FF;
position: relative;/*相对定位,上下左右*/
top: -20px;
left: 20px;
}
#second{
border: 1px #ef5c5c dashed;
background-color: #e0ac28;
}
#third{
border: 1px #e0ac28 dashed;
background-color: purple;
position: relative;
bottom: -10px;
right: 20px;
}
style>
head>
<body>
<div id="father">
<div id="first">第一个盒子div>
<div id="second">第二个盒子div>
<div id="third">第三个盒子div>
div>
body>
html>
相对定位::position:relative
相对于原来的位置进行指定偏移,相对定位的话仍然在标准文档流中! 原来位置会被保留!!
position:relative(前提)
top: -20px;
left: 20px;
bottom: -10px;
right: 20px;
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
<style>
#box{
width: 300px;/*宽度*/
height: 300px;/*高度*/
padding: 10px;/*内边距*/
border: 2px solid red;/*边界宽度 实线 颜色*/
}
a{
width: 100px;/*宽度*/
height: 100px;/*高度*/
text-decoration: none;/*去掉下划线*/
background-color: deeppink;/*背景颜色*/
line-height: 100px;/*保证一行居中*/
text-align: center;/*文字居中*/
color: white;/*文字颜色*/
display: block;/*变成块元素*/
}
a:hover{
background: pink;/*伪类,点击显示颜色*/
}
.a2,.a4{
position: relative;
left: 200px;
top: -100px;
}
.a5{
position: relative;
left: 100px;
bottom: 300px;
}
style>
head>
<body>
<div id="box">
<a class="a1" href="#">链接1a>
<a class="a2" href="#">链接2a>
<a class="a3" href="#">链接3a>
<a class="a4" href="#">链接4a>
<a class="a5" href="#">链接5a>
div>
body>
html>
定位:基于xxx定位,上下左右~
1.没有父级元素定位到前提下,我们相对于浏览器定位
2.假设父级元素存在定位,我们通常相对于父级元素进行便宜。
3.在父级元素范围内移动
相对于原来的位置进行指定偏移,决对定位。不在标准文档流中! 原来位置不会被保留!!
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
<style>
div{
margin: 10px;
padding: 5px;
font-size: 12px;
line-height: 25px;
}
#father{
border: 1px #666 solid;
padding: 0;
position: relative;
}
#first{
border: 1px #6cd50c dashed;
background-color: #0000FF;
}
#second{
border: 1px #ef5c5c dashed;
background-color: #e0ac28;
position: absolute;
right: 30px;
top: -10px;
}
#third{
border: 1px #e0ac28 dashed;
background-color: purple;
}
style>
head>
<body>
<div id="father">
<div id="first">第一个盒子div>
<div id="second">第二个盒子div>
<div id="third">第三个盒子div>
div>
body>
html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
<style>
body{
height: 1000px;
}
div:nth-of-type(1){
/*绝对定位:相对于浏览器*/
width: 100px;
height: 100px;
background: red;
position: absolute;
right: 0;
bottom: 0;
}
div:nth-of-type(2)/*fixed,固定定位*/
{
width: 50px;
height: 50px;
background: #e0ac28;
position: fixed;
right: 0;
bottom: 0;
}
style>
head>
<body>
<div>div1div>
<div>div2div>
body>
html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
<link rel="stylesheet" href="style.css">
head>
<body>
<div id="content">
<ul>
<li><img src="images/a.jpg" alt="">li>
<li class="tipText">学习找kkli>
<li class="tigBg">li>
<li>时间:2099-1-1li>
<li>地点:月球一号基地li>
ul>
div>
body>
html>
#content{
width: 380px;
padding: 0px;
margin: 0px;
overflow: hidden;
font-size:12px ;/*字体*/
line-height: 25px;/*行高*/
border: 1px #000 solid/*边框*/
}
ul,li{
padding: 0px;
margin: 0px;
list-style: none;/*去掉园点*/
}
/*父级元素相对定位*/
#content ul{
position: relative;
}
.tipText,tipBg{
position: absolute;
width: 380px;
top: 380px;
height: 25px;
}
.tipText{
color: white;
/*z-index: 999;*/
background: #0f110f;
opacity: 0.5;/*背景透明度*/
}