centering a image in a section [duplicate] - css

This question already has answers here:
How to make an image center (vertically & horizontally) inside a bigger div [duplicate]
(36 answers)
Closed 7 years ago.
I want this image be right in the center of the page, in a section but it is not working, btw I'am using jade and sass.
Jade:
section.believe(data-section-name='texture', <='', body='')
img.minion(src="/images/IMG_6219.jpg")
Sass:
.minion
top: 50%
left: 50%
padding: 100px
margin: 0 auto
height: 10%
transform: rotate(90deg)
This is what keeps happening

try this
.minion
position: absolute
top: calc(50% - 400px)
left: calc(50% - 400px)
margin: 0
400px = half of the image width/height

Related

After changing the image, the CSS style of the image is invalid [duplicate]

This question already has answers here:
Flexbox: center horizontally and vertically
(14 answers)
Closed 4 months ago.
At first, my picture is like this, the avatar can be displayed in the center。
And the CSS code for class .avator is:
.idx_box .search_box .avator {
width: 0.64rem;
height: 0.64rem;
border-radius: 50%;
background: #feb5b4;
}
The CSS code for img is:
.idx_box .search_box .avator img {
width: 0.3rem;
height: 0.3rem;
margin: 0 auto;
-webkit-transform: translateY(45%);
-ms-transform: translateY(45%);
transform: translateY(45%);
}
where 1rem is equal to 100px;
However, when I changed the picture, the horizontal centering effect didn't work. The CSS code is still the same as above and has not changed. I can't find the reason. Picture as shown:
Thanks!
Just add this 'text-align:center;' to .avator class.
I think the reason it didnt work, was because the image wasnt centrally aligned in the first instance. This showed in the second instance when you put a smaller image.
By the way, this 'margin: 0 auto;' inside the img, does nothing.

Scaling an SVG in CSS [duplicate]

This question already has answers here:
Can I change the height of an image in CSS :before/:after pseudo-elements?
(14 answers)
Closed 3 years ago.
I have the following line in my stylesheet that calls my website logo.
.navbar__logo::before{
content: url("../images/logo/logo.svg");}
How can I scale this down? I'm learning a bit about viewPort & viewBox but cant seem to get it to work.
Thanks in advance.
After declaring a viewBox in your svg file, you should definitely give your pseudo-element explicit width and height:
.navbar__logo::before {
content: url("../images/logo/logo.svg");
width: 200px;
height: 50px;
}
Beyond that, if you wish to dynamically resize your pseudo-element and / or animate the scaling you can use transform: scale():
.navbar__logo::before {
content: url("../images/logo/logo.svg");
width: 200px;
height: 50px;
transform: scale(0.5);
}

Why CSS transforms scale and translate are inconsistent math wise? [duplicate]

This question already has answers here:
Why does order of transforms matter? rotate/scale doesn't give the same result as scale/rotate
(2 answers)
Simulating transform-origin using translate
(2 answers)
Closed 3 years ago.
I have a 100px*100px div with a square image as child. This image has a scale of 1.5, so the size is 150px*150px.
Now if I apply on the image a translation of 25px (X or Y), should I not have the image at the edge of its parent?
Currently I need to translate of 16px to get to the edge, that's make no sense to me. What is the calcul here?
I'm pretty sure I missing the obvious here, but I'm having a hard time to figure it out.
.parent {
width: 100px;
height: 100px;
border: 1px solid red;
margin: 0 auto
}
img {
width: 100%;
height: auto;
transform: scale(1.5) translateY(-25px);
z-index: -1;
position: relative;
}
https://codepen.io/geosenna/pen/pYNyjR

Set property to current width of element with CSS? [duplicate]

This question already has answers here:
Element will not stay centered, especially when re-sizing screen
(2 answers)
Closed 5 years ago.
I'm looking for some syntax like this:
.centered{
left: calc(50% - current-width/2)
}
Basically, a way to reference the current-width of the target element so that I can have a flexible-width item centered. Does this exist?
One answer is to move it left and then translate it:
.centered {
left: 50%;
transform: translate(-50%);
}
But a better way is to use Flexbox on the parent element:
.centeredParent {
display: flex;
justify-content: center;
}

calc() in Safari for left [duplicate]

This question already has answers here:
CSS calc not working in Safari and fallback
(2 answers)
Closed 6 years ago.
I center a div within another one by using calc() function. It works fine in Chrome, Firefox, Opera and even in IE but in Safari this method doesn't work.
Any suggestions without a javascript fixation?
left: -webkit-calc(50% - 25px);
left: -moz-calc(50% - 25px);
left: calc(50% - 25px);
As Hashem said, it doesn't work in earlier versions of safari.
http://caniuse.com/calc
However if you just want to center the div, a couple ideas come to mind.
One, you could give the container a
margin-right: auto;
margin-left: auto;
width: 50%;
Or make the width whatever you like.
Second, you could give the parent div
text-align:center;
Make the child div
display: inline-block;
and/or set a width for the child div.

Resources