CSS
来源:互联网 发布:什么物流淘宝不能跟踪 编辑:程序博客网 时间:2024/06/01 12:22
CSS
一般放在head
标签内的Style
中。
3种选择器
分别是:标签选择器、类选择器、id选择器。
标签选择器:根据html的标签设置css
类选择器:在同类标签中使部分标签实现自己的风格。
id选择器:一般配合div使用。
<body> <ol> <li>锄禾日当午</li> <li class="myColor">汗滴禾下土</li> <li>谁知盘中餐</li> <li>粒粒皆辛苦</li> </ol> <div id="div1">层叠式样式表(CSS)是用于描述外观和格式化标记语言编写的文档的样式表语言</div> </body>
CSS:
<style type="text/css"> /* 标签选择器*/ li{ color:red; font-size:30px; } /*类选择器*/ .myColor{ color:blue; } /* id选择器*/ #div1{ border:5px solid red; width:100px; height:300px; background-color:lime; }}
属性选择器
属性选择器的格式
[属性名]{ 属性名:属性值;}
其中[]中可以是属性,也可以是[属性名=属性值],还有包含和以xx开头来判断等。
<style> [title]{ color: red; font-size: 1cm; }</style>
<p title="hello">Hello World</p><p title="hello">Hello JS</p>
还有其它格式:
[title=Java]{ color:green;}[title~=Android]{ color: blue;}[title|=pp]{ color: yellow;}
表单样式:
input[type=text]{ margin-bottom: 20px; display: block; background-color: yellow; width: 200px;}0input[type=button]{ display: block; background-color: yellow; width: 100px; margin-left: 30px;}
文字和文本属性
<style> div{ /* color:blue; */ /* font-weight:bold; */ /* font-size:35px; */ /* font-family:宋体; */ color:blue; font:bold 25px 黑体; text-indent:2em;/*缩进*/ line-height:35px;/*行高*/ }</style>
也可以一次写
font:bold 25px 黑体;
列表属性
list-style:简写属性,用于吧所有列表的属性设置于一个声明中
list-style-image:将图像设置为列表项的标志,就是左边的图标
text-decoration:none;:向文本添加修饰(下划线等)
<body><!--默认是一个空格,添加 代表增加一个空格--><ol> <li><a href="#">电视</a>         <a href="#">电视</a> <a href="#">电视</a></li> <li><a href="#">电视</a>   <a href="#">电视</a> <a href="#">电视</a></li> <li><a href="#">电视</a>   <a href="#">电视</a> <a href="#">电视</a></li> <li><a href="#">电视</a>   <a href="#">电视</a> <a href="#">电视</a></li></ol></body>
<style>li{ list-style:none; list-style-image:url("resource/arrow-icon.gif")}/* 去掉下划线 */a{ /* text-decoration:line-throgth; */ text-decoration:none;}</style>
背景属性
<head> <style> body{ background-color:blue; background-image:url("a.jpg"); background-position:right; } </style></head><body> 针对近日爆出浙江省中医院医源性艾滋病病毒感染事件,国家卫生计生委表示将对负有责任的单位和人员依法依规严肃处理和问责,要求进一步加强全国医疗机构内部管理,严格规范操作,开展医疗安全专项整顿活动。</body>
链接 Link
- 顺序:link–>visited–>hover–>active
- link:链接未访问
- visited:链接已经访问
- hover:鼠标放在链接上
- active:点击一瞬间
- css属性:
- color 链接字体颜色
- text-decoration 下划线等
- background-color 背景色
a:link { color: #b71c1c; text-decoration: overline; background-color: #212121;}a:visited { color: #1A237E; text-decoration: underline; background-color: #FFEB3B;}a:hover { color: #FFEB3B; text-decoration: line-through;}a:active { color: #3E2723; text-decoration: underline;}
<a href="https://www.baidu.com/" target="_self">百度一下,你就知道</a>
表格 Table
<table border="1" cellspacing="0" cellpadding="10px"> <tr> <th>姓名</th> <th>国籍</th> </tr> <tr> <td>奥巴马</td> <td>美国</td> </tr> <tr> <td>普京</td> <td>俄罗斯</td> </tr></table>
style
table,th,td { border: 3px black solid;}
<table id="table1"> <tr> <th>姓名</th> <th>国籍</th> </tr> <tr> <td>奥巴马</td> <td>美国</td> </tr> <tr> <td>普京</td> <td>俄罗斯</td> </tr></table>
#table1 { width: 100%; height: 100px; border-collapse: collapse; //单元格间距为0 text-align: right; //无效}
盒子模型
<p>盒子模型演示</p><div>这是一个盒子模型,内容宽度为200px,外边距为20px,内边距为20px,边框为30px</div>
div { background-color: lightgreen; margin: 20px; padding: 20px; border: 30px solid green;}
不同部分的说明:
Margin(外边距) - 清除边框外的区域,外边距是透明的。Border(边框) - 围绕在内边距和内容外的边框。Padding(内边距) - 清除内容周围的区域,内边距是透明的。Content(内容) - 盒子的内容,显示文本和图像。
边框 border
<p class="dotted">点线边框</p><p class="none">没有边框</p><p class="solid">实线边框</p><p class="dashed">虚线边框</p>
p.none { border-style: none;}p.solid { border-style: solid; border-width: 20px; border-color: #FFEB3B;}p.dotted { border-style: dotted;}p.dashed { border-left-style: dashed; border-top-style: dotted; border-right-style: double; border-bottom-style: groove;}
对齐
有3种对齐方式:
- 居中对齐
- 左右对齐(水平对齐)
- 垂直对齐
居中对齐
- 元素居中
- 内容居中
- 图片居中
元素居中:
margin: auto;
内容居中:
text-align: center;
图片居中(把图片放在 块元素中,然后使用margin)
margin: auto;display: block;
左右对齐
方法一:position
position: absolute;right: 0;
方法二:float
float: left;
垂直对齐
padding: 80px 0;
如果还要水平居中,还要加
text-align: center;
阅读全文
0 0
- CSS
- css
- css
- css
- css
- CSS
- CSS
- css
- css
- CSS
- css
- css
- CSS
- css
- CSS
- css
- CSS
- css
- C++ 引用
- 求和
- 蓝牙项目
- SpringMVC+Spring+Hibernate搭建实例
- Recurrent Neural Networks Tutorial阅读笔记
- CSS
- 从 http://www.batteries.com 搜索引擎优化效果谈起
- hibernate save集合时只有一个值
- Python笔记
- NAT技术的简要概述
- EditView与TextView如何实现长按复制、粘贴、选择
- myeclipse部署
- CentOS 6.5安装Erlang及RabbitMQ
- 04构建一个网站测试计划