html - Positioning a button within an image in CSS -


i want insert button within image using css; image has fixed width , height, centered in page. button must remain stationary within image @ different resolution.

css doesn't allow other elements inside <img> tag. common go-to in situation put both image , button inside 2 wrapper <div> elements act table (vertically , horizontally centered). like so;

html

<div class="wrapper">   <div>     <img src="[your image src]">     <a class="button" href="[go page]">button</a>   </div> </div> 

css

.wrapper{   display: table;   width: 100%; /* add or remove depending on layout */ } .wrapper > div{   display: table-cell;   vertical-align: middle;   text-align: center; } 

as long image has no size constraints should sit flush in center of image :). enjoy!

edit ---

alternatively, remove <img> tag , put background-image of .wrapper , use background-size: cover; center :). can control height , width of image easily.

remember use vendor prefixes too. have handy list of them here although in sass.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -