Q: 别人网站上看到的动态效果变化很多,还是引写好的套件(库)进专案吧?
A: 只引进一个套件(库)就可以满足你的需求吗?还是要引进很多个?
之前有提到伪类指的是元素的状态;这里的伪元素是css在元素中新增的内容::before
及::after
,它们可以当作元素对其下样式,但不是真正的元素!特别要注意的是伪元素在使用时一定要有属性content
,如果没有content
属性的话,那麽下再多样式都是看不到的!
/* 以下每个范例都将使用相同的基础html及css,如下:*/
<style>
.btn {
position: relative;
width: 150px;
line-height: 60px;
font-size: 20px;
color: RoyalBlue;
text-align: center;
background-color: Lavender;
cursor: pointer;
transition: .1s;
}
</style>
<div class="btn">I'm a button</div>
在这里使用::before
并定位在.btn
的最下方,在原本的状态时让它的宽度为0,:hover
时让它的宽度变为100%,而由於元素的transition
属性不会继承给伪元素使用,所以对::before
也要下transition
才会有渐变的效果。
<style>
.btn_underline::before {
content: '';
position: absolute;
bottom: 0;
right: 0;
height: 3px;
width: 0;
background-color: RoyalBlue;
transition: .3s;
}
.btn_underline:hover::before {
width: 100%;
left: 0;
}
</style>
在这里使用::before
并依照父元素的上下左右定位,并在:hover
时让它的定位为负的,这时候元素会向外延伸,以达到外框向外的效果。
<style>
.btn_border::before {
content: '';
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
border: 3px solid Lavender;
transition: .2s;
}
.btn_border:hover::before {
top: -5px;
bottom: -5px;
left: -5px;
right: -5px;
}
</style>
<style>
.btn_background {
transform: perspective(1px) translateZ(0)
}
.btn_background::before {
content: '';
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-color: RoyalBlue;
transform: scale(0);
transition: .3s;
z-index: -1;
}
.btn_background:hover {
color: Lavender;
}
.btn_background:hover::before {
transform: scale(1);
}
</style>
谜音:不要猪队友!你也可以开发出超炫招式!
如果有写错的地方,欢迎点评! 会及时改进~
如果有更好的写法,欢迎指教! 希望各位不吝赐教~
如果想看更多效果,欢迎敲碗! 提供示意图小编写写看~
如果内容疑似侵权,拜托告知! 内容皆为小编理解後原创~
如果对你有点帮助,拿去用吧!
>>: [Golang] Go Installation and Basic Toolchain Introduction
走过了前端的一些坑之後接着来处理後端的功能,相较於前端开发完後在浏览器可以看到即时的结果(例如场景有...
上一篇我们的基因体时代-AI, Data和生物资讯 Day26-取用基因序列资讯把整个Biocond...
昨天介绍了Node.js,今天我们就要来实际安装Node.js啦 首先当然是到官网去下载Node.j...
Q_Q .. styled.div 产生一个 div,写 css style,放进变数里变成 co...
思路 想说list最长的element,就会是center 程序码 class Solution {...