CSS
负责页面显示的效果
CSS引入的方式
1
| <div style="width: 200px;height: 100px;background-color: red">这个是div标签</div>
|

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>CSS学习</title> <style type="text/css"> .box1 { width: 200px; height: 100px; background-color: green; } </style> </head> <body> <div class="box1">这个是div2标签</div> </body> </html>
|

1
| <link rel="stylesheet" href="css/0830.css">
|
css/0830.css文件:
1 2 3 4 5 6
| .box2 { width: 200px; height: 100px; background-color: blue; }
|

CSS的基本语法
CSS规则:选择器+一条或者多条声明
- 选择器通常是需要改变样式的HTML元素
- 每条声明由一个属性和一个值组成
- 属性:希望设置的样式属性,每个属性有一个值,属性和值被冒号分开
h1 {color:red;font-size:14px;}
h1:选择器
color:red;:声明
color:属性
red:值
选择器
1 2 3 4 5
| <style type="text/css"> body { background-color: blue; } </style>
|

1
| <div class="box1">登录</div>
|
1 2 3 4 5 6
| .box1 { background: rgba(255, 195, 160, 0.5); color: white; font: bold 22px/30px 'Monaco'; text-align: center; }
|

1 2 3 4
| #b2 { text-align: center; font: normal 36px/60px 'Monaco'; }
|

1
| <div name="div3">div3</div>
|
1 2 3
| div[name]{ color: red; }
|

1 2 3 4 5 6
| <div class="box2"> <div> <span><i>Hello</i></span> <i>Python</i> </div> </div>
|
1 2 3
| .box2 div span{ color: green; }
|

选择多组元素
1 2 3
| .box2, .box1 { font: normal 36px/60px 'Monaco'; }
|
active
focus
hover:重要
link
Visited
鼠标放上去生效
1 2 3
| .box1:hover{ color: red; }
|


属性
背景
背景色:background-color: blue;
背景图片:background-image: url("image/IMG_3609.JPG");
不平铺:background-repeat: no-repeat;
背景定位
水平居中:background-position: center;
顶部:background-position: top;
颜色
用单词表示颜色:blue
使用RGB的方式:rgb(111, 222, 333)
透明度的RGB方法rgba(111, 222, 333, 50)
http://tool.oschina.net/commons?type=3

在Pycharm中直接选择

文字
设置顺序:是否加粗 字号/行高 字体;
1
| font: bold 22px/30px 'Monaco';
|
文字锁进
文字居中:text-align: center;
CSS模型框
规定了元素框处理元素内容,内边框,边框,外边距

内边距:padding
外边距:margin
传入顺序:上右下左「顺时针」
边框线:border
1 2 3 4 5 6 7 8
| .box1 { width: 300px; height: 150px; background: aqua; padding: 10px; border: solid 2px blue; margin: 80px; }
|


使用以上知识完成登录页面
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>登录页面</title> <style type="text/css"> body { background: #396b94 url("image/IMG_3609.JPG") center no-repeat; }
.login_box { width: 520px; height: 300px; margin: 15% auto; background: rgba(0, 0, 0, 0.25); text-align: center; border-radius: 8px; }
.login_title { color: #ffffff; font: bold 22px/40px 'Microsoft Sans Serif'; padding-top: 20px; }
.input_text { height: 40px; margin: 20px auto; width: 60%; border-radius: 8px; }
.btn { height: 100%; width: 100%; font: bold 22px/40px 'Microsoft Sans Serif'; background: #396b94; color: white; border: 0; border-radius: 8px; }
.input { height: 100%; width: 100%; font: bold 18px/40px 'Microsoft Sans Serif'; border-radius: 8px; border: solid 0.1px #57dbff; text-indent: 20px;
}
</style> </head> <body> <div class="login_box"> <div class="login_title">管理员登录</div> <form action=""> <div class="input_text"> <input type="text" class="input" placeholder="请输入账号"> </div> <div class="input_text"> <input type="password" class="input" placeholder="请输入密码"> </div> <div class="input_text"> <input type="submit" class="btn" value="点击登录"> </div> </form> </div> </body> </html>
|
