我正在嘗試制作一個簡單的導航選單,其中包含帶有影片下劃線的按??鈕。我使用 reactjs lib
如果按鈕元素處于活動狀態,我無法弄清楚如何立即顯示下劃線。
.btn {
position: relative;
text-transform: uppercase;
color: whitesmoke;
font-size: 1.4rem;
cursor: pointer;
}
.btn:hover {
color: whitesmoke;
text-decoration: none;
}
.btn:before {
content: "";
position: absolute;
width: 100%;
height: 0.105rem;
left: 0;
bottom: 0;
visibility: hidden;
background-color: whitesmoke;
transform: scaleX(0);
transition: all 0.3s ease-in-out 0s;
}
.btn:hover:before {
transform: scaleX(1);
visibility: visible;
}
button.active .btn:before {
visibility: visible;
transform: scaleX(1);
}
<a href="/">
<button id="home" className="btn active">
Home
</button>
</a>
</div>
<div className="col-4 col-sm-2">
<a href="/blog">
<button id="blog" className="btn">
Blog
</button>
</a>
uj5u.com熱心網友回復:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./style.css">
<title>Document</title>
</head>
<body>
<a href="/">
<button id="home" class="btn active">
Home
</button>
</a>
</div>
<div className="col-4 col-sm-2">
<a href="/blog">
<button id="blog" class="btn">
Blog
</button>
</a>
</body>
</html>
.btn {
position: relative;
text-transform: uppercase;
color: whitesmoke;
font-size: 1.4rem;
cursor: pointer;
border: none;
outline: none;
background-color: #332e2e77;
display: inline-block;
margin-bottom: 2rem;
}
a {
display: inline-block;
}
.btn:hover {
color: whitesmoke;
text-decoration: none;
}
.btn::before {
content: '';
position: absolute;
width: 0%;
height: 0.105rem;
left: 0;
bottom: 0;
visibility: hidden;
background-color: rebeccapurple;
transition: all 0.3s ease-in-out;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-ms-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
}
.btn:hover::before {
width: 100%;
visibility: visible;
}
.btn.active {
position: relative;
}
.btn.active::after {
content: '';
position: absolute;
width: 100%;
height: 0.105rem;
left: 0;
bottom: 0;
background-color: rebeccapurple;
transition: all 0.3s ease-in-out;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-ms-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
}
現在嘗試懸停。className -> 如評論中所述的 class 我使用了 width 0% -> width 100%; 并正確下劃線影片。
.btn:懸停::之前
-> 你這樣選擇偽選擇器
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/392785.html
下一篇:決議正則運算式字串的正則運算式
