【发布时间】:2021-11-22 05:17:40
【问题描述】:
我正在练习我的 CSS,所以在几个教程之后我开始创建一个简单的网站。我想创建这样的东西:
我怎样才能达到这种效果?我在互联网上寻找答案,我只找到了带有精美动画和下划线效果的解决方案,但我找不到与我的问题类似的解决方案。我只取得了这样的成绩:
这是我的代码
.button {
background-color: white;
border: none;
color: black;
text-align: center;
text-decoration: none;
cursor: pointer;
margin: 0;
}
.button:hover {
background-color: white;
border-bottom: #55415f 4px solid;
color: #55415f;
text-align: center;
text-decoration: none;
cursor: pointer;
margin: 0;
}
.r_menu {
display: flex;
justify-content: flex-end;
border-bottom: black 3px solid;
gap: 20px;
margin: 0;
}
<div class="r_menu">
<button class="button">Home page</button>
<button class="button">Style demo</button>
<button class="button">Full width</button>
<button class="button">Portfolio</button>
<button class="button">Gallery</button>
<button class="button">Dropdown</button>
</div>
【问题讨论】:
-
欢迎来到 SO。提供您迄今为止尝试过的代码,仅提供图像无济于事。因为到目前为止我们无法从图像中提取代码; ) .
-
这个问题是由于元素的默认
margin(用于菜单的标签)。因此,要消除此问题,请在包含border-bottom: 3px solid black的元素上使用margin: 0(即您的菜单)
标签: css menu hover styling underline