我試圖在用戶單擊時創建按鈕,內部容器改變寬度但外部容器作為一個整體(黑色背景)不會改變寬度。我目前擁有的是關閉的,但是當用戶單擊陰影時會發生變化。
片段:
html:
<button class="btn btn__primary" type="button">
Continue
<i class="fa-solid fa-sparkles m-l-8px"></i>
</button>
scss:
.btn {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
padding: 12px;
font-family: $aeonik_bold;
font-size: 15px;
line-height: 100%;
letter-spacing: 0.55px;
border: 1.5px solid $button_border_color;
box-sizing: border-box;
border-radius: 4px;
box-shadow: -1px 1px 0px 1.5px $button_border_color;
text-decoration: none;
transition: all 0.3s;
animation-timing-function: ease-in-out;
animation-duration: 150ms;
cursor: pointer;
width: 100%;
&:active {
box-shadow: none;
background-color: #5a44ff;
animation-timing-function: ease-in-out;
animation-duration: 150ms;
}
&:focus {
box-shadow: none;
background-color: #5a44ff;
animation-timing-function: ease-in-out;
animation-duration: 150ms;
}
&:disabled {
background: #d9dbe9;
border: 1.5px solid #d9dbe9;
box-sizing: border-box;
border-radius: 4px;
cursor: default;
}
&__primary {
background-color: $purple_resting;
color: white;
animation-timing-function: ease-in-out;
animation-duration: 150ms;
&:not(:disabled) {
&:hover {
background-color: #6955ff;
border: 1.5px solid #170f49;
box-sizing: border-box;
border-radius: 4px;
box-shadow: -0.5px 0.5px 0px 1px $button_border_color;
animation-timing-function: ease-in-out;
animation-duration: 150ms;
}
}
}
uj5u.com熱心網友回復:
我不知道你想用影片做什么,所以我想出了一種不同的方法,使用插入框陰影和在帶有過渡的子跨度上填充。
如果要更改框陰影的大小,則只需將框陰影中使用的像素添加到按鈕的左側和底部填充,然后在活動時執行相反的操作,例如
如果盒子陰影是inset 4px -4px 0 #000000并且按鈕的填充是16px.
然后按鈕的填充將是padding: 16px 16px 20px 20px;并且在活動時它將是padding: 20px 20px 16px 16px;
.btn {
-moz-box-shadow: inset 2px -2px 0 #000000;
-webkit-box-shadow: inset 2px -2px 0 #000000;
box-shadow: inset 2px -2px 0 #000000;
border: 1px solid #000000;
transition: all 0.25s ease-in-out;
border-radius: 5px;
}
.btn > span {
padding: 8px 8px 10px 10px;
transition: all 0.25s ease-in-out;
display: block;
}
.btn:active {
-moz-box-shadow: inset 0 0 0 #000000;
-webkit-box-shadow: inset 0 0 0 #000000;
box-shadow: inset 0 0 0 #000000;
}
.btn:active > span {
padding: 10px 10px 8px 8px;
}
<div class="container">
<button class="btn btn__primary" type="button">
<span>Continue <i class="fa-solid fa-sparkles m-l-8px"></i></span>
</button>
</div>
uj5u.com熱心網友回復:
您將在左側和底部添加邊框,然后在按鈕處于活動狀態時縮小它們
.container {
width: 150px;
margin: 0 auto;
}
.btn {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
padding: 12px;
font-size: 15px;
line-height: 100%;
letter-spacing: 0.55px;
border: 1.5px solid #092c4c;
border-left: 3px solid #092c4c;
border-bottom: 3px solid #092c4c;
box-sizing: border-box;
border-radius: 6px;
text-decoration: none;
transition: all .1s;
animation-timing-function: ease-in-out;
animation-duration: 150ms;
cursor: pointer;
width: 100%;
&:active {
border-left: 0 solid #092c4c;
border-bottom: 0 solid #092c4c;
background-color: #5a44ff;
animation-timing-function: ease-in-out;
animation-duration: 150ms;
}
&:focus {
background-color: #5a44ff;
animation-timing-function: ease-in-out;
animation-duration: 150ms;
}
&:disabled {
background: #d9dbe9;
border: 1.5px solid #d9dbe9;
box-sizing: border-box;
border-radius: 4px;
cursor: default;
}
&__primary {
background-color: #7a6af6;
color: white;
animation-timing-function: ease-in-out;
animation-duration: 150ms;
&:not(:disabled) {
&:hover {
background-color: #6955ff;
box-sizing: border-box;
animation-timing-function: ease-in-out;
animation-duration: 150ms;
}
}
}
}
希望對你有幫助 <3
uj5u.com熱心網友回復:
所以根據我的理解,你正在嘗試一個神經質的按鈕。這是我的方法。
*{
padding: 0;
box-sizing: border-box;
font: inherit;
}
.btn{
--off-x: 3px;
--off-y: 4px;
background: orchid;
padding: 0.5em 1em;
color: white;
font-family: sans-serif;
font-weight: bold;
letter-spacing: 1px;
border-radius: 8px;
box-shadow: calc(var(--off-x, 0)*-1) var(--off-y, 0) black;
transform: translate(var(--off-x, 0), calc(var(--off-y, 0)*-1));
transition: all 100ms ease-in-out;
}
.btn:active{
box-shadow: 0 0;
transform: translate(0);
}
<button class="btn">Continue</button>
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/492760.html
上一篇:當我單擊、更改顏色或不透明度時反應原生TouchableOpacity
下一篇:帶有徽標和按鈕的導航欄樣式
