CSS笔记
初级篇
===========================选择器============================
元素选择器
css:
h1{color: red}
html:
<h1> hello world </h1>
类型选择器
css:
koo{color: red}
html:
<koo> hello world </koo>
属性选择器
css:
[title]{color: red} //指定属性
html:
<koo title=""> hello </koo>
css:
[href][title]{color: red} //指定同时拥有属性值
html:
<koo href="#" title="">hello</koo>
css:
[title="hello"]{color: red} //指定属性及其值
html:
<koo title="hello">hello</koo>
[attribute] 用于选取带有指定属性的元素。
[attribute=value] 用于选取带有指定属性和值的元素。
[attribute~=value] 用于选取属性值中包含指定词汇的元素。
[attribute|=value] 用于选取带有以指定值开头的属性值的元素,该值必须是整个单词。
[attribute^=value] 匹配属性值以指定值开头的每个元素。
[attribute$=value] 匹配属性值以指定值结尾的每个元素。
[attribute*=value] 匹配属性值中包含指定值的每个元素。
类选择器
css:
.lemon {color: red}
html:
<h1 class="lemon"> hello </h1>
css:
.foo.lemon {color:red} //不能加空格
html:
<h1 class="lemon foo">hello </h1>
id选择器
css:
#lemon {color: red} //id是唯一不可以叠加
html:
<h1 id="demon"> hello </h1>
伪类
:active 向被激活的元素添加样式。
:hover 当鼠标悬浮在元素上方时,向元素添加样式。
:link 向未被访问的链接添加样式。
:visited 向已被访问的链接添加样式。
:focus 向拥有键盘输入焦点的元素添加样式。
伪元素
:first-letter 向文本的第一个字母添加特殊样式。
:first-line 向文本的首行添加特殊样式。
:before 在元素之前添加内容。
:after 在元素之后添加内容。
==============================逻辑结构====================================
分组:
css:
h1 , p {color: red}
html:
<h1> hello world </h1>
<p> hello world </p>
通配:
css:
* {color: red}
html:
<h1> hello world </h1>
<koo> hello world </koo>
声明:
css:
h1 {
color: red;
font-size:19px;
}
html:
<h1> hello world </h1>
后代:
css:
h1 em {color: red}
html:
<h1> <em> hello <b>world</b></em><h1> //<em>元素内容生效
css:
h1 em b{color: red}
html:
<h1> <em> hello <b>world</b></em><h1> //<b>元素内容生效
子代:
css:
h1 > em {color: red}
html:
<h1> <em>hello world</em> </h1> //<em>为子代生效
<h1><b><em>hello world</em></b></h1> //<em>为孙代不生效
相邻:
css:
h1 + p + p{color:red}
html:
<h1>hello world</h1> //不生效
<p>hello world</p> //不生效
<p>hello world</p> //生效
同时:
css:
[title][href]{color: Red}
html
<html title="" href="">hello world </html>
===========================相关属性======================================
字体相关属性:
font-size //字体大小
font-weight //字体粗细bold normal
font-type //字体倾斜italic normal
font-family //字体样式sans-seria
文本相关属性:
color //文本颜色
text-align //文本对齐center left right justify
text-decoration //文本修饰underline overline line-through
text-height //文本高度
text-indent //文本缩进
text-transform //文本形式uppercase lowercase capitalize
word-spacing //单词距离
letter-spacing //字母距离
white-spacing //空白距离nowrap pre normal
边框相关属性:
border:color width style //边框颜色 粗细 样式
outline:color width style //轮廓颜色 粗细 样式
背景相关属性:
background-color //背景颜色
background-position //背景起始位置top bottom left center right value
background-image //背景图片url("")
background-repeat //背景重复no-repeat repeat-x repeat-y
background-attachment //背景固定scroll fixed
列表相关属性:
list-style-image //图标图片
list-style-position //图标位置inside outside
list-style-type //图标样式
表格相关属性:
border-colapse //边框合并
border-spacing //边框距离
caption-side //标题位置
empty-cells //空单元格hide show
table-layout //边框算法automatic fixed(固定宽度)
vertical-align //垂直对齐bottom center top
wdith //表格宽度
height //表格高度
=============================盒子模型=================================
组成成分:
border 边框
margin 外边距
padding 内边距
element 元素(包括height width)
block元素:
margin :默认值不同元素不一样p为16 h1为21
padding :默认为0
height :默认为21px
width :默认100%
inline元素
margin :默认为0
padding :默认为0
height :默认为21px
width :默认为字体宽度
############### inline #################
# padding 和 margin 对上下方向无效
# height 和 width 对行级完全无效
# left 和 top 对行级完全无效
# display:block 行级转换成块级
############### block #################
# padding 左右看不出改变,事实上width会减小
# left 和 top 对块级完全无效
# display:inline 级转换成行级
# padding和element 能改变大小及内容位置
# margin 能改变盒子的位置
############### 简写数值 #################
padding: top right bottom left
margin : top right bottom left
border-width: top right bottom left
background-position : left top
################ 复制值 #################
margin 与padding 的复制值特性
这里以margin为例子(padding一致)
margin:10px 60px 10px 60px;
等价于
padding:10px 60px;
原理:
如果缺少左外边距的值,则使用右外边距的值。
如果缺少下外边距的值,则使用上外边距的值。
如果缺少右外边距的值,则使用上外边距的值。
############### 外边距合并 ################
0.当两个水平外边距相遇时,它们之间的宽度是两个元素的外边距之和
如:
h2 在 h1 水平右方
h1 元素外边距:5px
h2 元素外边距:3px
h1 和 h2 之间的距离是8px.
1.当两个垂直外边距相遇时,它们之间的高度是其中一个元素的外边距(较大者)
如:
h2 在 h1 垂直下方
h1 元素外边距:5px
h2 元素外边距:3px
h1 和 h2 之间的距离是 5px 而不是8px.
2.当一个元素包含在另一个元素中时(假设没有内边距或边框把
外边距分隔开),它们的上和/或下外边距也会发生合并
如:
h2 在 h1 的里边(都没有设置边框和内边距)
h1:上外边距是6px;
h2:上外边距是9px;
h1 和 h2 距离顶部的距离为9px;
3.当一个空元素,它有外边距,但是没有边框或填充。在这种
情况下,上外边距与下外边距就碰到了一起,它们会发生合并
注释:只有普通文档流中块框的垂直外边距才会发生外边距合并
。行内框、浮动框或绝对定位之间的外边距不会合并。
=========================元素定位============================
display属性:
设置为none 则不显示元素内容及其框
设置为inline 则将其元素变为行级元素
设置为block 则将其元素变为块级元素
CSS 有三种基本的定位机制:普通流、浮动和绝对定位
普通流中的元素的位置由元素在(X)HTML中的位置决定
行级元素的padding margin border都不会影响其高度,但是行高可以做到
position属性:
static
元素框正常生成。块级元素生成一个矩形框,作为文档流的一部分,行内元素则会创建一个或多个行框,置于其父元素中。
relative
元素框偏移某个距离。元素仍保持其未定位前的形状,它原本所占的空间仍保留。
absolute
元素框从文档流完全删除,并相对于其包含块定位。包含块可能是文档中的另一个元素或者是初始包含块。元素原先在正
常文档流中所占的空间会关闭,就好像元素原来不存在一样。元素定位后生成一个块级框,而不论原来它在正常流中生成何种类型的框。
fixed
元素框的表现类似于将 position 设置为 absolute,不过其包含块是视窗本身。
##########################################################################
static:无特殊定位,对象遵循正常文档流
top,right,bottom,left属性不会被应用。
relative:相对定位,对象遵循正常文档流
top,right,bottom,left属性在正常文档流中偏移位置。
因为其原本占有的空间仍保留,所以周围的元素不会受该元素的偏移而影响
absolute:绝对定位,对象脱离正常文档流
top,right,bottom,left属性进行设置相对原来的位置偏移量
fixed: 固定定位,对象脱离正常文档流,
top,right,bottom,left属性进行设置相对原来的位置偏移量
属性以窗口为参考点进行定位,对象不会随着滚动滚动
===================================元素浮动===============================
浮动表示 元素脱离文档流并且向左或右贴紧对齐
float:left/right
w3school定义
浮动的框可以向左或向右移动,直到它的外边缘碰到包含框或另一个浮动框的边框为止。
由于浮动框不在文档的普通流中,所以文档的普通流中的块框表现得就像浮动框不存在一样。
清除浮动 元素不允许周围存在浮动元素,因此会另置一行的位置
clear:both/left/right
------------------------------------------------------------------------------------------------------------------------------------------2016.11.05(军训前一天)
(3)水平菜单
css:
ul{
float:left;
width:100%;
list-style:none;
padding:0px;
margin:0px;
}
li{
display:inline; //水平排列
}
a{
width:110px;
float:left; //盒子浮动
color:white;
text-decoration:none;
background-color:purple;
padding:0.2em 0.6em;
border-right:1px solid white;
}
a:hover {background-color:#ff3300}
html:
<ul>
<li><a href="#">Link one</a></li>
<li><a href="#">Link two</a></li>
<li><a href="#">Link three</a></li>
<li><a href="#">Link four</a></li>
</ul>
-------------------------------------------
(4)改变光标
html:
<span style="cursor:auto">Auto</span><br />
<span style="cursor:crosshair">Crosshair</span><br />
<span style="cursor:default">Default</span><br />
<span style="cursor:pointer">Pointer</span><br />
<span style="cursor:move">Move</span><br />
<span style="cursor:e-resize">e-resize</span><br />
<span style="cursor:ne-resize">ne-resize</span><br />
<span style="cursor:nw-resize">nw-resize</span><br />
<span style="cursor:n-resize">n-resize</span><br />
<span style="cursor:se-resize">se-resize</span><br />
<span style="cursor:sw-resize">sw-resize</span><br />
<span style="cursor:s-resize">s-resize</span><br />
<span style="cursor:w-resize">w-resize</span><br />
<span style="cursor:text"text</span><br />
<span style="cursor:wait">wait</span><br />
<span style="cursor:help">help</span>
---------------------------------------------------------
(5)div布局
css:
.contain{
width:100%;
border:1px solid grey;
}
.top,.foot{
background:grey;
color:white;
clear:both;
}
.left{
float:left;
width:35%;
}
.right{
margin-left:220px;
border-left:1px solid grey;
}
html:
<div class="contain">
<div class="top">
<h1>W3School.com.cn</h1>
</div>
<div class="left">
<p>"Never increase, beyond what is necessary,
the number of entities required to explain
anything." William of Ockham (1285-1349)</p>
</div>
<div class="right">
<h2>Free Web Building Tutorials</h2>
<p>At W3School.com.cn you will find all the Web-building
tutorials you need,from basic HTML and XHTML to advanced
XML, XSL, Multimedia and WAP.<br/>
W3School.com.cn - The Largest Web Developers Site On The Net!</p>
</div>
<div class="foot">
Copyright 2008 by YingKe Investment
</div>
</div>
====================================图片透明=================================
1.设置图片透明度
css:
img{
opacity:0.4;
filter:alpha(opacity=40); /* For IE8 and earlier */
}
img:hover{ //伪类也可以运用于图片
opacity:1.0;
filter:alpha(opacity=100); /* For IE8 and earlier */
}
html:
<img src="img.png" alt="this is picture" />
注意:
在 IE 中,必须添加 <!DOCTYPE>,这样才能将
:hover 选择器用于除了 <a> 之外的其它元素
2.设置透明背景
css:
div.transbox{
width: 338px;
height: 204px;
margin:30px;
padding:0;
border: 1px solid black;
filter:alpha(opacity=60); /* for IE */
opacity:0.4; /* CSS3 standard */
}
html:
<div class="transbox"><p>
This is some text that is placed in the transparent box.
This is some text that is placed in the transparent box.
This is some text that is placed in the transparent box.
</p></div>
CSS笔记的更多相关文章
- HTML+CSS笔记 CSS笔记集合
HTML+CSS笔记 表格,超链接,图片,表单 涉及内容:表格,超链接,图片,表单 HTML+CSS笔记 CSS入门 涉及内容:简介,优势,语法说明,代码注释,CSS样式位置,不同样式优先级,选择器, ...
- CSS笔记--选择器
CSS笔记--选择器 mate的使用 <meta charset="UTF-8"> <title>Document</title> <me ...
- HTML+CSS笔记 CSS中级 一些小技巧
水平居中 行内元素的水平居中 </a></li> <li><a href="#">2</a></li> &l ...
- HTML+CSS笔记 CSS中级 颜色&长度值
颜色值 在网页中的颜色设置是非常重要,有字体颜色(color).背景颜色(background-color).边框颜色(border)等,设置颜色的方法也有很多种: 1.英文命令颜色 语法: p{co ...
- HTML+CSS笔记 CSS中级 缩写入门
盒子模型代码简写 回忆盒模型时外边距(margin).内边距(padding)和边框(border)设置上下左右四个方向的边距是按照顺时针方向设置的:上右下左. 语法: margin:10px 15p ...
- HTML+CSS笔记 CSS进阶再续
CSS的布局模型 清楚了CSS 盒模型的基本概念. 盒模型类型, 我们就可以深入探讨网页布局的基本模型了.布局模型与盒模型一样都是 CSS 最基本. 最核心的概念. 但布局模型是建立在盒模型基础之上, ...
- HTML+CSS笔记 CSS进阶续集
元素分类 在CSS中,html中的标签元素大体被分为三种不同的类型:块状元素.内联元素(又叫行内元素)和内联块状元素. 常用的块状元素有: <div>.<p>.<h1&g ...
- HTML+CSS笔记 CSS进阶
文字排版 字体 我们可以使用css样式为网页中的文字设置字体.字号.颜色等样式属性. 语法: body{font-family:"宋体";} 这里注意不要设置不常用的字体,因为如果 ...
- HTML+CSS笔记 CSS入门续集
继承 CSS的某些样式是具有继承性的,那么什么是继承呢?继承是一种规则,它允许样式不仅应用于某个特定html标签元素,而且应用于其后代(标签). 语法: p{color:red;} <p> ...
- HTML+CSS笔记 CSS入门
简介: </span>年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的<span>脚本解释程序</span>,作为ABC语言的一种继承. & ...
随机推荐
- 异步编程 In .NET
概述 在之前写的一篇关于async和await的前世今生的文章之后,大家似乎在async和await提高网站处理能力方面还有一些疑问,博客园本身也做了不少的尝试.今天我们再来回答一下这个问题,同时我们 ...
- python爬取github数据
爬虫流程 在上周写完用scrapy爬去知乎用户信息的爬虫之后,github上star个数一下就在公司小组内部排的上名次了,我还信誓旦旦的跟上级吹牛皮说如果再写一个,都不好意思和你再提star了,怕你们 ...
- Hive on Spark安装配置详解(都是坑啊)
个人主页:http://www.linbingdong.com 简书地址:http://www.jianshu.com/p/a7f75b868568 简介 本文主要记录如何安装配置Hive on Sp ...
- HDU1671——前缀树的一点感触
题目http://acm.hdu.edu.cn/showproblem.php?pid=1671 题目本身不难,一棵前缀树OK,但是前两次提交都没有成功. 第一次Memory Limit Exceed ...
- AFNetworking 3.0 源码解读 总结(干货)(下)
承接上一篇AFNetworking 3.0 源码解读 总结(干货)(上) 21.网络服务类型NSURLRequestNetworkServiceType 示例代码: typedef NS_ENUM(N ...
- 基于注解的bean配置
基于注解的bean配置,主要是进行applicationContext.xml配置.DAO层类注解.Service层类注解. 1.在applicationContext.xml文件中配置信息如下 &l ...
- javascript函数
array.sort(function(a, b){ return a -b ; } ) 把数组 array 按照从小到大排序. [11, 22, 586, 10, -58, 86].sort(f ...
- iOS之App Store上架被拒Legal - 5.1.5问题
今天在看到App Store 上架过程中,苹果公司反馈的拒绝原因发现了这么一个问题: Legal - 5.1.5 Your app uses background location services ...
- Android之网络数据存储
一.网络保存数据介绍 可以使用网络来保存数据,在需要的时候从网络上获取数据,进而显示在App中. 用网络保存数据的方法有很多种,对于不同的网络数据采用不同的上传与获取方法. 本文利用LeanCloud ...
- mysql 行级锁的使用以及死锁的预防
一.前言 mysql的InnoDB,支持事务和行级锁,可以使用行锁来处理用户提现等业务.使用mysql锁的时候有时候会出现死锁,要做好死锁的预防. 二.MySQL行级锁 行级锁又分共享锁和排他锁. 共 ...