《css揭秘》- 47个不为人知的高阶操作🔥(下篇20-47, 7K长文多图预警)(二)

简介: 《css揭秘》- 47个不为人知的高阶操作🔥(下篇20-47, 7K长文多图预警)(二)

26-自定义下划线


背景知识:css 渐变、background-size、text-shadow、'条纹背景'

介绍:默认的下划线虽然很实用,但是太普通,可能无法满满广大设计师们的审美需求,这里介绍一种自定义下划线的最佳方案。


防止下划线穿过文字底部、虚线下划线


1687781278184.png


<p>“The only way to <a>get rid of a temp­ta­tion</a> is to <a>yield</a> to it.”</p>
<p>“The only way to <a>get rid of a temp­ta­tion</a> is to <a>yield</a> to it.”</p>
/**
 * Custom underlines
 */
body {
    font: 250%/1.6 Baskerville, Palatino, serif;
}
a {
    background: linear-gradient(gray, gray) no-repeat;
    background-size: 100% 1px;
    background-position: 0 1.02em;
    text-shadow: .05em 0 white, -.05em 0 white;
}
p:nth-child(2) a {
    background: linear-gradient(90deg, gray 66%, transparent 0) repeat-x;
    background-size: .2em 2px;
    background-position: 0 1em;
}


波浪下划线


1687781289058.png


<p>“The only way to <a>get rrid of a temp­ta­toin</a> is to <a>yeild</a> to it.”</p>
/**
 * Wavy underlines
 */
body {
    font: 250%/1.6 Baskerville, Palatino, serif;
}
a {
    background: linear-gradient(-45deg, transparent 40%, red 0, red 60%, transparent 0) 0 1em,
    linear-gradient(45deg, transparent 40%, red 0, red 60%, transparent 0) .1em 1em;
    background-repeat: repeat-x;
    background-size: .2em .1em;
    text-shadow: .05em 0 white, -.05em 0 white;
}


27-现实中的文字效果


背景知识:text-shadow

介绍:介绍几种艺术文字的实现方案


凸版印刷效果


1687781301271.png


/**
 * Letterpress
 */
body {
    font: 250%/1.6 Baskerville, Palatino, serif;
}
p {
    padding: .8em 1em;
    background: hsl(210, 13%, 60%);
    color: hsl(210, 13%, 30%);
    text-shadow: 0 1px 1px hsla(0,0%,100%,.8);
}
p + p {
    background: hsl(210, 13%, 30%); 
    color: hsl(210, 13%, 60%);
    text-shadow: 0 -1px 1px black;
}


空心字效果


1687781314304.png


/**
 * Stroked text
 */
h1 {
    margin: 0;
    color: white;
}
h1:first-child {
    text-shadow: 1px 1px black, -1px -1px black, 1px -1px black, -1px 1px black;
}
h1 text { fill: currentColor }
h1 use {
    stroke: black; 
    stroke-width: 6;
    stroke-linejoin: round;
}
body {
    background: deeppink;
    font: bold 200%/1 Rockwell, serif;
}


文字外发光效果


1687781327180.png


<a href="http://csssecrets.io">Glow</a>
/**
 * Glowing text
 */
body {
    background: #203;
    font: bold 500%/1 Rockwell, serif;
}
a {
    color: #ffc;
    text-decoration: none;
    transition: 1s;
}
a:hover { text-shadow: 0 0 .1em, 0 0 .3em; }


文字凸起效果


1687781339999.png


/**
 * Extruded text
 */
body {
    background: #58a;
    color: white;
    text-shadow: 0 1px hsl(0,0%,85%),
                 0 2px hsl(0,0%,80%),
                 0 3px hsl(0,0%,75%),
                 0 4px hsl(0,0%,70%),
                 0 5px hsl(0,0%,65%),
                 0 5px 10px black;
    font: bold 500%/1 Rockwell, serif;
}


28-环形文字


背景知识:基本的 SVG

介绍:通过使用 SVG 路径来实现环形排列的文字效果


1687781353183.png


/**
 * Text on a circle
 */
body {
    font: bold 120% Helvetica, sans-serif;
}
.circular {
    width: 30em;
    height: 30em;
    margin: 4em auto 0;
}
.circular svg {
    display: block;
    overflow: visible;
    transition: 10s linear transform;
}
.circular svg:hover { transform: rotate(-2turn); }
.circular text { fill: currentColor }
.circular path { fill: none; }


29-选中合适的鼠标光标


主要就是介绍了 css3 中提供的一些新的鼠标光标效果,其中重点推荐了 cursor: not-allowed 和 隐藏光标的方法 cursor:none;


30-扩大可点击区域


介绍:根据Fitts 法则,我们推论出,目标越大,越容易到达,所以在目标大小固定的情况下,将可点击范围扩大,也可以提高用户体验,这里介绍两种方法。


透明边框 border 来实现


1687781370773.png


<button>+</button>
/**
 * Extending the hit area — with generated content
 */
button {
    position: relative;
    padding: .3em .5em;
    background: #58a;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,.3);
    box-shadow:  0 .1em .2em -.05em rgba(0,0,0,.5);
    color: white;
    font: bold 150%/1 sans-serif;
    cursor: pointer;
}
button:before {
    content: '';
    position: absolute;
    top: -10px; right: -10px;
    bottom: -10px; left: -10px;
}


伪元素来实现


使用透明伪元素覆盖,并将半径向外延伸10px 来实现


1687781384726.png


<button>+</button>
/**
 * Extending the hit area — with generated content
 */
button {
    position: relative;
    padding: .3em .5em;
    background: #58a;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,.3);
    box-shadow:  0 .1em .2em -.05em rgba(0,0,0,.5);
    color: white;
    font: bold 150%/1 sans-serif;
    cursor: pointer;
}
button:before {
    content: '';
    position: absolute;
    top: -10px; right: -10px;
    bottom: -10px; left: -10px;
}


目录
相关文章
|
2月前
|
移动开发 前端开发 JavaScript
编程笔记 html5&css&js 005 网页上都有哪内容、形式和操作
编程笔记 html5&css&js 005 网页上都有哪内容、形式和操作
|
2月前
|
前端开发 JavaScript
如何固定html表格头部,用css样式即可实现,操作简便、代码简单
如何固定html表格头部,用css样式即可实现,操作简便、代码简单
47 0
|
10月前
|
JSON 前端开发 JavaScript
jQuery操作CSS
jQuery操作CSS
70 0
|
12月前
|
前端开发
CSS 高阶小技巧 - 角向渐变的妙用!
CSS 高阶小技巧 - 角向渐变的妙用!
|
7月前
|
JavaScript 前端开发
【jQuery学习】—jQuery操作CSS和表格
【jQuery学习】—jQuery操作CSS和表格
|
12月前
|
存储 前端开发 JavaScript
JavaScript操作表格及CSS样式
JavaScript操作表格及CSS样式
149 0
|
12月前
|
前端开发
DSP开发软件css(10)使用基础(汉化、工程导入、设置目标配置文件、选择仿真器和芯片型号、添加文件|库路径、编译下载等操作)
DSP开发软件css(10)使用基础(汉化、工程导入、设置目标配置文件、选择仿真器和芯片型号、添加文件|库路径、编译下载等操作)
130 0
|
12月前
|
前端开发 JavaScript
使用JS操作CSS
一.什么是css? Cascading Style Sheets 通常称为CSS样式表或层叠样式表(级联样式表) CSS用于控制网页的外观 (HTML是用于控制网页结构的,JS是控制网页的行为) Css让界面变得更加美观
|
前端开发 流计算
《css揭秘》- 47个不为人知的高阶操作🔥(下篇20-47, 7K长文多图预警)(六)
《css揭秘》- 47个不为人知的高阶操作🔥(下篇20-47, 7K长文多图预警)(六)
114 0
|
前端开发
《css揭秘》- 47个不为人知的高阶操作🔥(下篇20-47, 7K长文多图预警)(五)
《css揭秘》- 47个不为人知的高阶操作🔥(下篇20-47, 7K长文多图预警)(五)
66 0