Using JavaScript I am wrapping an image with a wrapper and adding an element to overlay in the bottom right corner. The problem is that when I define the CSS to make sure the overlay is positioned correctly in reference to the image I lose the center or right alignment.
I can modify the CSS and JavaScript but cannot modify the HTML.
I also cannot assume the width of the images and would prefer not to use JS to measure those width to keep everything as light as possible and to not interfere with any media queries in the larger project.
I created a quick jsFiddle to explain the problem a little better: https://jsfiddle.net/terriann/p220ddet/6/
RESOLVED see Fiddle: http://jsfiddle.net/terriann/p220ddet/11/
Sample HTML output (cause SO requires code if I link to jsfiddle)
<div class="wrapper aligncenter">
<img src="https://farm4.staticflickr.com/3305/3493791131_cbfb113360.jpg" alt="Puppy" class="aligncenter wrapme" style="width:300px">
<div class="countbox">View Details</div>
</div>
<div class="wrapper alignright">
<img src="https://farm4.staticflickr.com/3305/3493791131_cbfb113360.jpg" alt="Puppy" class="alignright wrapme" style="width:300px">
<div class="countbox">View Details</div>
</div>
CSS
.aligncenter {
display: block;
margin-right: auto;
margin-left: auto;
}
.alignleft {
display: block;
margin-right: auto;
margin-left: 0;
}
.alignright {
display: block;
margin-right: 0;
margin-left: auto;
}
.wrapper {
position: relative;
display: inline-block;
}
.countbox {
position: absolute;
bottom: 10px;
right: 10px;
background-color:#fff;
padding:10px;
}
I'm sure this has been answered before but could not find an answer through previous searches because there are too many keywords involved :/
To clarify the goals:
- The floating box should be overlayed in the bottom right corner of the image
- The image itself should retain the same horizontal alignment as it would if I wasn't adding the overlay.
- Original image should still retain it's alignment while not applying any wrapper to the images with class nowrap (a different name can be applied to align the wrapped graphics correct, if necessary)
Here is a clarifying image: