Reputation: 99
I'm trying to make a circle button (I was thinking submit button or link to another page) that has a label/text on it, and then when you hover it has different text. I've been able to find tutorials on all of these things individually, but together I can't quite get them to work.
Currently I have:
HTML
<div class='button'>
<a href='activities.php'>
<div class='text'> hello world </div>
<img src="/Images/budapest.jpg">
</a>
</div>
CSS
.button img { /*http://codeitdown.com/css-round-buttons/*/
display: block;
width: 30vmin;
height: 30vmin;
line-height: 50px;
border: 2px;
border-radius: 50%;
color: #000000;
text-align: center;
text-decoration: none;
background: #000000;
font-size: 20px;
font-weight: bold;
z-index: 1;
}
.text{
display: block;
}
.text:hover {
display: none;
z-index: 2;
}
.button input[type=submit].nav {
font-family: 'Optima', sans-serif;
height: auto;
width: auto;
background: #111111;
border-radius: 1vmin;
color: #FFFFFF;
font-size: 2vmin;
z-index: 2;
}
The button currently is the image I want - yay, and indeed redirects to the correct page. However, the text "hello world" always shows (instead of only when on hover), is above the image (not on top of it), and I can click on it or the button to redirect me. Also, how do I get the text to change when I hover?
Update
The remaining problem is that the text is not inside the button/image.
My Code
.button img { /*http://codeitdown.com/css-round-buttons/*/
display: block;
width: 30vmin;
height: 30vmin;
line-height: 50px;
border: 2px;
border-radius: 50%;
color: #000000;
text-align: center;
text-decoration: none;
background: #000000;
font-size: 20px;
font-weight: bold;
z-index: 1;
}
.button .text-after {
display: none;
}
.button:hover .text-after {
display: inline;
}
.button:hover .text-before {
display: none;
}
<div class='button'>
<a href='activities.php'>
<span class="text-before">Before</span>
<span class="text-after">After</span>
<img src="/Images/budapest.jpg">
</a>
</div>
Upvotes: 0
Views: 2359
Reputation: 167250
Don't use <div>
inside <a>
(Worst nightmare! Division inside a link? Block inside an inline?).
Secondly use two text containers like this:
<div class='button'>
<a href='activities.php'>
<span class="text-before">Before</span>
<span class="text-after">After</span>
<img src="/Images/budapest.jpg">
</a>
</div>
Use this CSS:
.button .text-after {display: none;}
.button:hover .text-after {display: inline;}
.button:hover .text-before {display: none;}
Updated Snippet
My Code
.button img { /*http://codeitdown.com/css-round-buttons/*/
display: block;
width: 30vmin;
height: 30vmin;
line-height: 50px;
border: 2px;
border-radius: 50%;
color: #000000;
text-align: center;
text-decoration: none;
background: #333333;
font-size: 20px;
font-weight: bold;
z-index: 1;
}
.button .text-after {
display: none;
}
.button:hover .text-after {
display: inline;
}
.button:hover .text-before {
display: none;
}
.button a {
text-align: center;
display: block;
width: 89.6875px; /* should be the width of image*/
line-height: 89.6875px;
position: absolute;
z-index: 9;
left: 0;
top: 0;
}
.button {
position: relative;
z-index: 9;
}
.button img {
position: absolute;
left: 0;
top: 0;
z-index: 1;
}
<div class='button'>
<a href='activities.php'>
<span class="text-before">Beforexd</span>
<span class="text-after">After</span>
<img src="/Images/budapest.jpg">
</a>
</div>
The above is what I did, but unfortunately it didn't work. I don't know why, but I can give you a different solution:
.round-img-button {
width: 100px;
height: 100px;
position: relative;
}
.round-img-button a,
.round-img-button img {
position: absolute;
width: 100px;
height: 100px;
left: 0;
top: 0;
z-index: 1;
}
.round-img-button a {
z-index: 2;
color: #fff;
text-decoration: none;
text-align: center;
line-height: 100px;
}
.round-img-button a .after {
display: none;
}
.round-img-button:hover a .after {
display: inline;
}
.round-img-button:hover a .before {
display: none;
}
<div class="round-img-button">
<a href="#">
<span class="after">Hover</span>
<span class="before">Normal</span>
</a>
<img src="http://lorempixel.com/100/100" alt="" />
</div>
Upvotes: 2
Reputation: 9
Here's an example http://jsfiddle.net/josedvq/Jyjjx/45/
can be answer for your question.
<div class="round-button"><div class="round-button-circle"><a href="http://example.com" class="round-button">Button!!</a></div></div>
Upvotes: 0