六种设计难题的CSS实用技巧 css 难
suiw9 2024-11-14 19:13 17 浏览 0 评论
一、黑白图像
当你需要让一张彩色的图片显示为黑白照片的时候,你可以用下面的一段代码。
img.desaturate{
filter: grayscale(100%);
-webkit-filter: grayscale(100%);
-moz-filter: grayscale(100%);
-ms-filter: grayscale(100%);
-o-filter: grayscale(100%);
}
二、使用 :not() 在菜单上应用/取消应用边框
先给每一个菜单项添加边框
.nav li{
border-right: 1px solid #666;
}
然后再除去最后一个元素
.nav li:last-child{
border-right: none;
}
也可以直接使用 :not() 伪类来应用元素
.nav li:not(:last-child){
border-right: 1px solid #666
}
如果你的元素有兄弟元素的话,也可以使用通用的兄弟选择符( ~ )
.nav li:first-child ~ li{
border-left: 1px solid #666
}
三、页面顶部阴影
给网页加上漂亮的顶部阴影效果
body:before{
content: '';
position: fixed;
top: -10px;
left: 0;
width: 100%;
height: 10px;
-webkit-box-shadow: 0px 0px 10px rgba(0,0,0,.8);
-moz-box-shadow: 0px 0px 10px rgba(0,0,0,.8);
box-shadow: 0px 0px 10px rgba(0,0,0,.8);
z-index: 100;
}
四、给 body 添加行高
不需要给别给 p,h之类的添加行高,直接:
body{
line-height: 1;
}
五、所有一切都垂直居中
html,body{
height: 100%;
margin: 0;
}
body{
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
display: -webkit-flex;
display: flex;
}
IE11中需要注意 flexbox
六、逗号分隔列表
让HTML列表项看上去像被一个真正的,分隔的列表
ul > li:not(:last-child)::after{
content: ",";
}
七、使用负的 nth-child 选择项目
在 css 中使用负的 nth-child 选择项目1到项目n
li{
display: none;
}
li:nth-child(-n+3){
display: block;
}
八、对图标使用 SVG
.logo{
background: url("logo.svg");
}
九、优化显示文本
有时候,字体并不能在所有设备上都达到最佳的显示,所以可以让设备浏览器来帮助你
html{
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
text-rendering: optimizelegibility;
}
十、对纯 css 滑块使用 max-height
使用 max-height 和溢出隐藏来实现只有 css 的滑块
.slider ul{
max-height: 0;
overflow: hidden;
}
.slider:hover ul{
max-height: 1000px;
transition: .3s ease;
}
十一、继承 box-sizing
让 box-sizing 继承 html
html{
box-sizing: border-box;
}
*,*:before, *:after{
box-sizing: inherit;
}
十二、表格单元格等宽
.table{
table-layout: fixed;
}
十三、 用 Flexbox 摆脱外边距的各种 hack
当你需要用到列分隔符时,通过flexbox的 space-between 属性,你就可以摆脱 nth- first- last-chlid 的 hack 了
.list{
display: flex;
justify-content: space-between;
}
.list .person{
flex-basis: 23%;
}
十四、使用属性选择器用于空链接
当 a 元素没有文本值,但是 href 属性有链接的时候显示链接
a[href^="http"]:empty::before{
content: attr(href);
}
十五、检测鼠标双击
HTML: <div class="test">
<span>
<input type="text" value="" readonly="true"/>
<a href="http://renpingjun.com">Double click me</a>
</span>
</div>
CSS:.test span{
position: relative;
}
.test span a{
position: relative;
z-index: 2;
}
.test span a:hover,.test span a:active{
z-index: 4;
}
.test span input{
background-color: transparent;
border: 0;
cursor: pointer;
position: absolute;
top: -1px;
left: 0;
width: 101%;
height: 301%;
z-index: 3;
}
.test span input:focus{
background-color: transparent;
border: 0;
z-index: 1;
}
十六、 CSS 写出三角形
div.arrow-up{
width: 0px;
height: 0px;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-bottom: 5px solid #ccc;
font-size: 0px;
line-height: 0px;
}
div.arrow-down{
width: 0px;
height: 0px;
border-bottom: 5px solid transparent;
border-top: 5px solid transparent;
border-right: 5px solid #ccc;
font-size: 0px;
line-height: 0px;
}
div.arrow-left{
width: 0px;
height: 0px;
border-bottom: 5px solid transparent;
border-top: 5px solid transparent;
border-left: 5px solid #ccc;
font-size: 0px;
line-height: 0px;
}
div.arrow-right{
width: 0px;
height: 0px;
border-bottom: 5px solid transparent;
border-top: 5px solid transparent;
border-left: 5px solid #ccc;
font-size: 0px;
line-height: 0px;
}
十七、 CSS calc() 的使用
calc() 用法类似于函数,能够给元素设置动态的值
.simpleBlock{
width: calc(100% - 100px);
}
.complexBlock{
width: calc(100% - 50% / 3);
padding: 5px calc(3% - 2px);
margin-left: calc(10% + 10px);
}
十八、文本渐变
h2[data-text]{
position: relative;
}
h2[data-text]::after{
content: attr(data-text);
z-index: 10;
color: #e3e3e3;
position: absolute;
top: 0;
left: 0;
-webkit-mask-image: -webkit-gradient(linear, left top,left bottom,from(rgba(0,0,0,0)),color-stop(50%,rgba(0,0,0,1)),to(rgba(0,0,0,0)));
}
十九、禁用鼠标事件
.disabled{
pointer-events: none;
}
二十、模糊文本
.blur{
color: transparent;
text-shadow: 0 0 5px rgba(0,0,0,.5);
}
原文链接:https://juejin.im/post/6882983779376300045
原文作者:zhangwinwin
相关推荐
- 俄罗斯的 HTTPS 也要被废了?(俄罗斯网站关闭)
-
发布该推文的ScottHelme是一名黑客,SecurityHeaders和ReportUri的创始人、Pluralsight作者、BBC常驻黑客。他表示,CAs现在似乎正在停止为俄罗斯域名颁发...
- 如何强制所有流量使用 HTTPS一网上用户
-
如何强制所有流量使用HTTPS一网上用户使用.htaccess强制流量到https的最常见方法可能是使用.htaccess重定向请求。.htaccess是一个简单的文本文件,简称为“.h...
- https和http的区别(https和http有何区别)
-
“HTTPS和HTTP都是数据传输的应用层协议,区别在于HTTPS比HTTP安全”。区别在哪里,我们接着往下看:...
- 快码住!带你十分钟搞懂HTTP与HTTPS协议及请求的区别
-
什么是协议?网络协议是计算机之间为了实现网络通信从而达成的一种“约定”或“规则”,正是因为这个“规则”的存在,不同厂商的生产设备、及不同操作系统组成的计算机之间,才可以实现通信。简单来说,计算机与网络...
- 简述HTTPS工作原理(简述https原理,以及与http的区别)
-
https是在http协议的基础上加了一层SSL(由网景公司开发),加密由ssl实现,它的目的是为用户提供对网站服务器的身份认证(需要CA),以至于保护交换数据的隐私和完整性,原理如图示。1、客户端发...
- 21、HTTPS 有几次握手和挥手?HTTPS 的原理什么是(高薪 常问)
-
HTTPS是3次握手和4次挥手,和HTTP是一样的。HTTPS的原理...
- 一次安全可靠的通信——HTTPS原理
-
为什么HTTPS协议就比HTTP安全呢?一次安全可靠的通信应该包含什么东西呢,这篇文章我会尝试讲清楚这些细节。Alice与Bob的通信...
- 为什么有的网站没有使用https(为什么有的网站点不开)
-
有的网站没有使用HTTPS的原因可能涉及多个方面,以下是.com、.top域名的一些见解:服务器性能限制:HTTPS使用公钥加密和私钥解密技术,这要求服务器具备足够的计算能力来处理加解密操作。如果服务...
- HTTPS是什么?加密原理和证书。SSL/TLS握手过程
-
秘钥的产生过程非对称加密...
- 图解HTTPS「转」(图解http 完整版 彩色版 pdf)
-
我们都知道HTTPS能够加密信息,以免敏感信息被第三方获取。所以很多银行网站或电子邮箱等等安全级别较高的服务都会采用HTTPS协议。...
- HTTP 和 HTTPS 有何不同?一文带你全面了解
-
随着互联网时代的高速发展,Web服务器和客户端之间的安全通信需求也越来越高。HTTP和HTTPS是两种广泛使用的Web通信协议。本文将介绍HTTP和HTTPS的区别,并探讨为什么HTTPS已成为We...
- HTTP与HTTPS的区别,详细介绍(http与https有什么区别)
-
HTTP与HTTPS介绍超文本传输协议HTTP协议被用于在Web浏览器和网站服务器之间传递信息,HTTP协议以明文方式发送内容,不提供任何方式的数据加密,如果攻击者截取了Web浏览器和网站服务器之间的...
- 一文让你轻松掌握 HTTPS(https详解)
-
一文让你轻松掌握HTTPS原文作者:UC国际研发泽原写在最前:欢迎你来到“UC国际技术”公众号,我们将为大家提供与客户端、服务端、算法、测试、数据、前端等相关的高质量技术文章,不限于原创与翻译。...
- 如何在Spring Boot应用程序上启用HTTPS?
-
HTTPS是HTTP的安全版本,旨在提供传输层安全性(TLS)[安全套接字层(SSL)的后继产品],这是地址栏中的挂锁图标,用于在Web服务器和浏览器之间建立加密连接。HTTPS加密每个数据包以安全方...
- 一文彻底搞明白Http以及Https(http0)
-
早期以信息发布为主的Web1.0时代,HTTP已可以满足绝大部分需要。证书费用、服务器的计算资源都比较昂贵,作为HTTP安全扩展的HTTPS,通常只应用在登录、交易等少数环境中。但随着越来越多的重要...
你 发表评论:
欢迎- 一周热门
-
-
Linux:Ubuntu22.04上安装python3.11,简单易上手
-
宝马阿布达比分公司推出独特M4升级套件,整套升级约在20万
-
MATLAB中图片保存的五种方法(一)(matlab中保存图片命令)
-
别再傻傻搞不清楚Workstation Player和Workstation Pro的区别了
-
Linux上使用tinyproxy快速搭建HTTP/HTTPS代理器
-
如何提取、修改、强刷A卡bios a卡刷bios工具
-
Element Plus 的 Dialog 组件实现点击遮罩层不关闭对话框
-
日本组合“岚”将于2020年12月31日停止团体活动
-
SpringCloud OpenFeign 使用 okhttp 发送 HTTP 请求与 HTTP/2 探索
-
tinymce 号称富文本编辑器世界第一,大家同意么?
-
- 最近发表
- 标签列表
-
- dialog.js (57)
- importnew (44)
- windows93网页版 (44)
- yii2框架的优缺点 (45)
- tinyeditor (45)
- qt5.5 (60)
- windowsserver2016镜像下载 (52)
- okhttputils (51)
- android-gif-drawable (53)
- 时间轴插件 (56)
- docker systemd (65)
- slider.js (47)
- android webview缓存 (46)
- pagination.js (59)
- loadjs (62)
- openssl1.0.2 (48)
- velocity模板引擎 (48)
- pcre library (47)
- zabbix微信报警脚本 (63)
- jnetpcap (49)
- pdfrenderer (43)
- fastutil (48)
- uinavigationcontroller (53)
- bitbucket.org (44)
- python websocket-client (47)