Center image vertically in div [duplicate] - css

This question already has answers here:
How to vertically align an image inside a div
(37 answers)
Closed 5 years ago.
Basically screen is split in 2 part, left for logo, right for sponsor image.
I would like to vertical align the two image in center of screen. Now images are align on top of screen. I don't understand how to solve. Can you give some hint?
#logo {
float:left;
width: 50%;
height:100%;
}
#imgLogo {
height:100%;
}
#sponsor {
float:left;
width: 50%;
height:100%;
background:#ffffff;
display: inline-block;
vertical-align: middle;
}
#imgSponsor {
max-height:90%;
max-width:90%;
display: inline-block;
vertical-align: middle;
}
.app {
position:absolute;
left:0%;
top:0%;
height:100%;
width:100%;
text-align:center;
}
<div class="app">
<div id="logo">
<img id="imgLogo" src="logo.png">
</div>
<div id="sponsor">
<a href="#">
<img id="imgSponsor" src="http://www.foo.bar/wp-content/uploads/2017/10/foobar.jpg">
</a>
</div>
</div>

Here is a way you could approach your layout using flexbox:
body {
margin: 0;
}
.app {
display: flex;
align-items: center;
height: 100vh;
}
.app div {
flex: 1;
}
img {
width: 100%;
height: auto;
}
<div class="app">
<div id="logo">
<img id="imgLogo" src="https://unsplash.it/200x200">
</div>
<div id="sponsor">
<a href="#">
<img id="imgSponsor" src="https://unsplash.it/200x200">
</a>
</div>
</div>

You can use these 2 in your code which will center-center your image.
#logo {
float:left;
width: 50%;
height:100%;
}
#imgLogo {
height:100%;
}
#sponsor {
float:left;
width: 50%;
height:100%;
background:#ffffff;
display: inline-block;
vertical-align: middle;
text-align: center;
}
#imgSponsor {
max-height:90%;
max-width:90%;
display: inline-block;
vertical-align: middle;
}
.app {
position:absolute;
left:0%;
top:0%;
height:100%;
width:100%;
text-align:center;
}
<div class="app">
<div id="logo">
<img id="imgLogo" src="logo.png">
</div>
<div id="sponsor">
<a href="#">
<img id="imgSponsor" src="http://www.foo.bar/wp-content/uploads/2017/10/foobar.jpg">
</a>
</div>
</div>
or you can use:
background-position: center center:

That is where CSS flex comes very handy:
body {
margin: 0;
}
.app {
display: flex;
width: 100vw;
height: 100vh;
align-items: center;
justify-content: space-around;
}
#sponsor, #logo {
width: 50%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
#imgLogo {
height: 100%;
}
#imgSponsor {
max-height:90%;
max-width:90%;
}
#sponsor a {
display: flex;
width: 100%;
height: 100%;
align-items: center;
justify-content: center;
}
<div class="app">
<div id="logo">
<img id="imgLogo" src="https://placehold.it/200x200">
</div>
<div id="sponsor">
<a href="#">
<img id="imgSponsor" src="https://placehold.it/200x200">
</a>
</div>
</div>

Related

clip-path alternatives for Internet Explorer/Edge

I have a project that uses clip-paths to render a slant throughout the design. The scope of the project has changed and I now need to support IE/Edge, which do not support clip-paths.
There is a common repeated design element where the clip-path is applied to an image/text component wrapper, and clips the bottom right corner (you can see this in the snippet below).
I am not certain how to do this via other means so that it will work in IE/Edge. Is there another way of doing this that doesn't involve me having to export the images with the slant already applied?
.image-text-wrapper {
clip-path: polygon(0 0, 100% 0, 100% 75%, 0% 100%);
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
width: 600px;
background-color: aliceblue;
}
.image-text-wrapper .image {
width: 50%;
overflow: hidden;
}
.image-text-wrapper .text {
width: 50%;
text-align: center;
}
<div class="image-text-wrapper">
<div class="image">
<img src="https://img.purch.com/rc/640x415/aHR0cDovL3d3dy5zcGFjZS5jb20vaW1hZ2VzL2kvMDAwLzA4Mi8yMzEvb3JpZ2luYWwvbTMzLmpwZw==" />
</div>
<div class="text">
Content is here
</div>
</div>
One easy way that is supported but doesn't make the clipped part transparent is to add an overlay above with the same shape and you make its color the same as the background.
Here is an idea with linear-gradient:
.image-text-wrapper {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
width: 600px;
background-color: aliceblue;
position:relative;
}
.image-text-wrapper::before {
content:"";
position:absolute;
bottom:0;
left:0;
right:0;
height:25%;
background:linear-gradient(to bottom right,transparent 49.5%,#fff 50%);
}
.image-text-wrapper .image {
width: 50%;
overflow: hidden;
}
img {
display:block;
}
.image-text-wrapper .text {
width: 50%;
text-align: center;
}
<div class="image-text-wrapper">
<div class="image">
<img src="https://img.purch.com/rc/640x415/aHR0cDovL3d3dy5zcGFjZS5jb20vaW1hZ2VzL2kvMDAwLzA4Mi8yMzEvb3JpZ2luYWwvbTMzLmpwZw==" />
</div>
<div class="text">
Content is here
</div>
</div>
Another idea with transparency is to consider skew transformation but you have to adjust the HTML slightly:
.wrapper {
display:inline-block;
overflow:hidden;
}
.skew {
display:inline-block;
transform:skewY(-10deg);
transform-origin:bottom left;
overflow:hidden;
}
.skew > * {
transform:skewY(10deg);
transform-origin:bottom left;
}
.image-text-wrapper {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
width: 600px;
background-color: aliceblue;
}
.image-text-wrapper .image {
width: 50%;
overflow: hidden;
}
img {
display:block;
}
.image-text-wrapper .text {
width: 50%;
text-align: center;
}
body {
background:pink;
}
<div class="wrapper">
<div class="skew">
<div class="image-text-wrapper">
<div class="image">
<img src="https://img.purch.com/rc/640x415/aHR0cDovL3d3dy5zcGFjZS5jb20vaW1hZ2VzL2kvMDAwLzA4Mi8yMzEvb3JpZ2luYWwvbTMzLmpwZw==" />
</div>
<div class="text">
Content is here
</div>
</div>
</div>
</div>

FlexBox: How can i keep boxes fixed one below the other

I'm trying to create a page using FlexBox so i can keep the main image always centered with the top logo and page. And add of "off-center" text, next to the left.
My problem now is that i cannot make each box (image+text) keep their place vertically, boxes float and they have different space between each other based on what i'm using to view (big screen, laptop).
Not an expert with FlexBox, can i do that?
And also, i want to add a bar after the third box, 100% width...but it's placing in the middle of the page, between the boxes.
Any help will be welcome and i'll keep learning :)
body {
margin: 0;
}
.container {
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
height: 100vh;
}
.top {
border: 1px solid white;
width: 50%;
height: 10%;
align-self: flex-start;
text-align: center;
}
.inner-container {
border: 1px solid white;
width: 50%;
height: 60%;
display: flex;
}
.center {
position: absolute;
width: 50%;
text-align: left;
align-self: flex-end;
}
.off-center {
position: absolute;
vertical-align: bottom;
text-transform: uppercase;
padding-left: 10px;
min-width: 200px;
align-self: flex-end;
}
.center, .off-center {
position: absolute;
}
.center img {width: 100%;}
.off-center h2 {font-size:12px; font-family: 'Open Sans', sans-serif; font-weight: 400;text-transform: uppercase; color:black; display: block!important;margin: 0px;}
.off-center p {font-size: 20px; font-family:'aileronbold', sans-serif; display: block!important;margin: 0px;text-transform: none;}
.row.subscriptionBar {display:flex; background-color: black; display: block; padding:20px;}
.subscriptionBar h2 {color:white;}
.firstPart {display: }
#media screen and (min-width: 769px) {
.off-center {
margin-left: 50%;
}
#media screen and (max-width: 768px) {
.off-center {
margin-top: 105px;
}
}
<div class="container">
<div class="top"><img src="https://www.oilandgasreinvented.com/img/logo-placeholder.svg" width="80px"></div>
<div class="inner-container">
<div class="center">
<img src="http://hdimages.org/wp-content/uploads/2017/03/placeholder-image1.gif" alt=""></div>
<div class="off-center">
<h2 class="">ArtistName 1</h2>
<p>509476ZclHtqXy</p></div>
</div>
<div class="inner-container">
<div class="center">
<img src="http://hdimages.org/wp-content/uploads/2017/03/placeholder-image1.gif" alt=""></div>
<div class="off-center">
<h2 class="">ArtistName 2</h2>
<p>Title lala 1</p></div>
</div>
<div class="inner-container">
<div class="center">
<img src="http://hdimages.org/wp-content/uploads/2017/03/placeholder-image1.gif" alt=""></div>
<div class="off-center">
<h2 class="">ArtistName 3 444</h2>
<p>Title 093830</p></div>
</div>
</div>
.wrapper {
display: flex;
flex-flow: row wrap;
font-weight: bold;
text-align: center;
}
.wrapper > * {
padding: 10px;
flex: 1 100%;
}
header{
background: tomato;
}
section{
display: flex
}
.main {
background: deepskyblue;
}
.main img{
max-width: 100%;
}
.full-width {
background: lightgreen;
}
.main { order: 2; flex: 3 0px; }
.aside { flex: 1 auto; }
.aside-1 { order: 1; background: gold; width: 10%}
.aside-2 { order: 3; background: hotpink; position: relative; width: 10%}
.aside-2 > span {
position: absolute;
bottom: 0;
left: 0;
}
.vertical {
width: 15%; /* Modify this value for different screen size*/
}
/* .full-width { order: 4; } */
/*#media all and (min-width: 600px) {
.aside { flex: 1 auto; }
}
#media all and (min-width: 800px) {
.main { flex: 3 0px; }
.aside-1 { order: 1; }
.main { order: 2; }
.aside-2 { order: 3; }
.footer { order: 4; }
}*/
body {
padding: 2em;
}
<div class="wrapper">
<header><img src="https://www.oilandgasreinvented.com/img/logo-placeholder.svg" width="80px"></header>
<section>
<div class="main">
<img src="http://hdimages.org/wp-content/uploads/2017/03/placeholder-image1.gif" alt="">
</div>
<aside class="aside aside-1"></aside>
<aside class="aside aside-2"><span>Aside Right</span></aside>
</section>
<section>
<div class="main">
<img src="https://picsum.photos/200/300" alt="">
</div>
<aside class="aside aside-1 vertical"></aside>
<aside class="aside aside-2 vertical"><span>Aside Right</span></aside>
</section>
<section>
<div class="main">
<img src="http://hdimages.org/wp-content/uploads/2017/03/placeholder-image1.gif" alt="">
</div>
<aside class="aside aside-1"></aside>
<aside class="aside aside-2"><span>Aside Right</span></aside>
</section>
<section class="full-width">Full Width</section>
<section>
<div class="main">
<img src="http://hdimages.org/wp-content/uploads/2017/03/placeholder-image1.gif" alt="">
</div>
<aside class="aside aside-1"></aside>
<aside class="aside aside-2"><span>Aside Right</span></aside>
</section>
</div>
I'm just doing a quick sample because it's not clear on what you're looking for. If this is the direction you're hoping to move toward, then I may be able to assist further.
You just have a few too many things going on with your combination of flexbox and absolute positioning. Below is a version of your snippet with much of the unnecessary css commented out (so you can see exactly what it is) plus a couple of new additions.
Most important changes other than removing some of the absolute positioning are removing flex-wrap from your .container and adding flex-direction: column as well as matching the widths of .center and .off-center so you can use position: absolute on .off-center (good use of it in that case) along with margin-left equivalent to the width to ensure that it is positioned just to the right of your image container.
body {
margin: 0;
}
.container {
display: flex;
flex-direction: column;
align-items: center;
/*justify-content: center;
flex-wrap: wrap;
height: 100vh;*/
}
.top {
border: 1px solid white;
/*width: 50%;*/
height: 10%;
/*align-self: flex-start;*/
text-align: center;
}
.inner-container {
border: 1px solid white;
/*width: 50%;*/
height: 60%;
display: flex;
justify-content: space-around;
}
.center {
/*position: absolute;*/
width: 50%;
min-width: 200px;
text-align: left;
/*align-self: flex-end;*/
}
.off-center {
position: absolute;
/*vertical-align: bottom;*/
text-transform: uppercase;
padding-left: 10px;
width: 50%;
min-width: 200px;
align-self: flex-end;
margin-left: 50%;
}
/*.center, .off-center {
position: absolute;
}*/
.center img {
width: 100%;
}
.off-center h2 {
font-size: 12px;
font-family: 'Open Sans', sans-serif;
font-weight: 400;
text-transform: uppercase;
color: black;
display: block!important;
margin: 0px;
}
.off-center p {
font-size: 20px;
font-family: 'aileronbold', sans-serif;
display: block!important;
margin: 0px;
text-transform: none;
}
.row.subscriptionBar {
display: flex;
background-color: black;
display: block;
padding: 20px;
}
.subscriptionBar h2 {
color: white;
}
.firstPart {
display:
}
/*#media screen and (min-width: 769px) {
.off-center {
margin-left: 50%;
}
#media screen and (max-width: 768px) {
.off-center {
margin-top: 105px;
}
}*/
<div class="container">
<div class="top"><img src="https://www.oilandgasreinvented.com/img/logo-placeholder.svg" width="80px"></div>
<div class="inner-container">
<div class="center">
<img src="http://hdimages.org/wp-content/uploads/2017/03/placeholder-image1.gif" alt="">
</div>
<div class="off-center">
<h2 class="">ArtistName 1</h2>
<p>509476ZclHtqXy</p>
</div>
</div>
<div class="inner-container">
<div class="center">
<img src="http://hdimages.org/wp-content/uploads/2017/03/placeholder-image1.gif" alt=""></div>
<div class="off-center">
<h2 class="">ArtistName 2</h2>
<p>Title lala 1</p>
</div>
</div>
<div class="inner-container">
<div class="center">
<img src="http://hdimages.org/wp-content/uploads/2017/03/placeholder-image1.gif" alt=""></div>
<div class="off-center">
<h2 class="">ArtistName 3 444</h2>
<p>Title 093830</p>
</div>
</div>
</div>

Vertically centering element to it's siblings height

I'm trying to center vertically .container img:nth-child(2) to its siblings height but it just doesn't work. I tried to center it vertically with a lot of commands (and adding it to both - .container and .child) but nothing happened.
Also, when the window is scaled down, I want the first .container img child to be centered and above the second one. The whole container should also be horizontally aligned to the center of browser windows width (screenshot attached).
Is it possible without using media queries? Could you guys help me out? I'm a beginner and I'm really trying to figure those displays and positioning out...
body {
margin: 0;
}
.parent {
background-image:url("http://bossfight.co/wp-content/uploads/2016/04/boss-fight-free-high-quality-stock-images-photos-photography-trees-forest-mist.jpg");
background-size: cover;
flex-wrap: wrap;
height: 100vh;
position: relative;
}
.parent h1 {
margin-top:0;
padding-top: 2em;
text-align: center;
font-family: helvetica;
}
.container {
display: flex;
align-items: center;
justify-content: center;
align-content: center;
position: absolute;
bottom: 2em;
width: 100%;
}
.child {
display: inline-flex;
padding: 0 5px;
}
.container img {
float: left;
}
.container a {
opacity: 0.5;
}
.container a:hover {
opacity: 1;
}
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>random title</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="parent">
<h1>Heading example</h1>
<div class="container">
<div class="child">
<a href="_top">
<img src="http://placehold.it/90x90" alt="ux-button">
<img src="http://placehold.it/150x40" alt="ux-button">
</a>
</div>
<div class="child">
<a href="_top">
<img src="http://placehold.it/90x90" alt="ux-button">
<img src="http://placehold.it/150x40" alt="ux-button">
</a>
</div>
<div class="child">
<a href="_top">
<img src="http://placehold.it/90x90" alt="ux-button">
<img src="http://placehold.it/150x40" alt="ux-button">
</a>
</div>
</div>
</body>
</html>
You can use nested flexbox with media queries.
Make each anchor link as flexbox.
.container a {
display: flex;
align-items: center;
justify-content: center;
}
Switch flex-direction value in the media queries.
#media (max-width: 768px) {
.container a {
flex-direction: column;
}
}
body {
margin: 0;
}
.parent {
background-image: url("http://bossfight.co/wp-content/uploads/2016/04/boss-fight-free-high-quality-stock-images-photos-photography-trees-forest-mist.jpg");
background-size: cover;
flex-wrap: wrap;
height: 100vh;
position: relative;
}
.parent h1 {
margin-top: 0;
padding-top: 2em;
text-align: center;
font-family: helvetica;
}
.container {
display: flex;
align-items: center;
justify-content: center;
/* align-content: center; */
position: absolute;
bottom: 2em;
width: 100%;
}
.child {
padding: 0 5px;
}
.container img {
/* float: left; */
}
.container a {
opacity: 0.5;
display: flex;
align-items: center;
justify-content: center;
}
.container a:hover {
opacity: 1;
}
#media (max-width: 768px) {
.container a {
flex-direction: column;
}
}
<div class="parent">
<h1>Heading example</h1>
<div class="container">
<div class="child">
<a href="_top">
<img src="http://placehold.it/90x90" alt="ux-button">
<img src="http://placehold.it/150x40" alt="ux-button">
</a>
</div>
<div class="child">
<a href="_top">
<img src="http://placehold.it/90x90" alt="ux-button">
<img src="http://placehold.it/150x40" alt="ux-button">
</a>
</div>
<div class="child">
<a href="_top">
<img src="http://placehold.it/90x90" alt="ux-button">
<img src="http://placehold.it/150x40" alt="ux-button">
</a>
</div>
</div>
Make your have display:flex; justify-content:center; flex-direction:row
and have the be flex: 0 1 auto; align-self: center;
body {
margin: 0;
}
.parent {
background-image:url("http://bossfight.co/wp-content/uploads/2016/04/boss-fight-free-high-quality-stock-images-photos-photography-trees-forest-mist.jpg");
background-size: cover;
flex-wrap: wrap;
height: 100vh;
position: relative;
}
.parent h1 {
margin-top:0;
padding-top: 2em;
text-align: center;
font-family: helvetica;
}
.container {
display: flex;
align-items: center;
justify-content: center;
align-content: center;
position: absolute;
bottom: 2em;
width: 100%;
}
.child {
display: inline-flex;
padding: 0 5px;
}
.child>a{
display:flex;
flex-direction: row;
justify-content:center;
}
.child>a>img{
flex:0 1 auto;
align-self:center
}
.container img {
float: left;
}
.container a {
opacity: 0.5;
}
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>random title</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="parent">
<h1>Heading example</h1>
<div class="container">
<div class="child">
<a href="_top">
<img src="http://placehold.it/90x90" alt="ux-button">
<img src="http://placehold.it/150x40" alt="ux-button">
</a>
</div>
<div class="child">
<a href="_top">
<img src="http://placehold.it/90x90" alt="ux-button">
<img src="http://placehold.it/150x40" alt="ux-button">
</a>
</div>
<div class="child">
<a href="_top">
<img src="http://placehold.it/90x90" alt="ux-button">
<img src="http://placehold.it/150x40" alt="ux-button">
</a>
</div>
</div>
</body>
</html>

Safari isn't stretching image to flexbox grid

I'm trying to build a simple teaser grid for featured posts on a website using flexbox. It should look like this:
And in FF and Chrome it's all good. If i change the resolution of one image, all the others follow and update their size. But not in Safari. Whatever i do, it never fits to an equal height:
I really don't get the point why this is happening. Each image container on the right has exactly 50% of the height calculated by flexbox. And each image should be stretched to that height.
I could probably achieve this with background-size:cover but i would love to find a solution to use img tags instead.
Here's a demo: https://jsfiddle.net/7tjw8j83/1/
.featured-grid{
margin: 0;
padding: 0;
display: flex;
flex-wrap: wrap;
}
img{
width: 100%;
height: 100%;
display: block;
object-fit:cover;
}
.left{
width: 66.6666%;
}
.right{
width: 33.3333%;
display: flex;
flex-direction: column;
}
.right-top{
background: green;
flex: 1;
}
.right-bottom{
background: red;
flex: 1;
}
<div class="featured-grid">
<div class="left">
<img src="https://unsplash.it/600/450?image=1055">
</div>
<div class="right">
<div class="right-top">
<img src="https://unsplash.it/600/400?image=1051">
</div>
<div class="right-bottom">
<img src="https://unsplash.it/600/400?image=1057">
</div>
</div>
</div>
In addition to Michaels suggestion, you could do like this, where I used background-image instead of img (since you use a given height anyway), and how to add text at an absolute position
html, body {
margin: 0;
}
.featured-grid{
display: flex;
height: 100vh;
}
div {
position: relative;
background-position: center;
background-repeat: no-reapat;
background-size: cover;
overflow: hidden;
}
.left {
width: 66.666%;
}
.right{
width: 33.333%;
display: flex;
flex-direction: column;
}
.right-top{
flex: 1;
}
.right-bottom{
flex: 1;
}
.text {
position: absolute;
left: 10px;
bottom: 10px;
color: white;
}
.text > * {
margin: 5px;
}
<div class="featured-grid">
<div class="left" style="background-image: url(https://unsplash.it/600/450?image=1055)">
<div class="text">
<h2>Title</h2>
<h3>Text</h3>
</div>
</div>
<div class="right">
<div class="right-top" style="background-image: url(https://unsplash.it/600/400?image=1051)">
<div class="text">
<h2>Title</h2>
<h3>Text</h3>
</div>
</div>
<div class="right-bottom" style="background-image: url(https://unsplash.it/600/400?image=1057)">
<div class="text">
<h2>Title</h2>
<h3>Text</h3>
</div>
</div>
</div>
</div>
Updated based on a comment
html, body {
margin: 0;
}
.featured-grid{
display: flex;
height: 100vh;
}
div {
position: relative;
overflow: hidden;
}
img{
width: 100%;
height: 100%;
display: block;
object-fit:cover;
}
.left {
width: 66.666%;
}
.right{
width: 33.333%;
display: flex;
flex-direction: column;
}
.right-top{
flex: 1;
}
.right-bottom{
flex: 1;
}
.text {
position: absolute;
left: 10px;
bottom: 10px;
color: white;
}
.text > * {
margin: 5px;
}
<div class="featured-grid">
<div class="left">
<img src="https://unsplash.it/600/450?image=1055">
<div class="text">
<h2>Title</h2>
<h3>Text</h3>
</div>
</div>
<div class="right">
<div class="right-top">
<img src="https://unsplash.it/600/400?image=1051">
<div class="text">
<h2>Title</h2>
<h3>Text</h3>
</div>
</div>
<div class="right-bottom">
<img src="https://unsplash.it/600/400?image=1057"> <div class="text">
<h2>Title</h2>
<h3>Text</h3>
</div>
</div>
</div>
</div>
Updated (2:nd) based on a comment
html,
body {
margin: 0;
}
.featured-grid {
display: flex;
}
div {
position: relative;
overflow: hidden;
}
img {
visibility: hidden;
display: block;
}
img.show {
position: absolute;
visibility: visible;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: block;
object-fit: cover;
}
.left img {
max-height: 100vh;
}
.right img {
max-height: 50vh;
}
.left {
width: 66.666%;
}
.right {
width: 33.333%;
display: flex;
flex-direction: column;
}
.right-top {
flex: 1;
}
.right-bottom {
flex: 1;
}
.text {
position: absolute;
left: 10px;
bottom: 10px;
color: white;
}
.text > * {
margin: 5px;
}
<div class="featured-grid">
<div class="left">
<img src="https://unsplash.it/300/250?image=1055">
<img class="show" src="https://unsplash.it/300/250?image=1055">
<div class="text">
<h2>Title 1</h2>
<h3>Text 1</h3>
</div>
</div>
<div class="right">
<div class="right-top">
<img src="https://unsplash.it/300/200?image=1057">
<img class="show" src="https://unsplash.it/300/200?image=1057">
<div class="text">
<h2>Title 2</h2>
<h3>Text 2</h3>
</div>
</div>
<div class="right-bottom">
<img src="https://unsplash.it/300/200?image=1057">
<img class="show" src="https://unsplash.it/300/200?image=1057">
<div class="text">
<h2>Title 3</h2>
<h3>Text 3</h3>
</div>
</div>
</div>
</div>

Why img is not moving?

I am trying to center an element in a bottom-block div, but it stays to the left. Here is my code:
.logo {
display: inline-block;
height: 100px;
width: 100px;
padding-bottom: 10px;
}
.logo img {
box-sizing: padding-box;
display: block;
width: 100%;
height: auto;
margin: 0 auto;
}
<div class="bottom_block">
<a class="logo" href="#">
<img src="Style/img/logo_uniqa.jpg" alt="logo">
</a>
</div>
How can I fix this?
Try this:
.logo {
display: block;
padding-bottom: 10px;
}
.logo img {
display: block;
margin: 0 auto;
}
<div class="bottom_block">
<a class="logo" href="#">
<img src="http://placehold.it/100x100" alt="logo">
</a>
</div>
Try adding this css:
.bottom_block{
text-align:center;
}

Resources