css 单项选择块,css

css

@import url(https://fonts.googleapis.com/css?family=Open+Sans:700,300);

.frame {

position: absolute;

top: 50%;

left: 50%;

width: 400px;

height: 400px;

margin-top: -200px;

margin-left: -200px;

border-radius: 2px;

box-shadow: 4px 8px 16px 0 rgba(0, 0, 0, 0.1);

overflow: hidden;

background: #FDA231;

color: #333;

font-family: 'Open Sans', Helvetica, sans-serif;

-webkit-font-smoothing: antialiased;

-moz-osx-font-smoothing: grayscale;

display: -webkit-box;

display: flex;

-webkit-box-align: center;

align-items: center;

-webkit-box-pack: center;

justify-content: center;

}

.center {

width: 60%;

height: 70%;

background: white;

box-shadow: 5px 5px 20px #00000044;

}

.dateContainer {

padding: 25px 20px;

display: -webkit-box;

display: flex;

-webkit-box-orient: vertical;

-webkit-box-direction: normal;

flex-direction: column;

-webkit-box-align: center;

align-items: center;

}

.dateContainer .day {

font-size: 20px;

font-weight: bold;

}

.dateContainer .date {

font-size: 14px;

padding: 5px;

}

.dateContainer:after {

content: '';

background: #aaa;

position: absolute;

height: 1px;

width: 160px;

top: 38%;

}

.task {

padding: 10px 20px;

position: relative;

}

.task input[type=checkbox] {

-webkit-box-flex: 1;

flex: 1;

display: none;

}

.task input[type=checkbox]:checked ~ .task-name {

color: #C8D4D9;

display: inline-block;

-webkit-text-decoration: line-through #C8D4D9;

text-decoration: line-through #C8D4D9;

}

.task input[type=checkbox]:checked ~ .task-btn {

-webkit-transform: scale(1.2);

transform: scale(1.2);

opacity: 0;

}

.task input[type=checkbox]:checked ~ .tick {

opacity: 1;

}

.task .task-name {

-webkit-transition: all 0.3s ease;

transition: all 0.3s ease;

font-size: 14px;

}

.task .task-btn {

width: 15px;

height: 15px;

border: 1px solid black;

border-radius: 100%;

position: absolute;

right: 10%;

-webkit-transition: all 0.3s ease;

transition: all 0.3s ease;

}

.task .task-btn:hover {

cursor: pointer;

}

.task .tick {

width: 5px;

height: 13px;

border: solid #C8D4D9;

border-width: 0 2px 2px 0;

-webkit-transform: rotate(45deg);

transform: rotate(45deg);

position: absolute;

right: 12%;

opacity: 0;

-webkit-transition: all 0.4s ease;

transition: all 0.4s ease;

}

### CSS 选择器概述 CSS 选择器是一种强大的工具,用于定位 HTML 文档中的特定元素,并对其应用样式。掌握不同类型的 CSS 选择器及其用法对于前端开发至关重要。 #### 基本选择器 基本选择器是最常用的几种选择器之一,主要包括以下几类: 1. **元素选择器 (Type Selector)** 元素选择器通过匹配 HTML 的标签名称来选取元素。例如,`p {}` 将应用于所有的 `<p>` 标签[^1]。 2. **类选择器 (.class)** 类选择器以点号 `.` 开头,后面紧跟类名。它可以选择所有具有该类名的 HTML 元素。例如 `.my-class { color: blue; }` 将使所有带有 `class="my-class"` 属性的元素文字颜色变为蓝色[^2]。 3. **ID 选择器 (#id)** ID 选择器以井号 `#` 开头,后接具体的 ID 名称。由于每个页面上的 ID 应当唯一,因此 ID 选择器通常只作用于单个元素。例如 `#unique-element { font-size: 20px; }` 只会影响拥有 `id="unique-element"` 的单一元素[^3]。 --- #### 组合选择器 组合选择器允许开发者基于多种条件联合选择目标元素。常见的组合方式如下: 1. **后代选择器** 后代选择器通过空格分隔两个或更多选择器,表示后者是前者的任意层次子级。例如 `div p { color: green; }` 表示选择位于任何 `<div>` 下的所有 `<p>` 子孙节点[^1]。 2. **子选择器 (> 符号)** 子选择器仅限于直接父子关系的选择。例如 `ul > li { list-style-type: none; }` 只会针对那些直接嵌套在 `<ul>` 内部的第一层 `<li>` 进行操作[^1]。 3. **相邻兄弟选择器 (+ 符号)** 相邻兄弟选择器用来定义紧随某个元素之后的第一个同辈元素的样式。比如 `h1 + p { margin-top: 0; }` 对紧接着 `<h1>` 出现的一个 `<p>` 设置零上边距[^1]。 4. **通用兄弟选择器 (~ 符号)** 它类似于相邻兄弟选择器,不过它可以影响后续所有符合条件的同胞元素而不仅仅是第一个。如 `img ~ span { border: solid black; }` 让每张图片后的每一个 `<span>` 都加上黑色实线框[^1]。 --- #### 伪类选择器 (:pseudo-class) 伪类选择器扩展了标准选择的能力,能够依据状态或其他特性动态调整样式的呈现形式。一些典型的例子包括但不限于以下几个方面: 1. **链接状态**: 如 `a:hover`, 当鼠标悬停在一个超链接上方时触发特殊效果; 2. **表单项验证**: 使用像 `input:valid` 或者 `textarea:focus` 来分别处理有效输入以及获得焦点的情况下的表现差异; 3. **结构化控制**: 利用诸如 `nth-child(n)` 和 `last-of-type` 实现复杂布局需求——前者可精确指定某序位项目,后者则锁定最后一种类型实例等等[^1]。 --- #### 伪元素选择器 (::pseudo-element) 不同于单纯改变外观的行为模式设定,伪元素实际上是在文档流里创建额外的内容片段或者装饰部分而不实际增加DOM树成员数量。典型的应用场景有: 1. 添加引号(`::before`)或版权符号(`::after`); 2. 自定义滚动条样式; 3. 抽取首字母/行做特别强调显示等[^1]. 以下是几个简单的代码演示如何运用这些概念构建视觉吸引力强的设计方案: ```css /* 示例一:利用hover伪类增强交互体验 */ button { background-color: white; } button:hover { background-color: lightblue; } /* 示例二:借助first-letter伪元素突出段落开端 */ article p:first-of-type::first-letter { float: left; font-size: 3em; line-height: 1; padding-right: .2em; color: darkred; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值