gpt4 book ai didi

CSS 按钮 - 仅在文本上链接,而不在按钮上链接

转载 作者:太空宇宙 更新时间:2023-11-03 23:07:03 24 4
gpt4 key购买 nike

我正在制作一个 CSS 按钮作为小部件。 href 链接仅在悬停/单击“调用我们”文本时适用,如何让它显示在整个按钮上?

HTML:

<div class="mybutton"><a href="http://example.com">Call Us</a></div>

CSS:

.mybutton {
width: 200px;
height: 80px;
background-color: #214b83;
color: #fff;
text-align: center;
}

最佳答案

a 元素默认有 display:inline 所以你可以给 display:block; 然后给 height:100% ;width:100%;。要使文本居中,您需要提供 line-height:80px;(height of parent)。

.mybutton {
width: 200px;
height: 80px;
background-color: #214b83;
color: #fff;
text-align: center;
}
.mybutton a {
display: block;
width: 100%;
height: 100%;
background: red;
line-height: 80px;
}
<div class="mybutton"><a href="http://example.com">Call Us</a>
</div>

关于CSS 按钮 - 仅在文本上链接,而不在按钮上链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34335786/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com