css零散笔记回顾

1、text-align: 也可以对图片进行居中
2、属性选择器
[title] {
	color: red;
}

/* 必须title属性等于div才选中*/
[title='div']{
	background-color: blue;
}
3.兄弟选择器
/* 后一个相邻的兄弟 */
.box + .content {
	color: red;
}
/* 后面所有兄弟 */
.box ~ div {
	font-size: 30px;
}
4.交集选择器
/* 不可以出现空格,div .box,这样就变成后代选择器了*/
div.box {
	color: red;
	font-size: 20px;
}
5.并集选择器
p,
h2, 
h3 {
	color: red;
}
6.伪类的理解
/* 需求: 一个div元素,鼠标放上去,文字变成红色 */
/* hover: 伪类*/
div:hover {
	color: red;
}
7.动态伪类
/* a元素的链接从未被访问过 */
a:link {
	color: red;
}
/* a元素被访问后的状态*/
a:visited {
	color: green;
}
/* a元素鼠标放在上面*/
a:hover {
	color: yellow;
}
/* a元素点击未松手*/
a:active {
	color: blue;
}
8.伪元素befor、 after
9. 默认继承
/* 给div所有子元素字体设置红色 */
div.box {
  color: red
}

<div class="box">
  <h1>我是h1标题</h1>
  <p>
    我是p标题
    <span>呵呵呵呵</span>
  </p>
  <span>我是span标题</span>
</div>
10.元素的隐藏: display-visibility-opacity
.box {
	/* 不占据空间 */
	display: none;
}
.content {
	/* 隐藏了,但是依然占据空间 */
	visibility: hidden;
}
11. width默认值
.box {
	background-color: red;
	/* width如果没有设置,默认是auto, auto 交给浏览器来决定 */
	width: auto;
}
.title {
	/* 行内级非替换元素设置宽高无效*/
	width: auto;
	/* 如果是行内级,width:auto,包裹内容 */
	display: inline-block;
	width:auto;
}
12. 外边距-margin
/* box 跟 container之间是有间隙的,是由换行等造成的,可以通过font-size/浮动/flex布局来解决*/
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      /* box跟container之间是有间隙的,是由换行等造成的,可以通过font-size\浮动\flex布局解决 */
      /* 如果有间距,设置margin就不准确了 */
      body {
        font-size: 0;
      }
      .box {
        display: inline-block;
        width: 100px;
        height: 100px;
        background-color: red;
        /* margin-bottom: 30px; */
      }
      .container {
        display: inline-block;
        width: 100px;
        height: 100px;
        background-color: green;
        /* 上下的magin会折叠,左右是不会的 */
        /* margin-top: 30px; */
      }
    </style>
  </head>
  <body>
    <div class="box"></div>
    <div class="container"></div>
  </body>
</html>
13.nth-of-type
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      /* 倒数的某一个时 */
      ul > li:nth-last-child(2) {
        color: red;
      }

      /* 倒数的后几个是 */
      ul > li:nth-last-child(-n + 3) {
        font-size: 30px;
      }
    </style>
  </head>
  <body>
    <ul>
      <li>列表元素1</li>
      <li>列表元素2</li>
      <li>列表元素3</li>
      <li>列表元素4</li>
      <li>列表元素5</li>
      <li>列表元素6</li>
      <li>列表元素7</li>
      <li>列表元素8</li>
    </ul>
  </body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值