css-小妙招(二)

简介: css小妙招系列

平常工作中,为了能够更好的掌握CSS这一个模块,我们需要掌握更多关于它的知识,不仅仅是掌握它的全部必要的知识,掌握一些小技巧对我们的帮助也是非常大的,这样我们就可以走更少的弯路,减少一些不必要的步骤,可以更快的完成代码的产出。

1.禁用鼠标事件

CSS3 新增的 pointer-events 让你能够禁用元素的鼠标事件

.disabled { pointer-events: none; }

2.检测鼠标双击

.test3 span {
  position: relative;
}
.test3 span a {
  position: relative;
  z-index: 2;
}
.test3 span a:hover, .test3 span a:active {
  z-index: 4;
}
.test3 span input {
  background: transparent;
  border: 0;
  cursor: pointer;
  position: absolute;
  top: -1px;
  left: 0;
  width: 101%;  /* Hacky */
  height: 301%; /* Hacky */
  z-index: 3;
}
.test3 span input:focus {
  background: transparent;
  border: 0;
  z-index: 1;
}

3.表格单元格等宽

.calendar {
  table-layout: fixed;
}

4.继承 box-sizing

html {
  box-sizing: border-box;
}
*, *:before, *:after {
  box-sizing: inherit;
}

5.对纯 CSS 滑块使用 max-height

.slider ul {
  max-height: 0;
  overlow: hidden;
}
.slider:hover ul {
  max-height: 1000px;
  transition: .3s ease;
}

6.黑白图像

让彩色照片显示为黑白照片

img {
    filter: grayscale(100%);
    -webkit-filter: grayscale(100%);
    -moz-filter: grayscale(100%);
    -ms-filter: grayscale(100%);
    -o-filter: grayscale(100%);
}

7.使用负的 nth-child 选择项目

li {
  display: none;
}
/* select items 1 through 3 and display them */
li:nth-child(-n+3) {
  display: block;
}

8.对图标使用 SVG

.logo {
  background: url("logo.svg");
}

9.逗号分隔的列表

ul > li:not(:last-child)::after {
  content: ",";
}

10.使用 :not() 在菜单上应用/取消应用边框

/* add border */
.nav li {
  border-right: 1px solid #666;
}
然后再除去最后一个元素
// remove border /
.nav li:last-child {
  border-right: none;
}
目录
相关文章
|
9月前
|
存储 自然语言处理 API
省下亿万Token的秘密:三次对话,两万字代码背后的RAG魔法
本文剖析了开发者在调试中“复制粘贴海量代码→浪费Token→触发模型失忆”的恶性循环,提出RAG编码助手作为破局方案:通过AST智能切分、跨文件多跳检索与结构化Prompt,将每次输入从2.5万字压缩至数百字,Token消耗降低96%,响应提速数倍,且支持纯本地部署,兼顾效率、精准与安全。(239字)
867 6
|
9月前
|
数据采集 存储 NoSQL
数据采集效率翻倍?关键在爬虫工具的这几步配置
在数据驱动时代,爬虫效率取决于科学配置而非工具本身。本文详解四大核心技巧:合理选型(Requests/Scrapy)、优化请求参数(模拟用户、控频防封)、启用异步与分布式、精准过滤存储。兼顾速度与合规,让爬虫稳定高效获取数据。
533 16
|
前端开发
css-小妙招(一)
css小妙招系列
372 18
|
安全 自然语言处理
Modelscope 中文竞技场大模型体验
Modelscope 中文竞技场大模型体验
501 13
|
3天前
|
监控 网络协议 算法
2026年起SSL证书有效期逐年缩短:企业如何避免“续期风暴”!
SSL证书有效期将从2026年起分三阶段逐步缩短至47天,人工续期难以为继。阿里云“WoSign SSL证书+自动化服务”,支持域名监控、自动托管、云产品/服务器一键部署及智能提醒,助力企业高效应对高频续期挑战。
8088 2
|
12天前
|
域名解析 人工智能 Linux
|
20天前
|
人工智能
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
进不去 Antigravity 或 Gemini,提示所在地区不可用?三步查清 Google 账号关联地区、官方更正表单理由选法与改区注意事项。
10477 13
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
|
6天前
|
人工智能 安全 网络安全