0
I have an image that has a height
of 100%
. However, the width
exceeds the lateral limits and the image is cut on the right side and I would like to center it to cut equally on both sides. Here is a Jsfiddle that I made for demonstration
0
I have an image that has a height
of 100%
. However, the width
exceeds the lateral limits and the image is cut on the right side and I would like to center it to cut equally on both sides. Here is a Jsfiddle that I made for demonstration
1
You can use as background
and apply the background-position: center
Documentation: https://developer.mozilla.org/en-US/docs/Web/CSS/background-position
Note:
background-position: center
can be used directly withinbackground:
, as in the example
.foo {
width: 100%;
}
.foo .cover {
/* propriedades para centralizar e assim irá aparar igualmente ambos lados */
background: url(https://i.stack.imgur.com/DD8Pf.jpg) center no-repeat;
/* a altura exata da imagem */
height: 1350px;
}
<div class="foo">
<div class="cover"></div>
</div>
Worked perfectly!
Browser other questions tagged css
You are not signed in. Login or sign up in order to post.
You want to center the background on Body, or you want to center an element that has an image in the center of Body?
– hugocsl