admin管理员组文章数量:1336631
I have a Next.js app with five buttons that have the same SCSS class and height. However, the height of the ::after element in one button is different and I don't know why.
Scss class:
.underline-button {
color: $color;
cursor: pointer;
user-select: none;
&:after {
content: "";
display: block;
width: 50%;
height: 1px;
margin-left: auto;
margin-right: auto;
background: $color;
transition: width 0.3s;
}
&:hover:after {
width: 100%;
}
&:active:after {
width: 0;
}
}
Jsx code:
export default function Home() {
return (
<div>
<div className="underline-button">Button</div>
<div className="underline-button">Button</div>
<div className="underline-button">Button</div>
<div className="underline-button">Button</div>
<div className="underline-button">Button</div>
<div className="underline-button">Button</div>
</div>
);
Render output (.png)
I have a Next.js app with five buttons that have the same SCSS class and height. However, the height of the ::after element in one button is different and I don't know why.
Scss class:
.underline-button {
color: $color;
cursor: pointer;
user-select: none;
&:after {
content: "";
display: block;
width: 50%;
height: 1px;
margin-left: auto;
margin-right: auto;
background: $color;
transition: width 0.3s;
}
&:hover:after {
width: 100%;
}
&:active:after {
width: 0;
}
}
Jsx code:
export default function Home() {
return (
<div>
<div className="underline-button">Button</div>
<div className="underline-button">Button</div>
<div className="underline-button">Button</div>
<div className="underline-button">Button</div>
<div className="underline-button">Button</div>
<div className="underline-button">Button</div>
</div>
);
Render output (https://i.sstatic/9nDgBtcK.png)
Share Improve this question asked Nov 19, 2024 at 16:28 benben 12 bronze badges 2 |1 Answer
Reset to default -2It seems that you have written your code in wrong hierarchy.
$color: #333;
.underline-button {
color: $color;
cursor: pointer;
user-select: none;
text-align: center;
padding: 15px 0;
font-size: 24px;
&:after {
content: "";
display: block;
width: 50%;
height: 1px;
margin-left: auto;
margin-right: auto;
background: $color;
transition: width 0.3s;
}
&:hover {
&:after {
width: 100%;
}
}
&:active {
:after {
width: 0;
}
}
}
<div>
<div class="underline-button">Button</div>
<div class="underline-button">Button</div>
<div class="underline-button">Button</div>
<div class="underline-button">Button</div>
<div class="underline-button">Button</div>
<div class="underline-button">Button</div>
</div>
As your code is in .SCSS please check this.
本文标签: nextjscss after element height not worksStack Overflow
版权声明:本文标题:next.js - css ::after element height not works - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742413496a2470255.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
<>
icon. See How to create a Minimal, Reproducible Example – Paulie_D Commented Nov 19, 2024 at 16:33