I have a layout problem where I want to center images horizontally that is bigger than the container they are in. the container size is 800px and the images are 1200px.
when I use regular max-width
and margin:0 auto
it results in something like this. how can I make the images centered horizontally in this layout and keep the image size to 1200px
3
Answers
width: 100%
should work perfectly. It will be easier to answer if you share your code.I suggest you just change the HTML with
<div>
separator, it will make sense for the image width will follow its parents instead of the paragraph’s parent.Before:
After (run this snippet only on full page version):
Apply
display: block;
and
position:relative;to your image to make it possible to move it, then
left: 50%;(which moves its left side to the center of the parent container) and
transform: translateY(-50%);`, which moves it to the left by 50% of its own width.All this together will center it horizontally the way you asked for.