Reputation: 5929
I have a problem (obviously). I have to position a element to be always on the right side of a image. But I can't use the img-Tag as a container. Also I'm using bootstrap, which makes it impossible to set a fixed width for the container.
Small example jsFiddle
<div id="container" class="col-lg-3">
<div class="positioning">
Some Text
</div>
<img src="http://placehold.it/300x200/eeeeee" />
</div>
I hope that is understandable
EDIT: Basically I want the image to behave like a container, without using "background-image"
Upvotes: 5
Views: 31843
Reputation: 73
An absolutely positioned element will always be positioned relating to it's parent that has 'position: relative'. Here is a good example http://learnlayout.com/position.html
So if you wrap the and the content inside a div and position it relatively, then you can position the content absolutely inside it. Then, you just need to make the display: block; and width 100% so the will fill the whole container.
.container {
position: relative;
}
.container img {
display: block;
width: 100%;
}
.container .content {
position: absolute;
bottom: 10px;
right: 10px;
}
Here's an example: http://jsfiddle.net/kbzvyjy9/
Hope that solves your issue.
Upvotes: 0
Reputation: 86
I think the <figure>
tag is the best solution here.
Here's an exemple: http://jsfiddle.net/mzd7maqq/7/
Upvotes: 3
Reputation: 1079
Wrap the image and the caption in a div with position: relative
like in this Fiddle
html
<div id="container" class="col-lg-3">
<div class="img-container">
<div class="positioning">
Some Text
</div>
<img src="http://placehold.it/300x200/eeeeee" />
</div>
</div>
CSS
.col-lg-3{
width: 25%;
min-width: 230px;
float: left;
position: relative;
min-height: 1px;
padding-left: 15px;
padding-right: 15px;
background-color: #aaa;
text-align: center;
}
.col-lg-3 img {
max-width: 100%;
}
.img-container {
display: inline-block;
position: relative;
}
.positioning{
position: absolute;
right: 15px;
bottom: 22px;
background-color: red;
color: white;
padding: 4px;
font-size: 17px;
line-height: 18px;
}
Upvotes: 14
Reputation: 550
You can use the float property and set it to right.
style="float:right";
Upvotes: 0