我正在嘗試復制此頁面上看到的按鈕影片:
https://www.beedie.ca/
邊框從左上角到右下角改變顏色的地方。
我可以讓左側和頂部正確設定影片,但隨后線條不再向下延伸并穿過底部,而是為底部和右側展開了一個框。誰能看到我做錯了什么。
我在下面的代碼中附上了我的嘗試。HTML 和 CSS。
.hover-effect-button-container-yellow {
max-width:150px;
position:relative;
}
.hover-effect-button-yellow {
text-align:center;
border:1px solid white;
font-family: "Muli", sans-serif;
font-size: 15px;
font-weight: 500;
line-height: 25.5px;
padding-bottom: 10px;
padding-left: 25px;
padding-right: 24px;
padding-top: 10px;
}
.hover-effect-button-yellow:before {
box-sizing: inherit;
content: "";
position: absolute;
width: 0;
height: 0;
}
.hover-effect-button-yellow:after {
box-sizing: inherit;
content: "";
position: absolute;
width: 0;
height: 0;
}
.hover-effect-button-yellow:before {
border-top: 1px solid white;
border-left: 1px solid white;
top: 0;
left: 0;
}
.hover-effect-button-yellow:after {
border-right:1px solid white;
border-bottom:1px solid white;
top: 0;
left:0;
}
.hover-effect-button-yellow:hover:before {
width:100%;
height:100%;
border-top-color: red;
border-left-color: red;
transition: height 1s ease-out, width 1s ease-out;
}
.hover-effect-button-yellow:hover:after {
width:100%;
height:100%;
border-bottom-color: red;
border-right-color: red;
transition: height 1s ease-out 1s, width 1s ease-out 1s;
}
<div class="hover-effect-button-container-yellow">
<div class="hover-effect-button-yellow">
<a href="#">CLICK HERE</a>
</div>
</div>
uj5u.com熱心網友回復:
你需要給并給<a>它 css。
您需要在按鈕的::before和::after中添加整個邊框:
.button::before, .button::after {
border: 1px solid transparent;
}
并更改按鈕的 ::before 和 ::after 選擇器懸停時的右上角左下邊框;也改變過渡,如圖所示:
.button:hover::before {
border-top-color: #0076b6;
border-right-color: #0076b6;
transition: width 0.25s ease-out, height 0.25s ease-out 0.25s;
}
.button:hover::after {
border-bottom-color: #0076b6;
border-left-color: #0076b6;
transition: height 0.25s ease-out, width 0.25s ease-out 0.25s;
}
請在下面找到更新的 css 和 html:
.button {
background: none;
border: 0;
box-sizing: border-box;
padding: 0.9rem 2rem;
box-shadow: inset 0 0 0 1px #fff;
color: #000000;
text-transform: uppercase;
font-family: "ff-meta-web-pro","Helvetica Neue",Helvetica,Roboto,Arial,sans-serif;
font-weight: 400;
letter-spacing: 0.025em;
position: relative;
vertical-align: middle;
transition: color 0.25s;
display: inline-block;
text-decoration: none;
}
.button::before {
top: 0;
left: 0;
}
.button::before, .button::after {
box-sizing: inherit;
content: "";
position: absolute;
width: 0;
height: 0;
border: 1px solid transparent;
}
.button::after {
top: 0;
left: 0;
bottom: 0;
right: 0;
}
.button:hover {
outline-width: 0;
text-decoration: none;
}
.button:hover::before {
border-top-color: #0076b6;
border-right-color: #0076b6;
transition: width 0.25s ease-out, height 0.25s ease-out 0.25s;
}
.hover-effect-button-container-yellow {
padding: 10px;
background: pink;
}
.button:hover::before, .button:hover::after {
width: 100%;
height: 100%;
}
.button:hover::after {
border-bottom-color: #0076b6;
border-left-color: #0076b6;
transition: height 0.25s ease-out, width 0.25s ease-out 0.25s;
}
<div class="hover-effect-button-container-yellow">
<div class="hover-effect-button-yellow">
<a class="button" href="https://beedie.ca/industrial/">Learn More</a>
</div>
</div>
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/487472.html
