html 表单默认选择器,常见表单元素和css选择器

实例

html>

Title

ul li {

list-style: none; /*去掉默认列表项样式*/

float: left;  /*左浮动*/

width: 40px;  /*设置宽度*/

height: 40px; /*设置高度*/

line-height: 40px; /*文本垂直居中*/

text-align: center; /*文本水平居中*/

border-radius: 50%; /*设置边框圆角*/

box-shadow: 2px 2px 2px #888;

background: skyblue; /*背景色天蓝*/

margin-right: 5px; /*每个球之间的右外边距*/

}

ol li {

list-style: none; /*去掉默认列表项样式*/

float: left;  /*左浮动*/

width: 40px;  /*设置宽度*/

height: 40px; /*设置高度*/

line-height: 40px; /*文本垂直居中*/

text-align: center; /*文本水平居中*/

border-radius: 50%; /*设置边框圆角*/

box-shadow: 2px 2px 2px #888;

background: skyblue; /*背景色天蓝*/

margin-right: 5px; /*每个球之间的右外边距*/

}

/*属性选择器: 属性名*/

ul li[class] {

background-color: blueviolet;

}

/*属性选择器: 属性值*/

ul li[class="item2"] {

background-color: grey;

}

/*属性选择器: 以指定属性值开头*/

ul li[class^="cat"] {

background-color: brown;

}

/*属性选择器: 以指定属性值结束*/

ul li[class$="pig"] {

background-color: red;

}

/*属性选择器: 属性值中包含指定子串*/

ul li[class*="te"] {

/*第1,2小球会变色,思考为什么1球没变色?*/

/*第1个小球是id,它的优先级大于标签属性选择器,改成class就会有效果*/

background-color: green;

}

/*后代选择器*/

body ul li {

border: 1px solid black;

}

/*子选择器*/

ul > li[class$="pig"] {

background-color: greenyellow;

}

/*相邻选择器*/

ul li[class$="pig"] ~ * {

/*选择当前元素之后的所有同级元素(不含当前)*/

background-color: black;

color: white;

}

/*相邻兄弟选择器*/

ul li[class$="pig"] + li {

background-color: pink;

color: black;

}

/*群组选择器*/

h1, p {

font-size: 2rem;

font-weight: lighter;

margin: 0;

}

/*伪类选择器: 链接*/

a {

font-size: 2rem;

}

/*访问前*/

a:link {

color:red;

}

/*访问后*/

a:visited {

color: orange;

}

/*获取焦点时*/

a:focus {

color: purple;

}

/*鼠标悬停时*/

a:hover {

color: green;

}

/*鼠标点击时*/

a:active {

color: blue;

}

/*伪类选择器: 位置*/

/*选择集合中的第一个元素*/

ul li:first-child {

background-color: #efefef;

background-color: #efefef!important;

}

/*选择集合中的最后一个子元素*/

ul li:last-child {

background-color: red;

}

/*按索引选择指定的元素,注意从1开始计数*/

ul li:nth-child(5) {

background-color: red;

}

/* 选择所有的偶数小球变色 */

/* 2n偶数, even偶数, 2n+1奇数, odd奇数*/

ul li:nth-child(even) {

background-color: purple!important;

}

/*伪类选择器: 根据子元素数量*/

/*选择具有唯一子元素的元素*/

ol:only-child {

background-color: lawngreen;

}

/* 选择指定类型的唯一子元素 */

ol li:only-of-type {

background-color: lawngreen;

}

/* 倒数选择指定位置的元素 */

ul li:nth-last-child(3) {

/*将倒数第3个小球变色,实际上第8号球*/

background-color: wheat!important;

}

/*选择指定父级的第二个

子元素*/

ol li:nth-of-type(2) {

background-color: wheat;

}

ol li:nth-child(odd) {

background-color: deeppink;

}

  • 1
  • 2
  • 3
  • 4
  • 5
  1. 6
  2. 7
  3. 8
  4. 9
  5. 10

运行实例 »

点击 "运行实例" 按钮查看在线实例

实例

html>

px,em,rem

html {

/*浏览器默认为16px*/

/*font-size: 16px;*/

/*谷歌文本最小12px,设置为10px无效*/

/*font-size: 10px;*/

}

.px {

font-size: 20px;

width: 100px;  /*px,相对于屏幕*/

height: 100px; /*后面有line-height,此处可选*/

background-color: lightgreen;

text-align: center;

line-height: 100px;

}

.em {

font-size: 20px;

width: 5em;  /*em,相对于当前元素或父元素文本大小*/

height: 5em;

background-color: lightblue;

text-align: center;

line-height: 100px;

}

/*css3新增单位*/

.rem {

font-size:1.25rem;

width: 6.25rem;  /*em,相对于根html元素文本大小*/

height: 6.25rem;

background-color: lightcoral;

text-align: center;

line-height: 6.25rem;

}

元素的单位

px
em
rem

运行实例 »

点击 "运行实例" 按钮查看在线实例

1534394792652606.png

1534394804164751.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值