How to make text over the image/button using html/css.
Eg: I have a button(Login Button). I want the text \"Login\" to be placed over that button. The text should be cen
If you need to center text over an image, you might want to wrap your img
in a div, use positioning on the img
itself as well as the text.
You would then be able to center this using transforms (supporting multi-lined text).
demo
.wrap {
position: relative;
display: inline-block;
height: 300px;
width: 300px;
}
img {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
}
p {
position: absolute;
top: 50%;
left: 50%;
display: inline-block;
transform: translate(-50%, -50%);
font-size: 20px;
color: tomato;
font-weight: bold;
}
some text
Since button elements are centered automatically by default, you're issue would be to add an image to the button.
This can be achieved using the background-image
property.
So in your CSS use something like:
background-image:url(http://lorempixel.com/200/200);
adjusting the size using
background-size:100% 100%;
to stretch it to the full size of the button.