Margin-right broken on width 100%
It's better if you remove width:100%
. write like this:
.photo-caption {
left:0;
right:0;
background-color: black;
position: absolute;
bottom: 0px;
margin-right: 10px;
margin-left: 10px;
margin-bottom: 10px;
}
The problem is that width=100%
would give photo-caption
exact width of article-container
; adding margins (or padding) would not affect width calculation. You can do this yourself using the css calc()
so the style become:
.photo-caption {
width: calc(100% - 20px); // 20 = right margin + left margin
background-color: black;
position: absolute;
bottom: 0px;
margin-right: 10px;
margin-left: 10px;
margin-bottom: 10px;
}
Note that you might want to check for calc() browser support here
An absolutely positioned element is positioned with top
, left
, right
and bottom
, not with margin
.