简体   繁体   English

HTML / CSS按钮链接不起作用

[英]HTML/CSS button link not working

I'm trying to put a link to another page of my website inside this button I've made using CSS. 我正试图在我使用CSS制作的这个按钮内放置一个链接到我网站的另一个页面。 However, the button already has formatted text in it and the link apparently only works when I use text inside the <a></a> tags. 但是,该按钮已经在其中设置了格式化文本,并且链接显然仅在我在<a></a>标记内使用文本时才有效。 Any ideas how I can just make the entire button a clickable link? 任何想法如何让整个按钮成为可点击的链接? Here's the offending code: 这是有问题的代码:

<nav>
<p class="button"><a href="pictures.htm"></a>Pictures of our destinations</p>
<p class="button">Prices for flights, hotels and all in one deals</p>
<p class="button">Today's deals</p>
<p class="button">Contact us!</p> 
<p class="button">Sign up for an account</p>
</nav>

As that code stands, the link does not work and there is no clickable area. 该代码代表,链接不起作用,没有可点击的区域。 However, moving the text from the <p> tags to the <a> tags makes the link work, but my CSS formatting doesn't apply to it then. 但是,将文本从<p>标记移动到<a>标记会使链接起作用,但我的CSS格式不适用于它。

You need to do like this 你需要这样做

<a href="pictures.htm" class="button">Pictures of our destinations</a>

You need to put content inside a tag that is to be clickable 您需要将内容放在可点击a标记内

And now style the button 现在按下按钮

.button{    
/*.......

Your button style properties

.........*/        
}

<a href="pictures.htm" class="button">Pictures of our destinations</a>而不是第一段

您可以直接添加class="button" <a>标签的样式并删除<p>标签。

<a class="button" href="pictures.htm">Pictures of our destinations</a>

Removing the <p> tag will solve your issue: 删除<p>标记将解决您的问题:

<a href="pictures.htm" class="button">Pictures of our destinations</a>

Use your own CSS class: 使用您自己的CSS类:

.button {
    border: none;
    background-color: #e7e7e7;
    color: black;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin: 4px 2px;
    cursor: pointer;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM