I have a button that should direct me to a certain page, and when I click it, it works. However, it only works when I click the actual text inside the button, not anywhere on the button itself.
I was able to find some CSS online for making a button, and I just edited it a bit, changed the color, radius, margins, and some other attributes. Here is the current CSS:
.btn {
display: inline-block;
cursor: pointer;
border-radius: 10px;
overflow: hidden;
background-color: black;
font-size: 1.19rem;
text-align: center;
padding: 12px 24px;
margin-left: 45vw;
margin-right: 45vw;
border: 3px solid black;
outline: 3px solid black;
}
<div class="btn">
<a href="<insert-url-here>">Text Here</a>
</div>
Before I changed the CSS a bit, I could click anywhere on the button to go to the URL. However, after just changing the color and margins, which I don’t think would cause this problem, I have to click on the text to go the URL, or else the button does nothing.
2
Answers
css:
html:
This will be much easier if you wrap a
button
component in a link (though adiv
would also work). That makes everything inside thea
element go to that link when clicked.This will also allow you to simplify your CSS a good bit.
Depending on how you’re using it, you should also look into centering your element with
margin: auto
.Lastly, the default button text color is black so you’ll also want to either change the text color or change your black background, otherwise it will just look like a black box.