Skip to content Skip to sidebar Skip to footer

Centering Responsive Divs With Images Inside

I would like to center the following jsfiddle to be centered vertically at alll times, responsive design makes it hard for me to guess where to get a value from because all tutoria

Solution 1:

Give following css will do a trick:

.rowOne > div {
    text-align: center;
}


.rowTwo > div {
    text-align: center;
}

Updated Fiddle

Solution 2:

First you should add extra div to your markup and put rowOne and rowTwo in the extra div, named middle:

Markup

<divclass="wrapper"><divclass="middle"><divclass="rowOne"></div><divclass="rowTwo"></div></div></div>

Then you should add some CSS:

CSS

.wrapper{
    display: table;
    position: absolute;
    height: 100%;
    width: 100%;
}
.wrapper.middle {
    display: table-cell;
    vertical-align: middle;
}
.wrapperdiv{ text-align:center }
.wrapperdiva{ display: inline-block }

Solution 3:

Please check code.. Please in HTML wrap with div class .centered and in css position:absolute and transform suing css3 .. Its pretty easy and cool.

https://jsfiddle.net/34o9vcba/19/

.wrapper {
    height: 100vh;
    margin: 0 auto;
    position: relative;
    width: 100%;
}
.rowOne, .rowTwo {
    width: 50%;
    height: auto;
    float: left;
}
.Absolute-Center.is-Image {
  height: auto;
}

.centered {
  position: absolute;
  transform: translate(-50%, -50%);
  top: 50%;
  left: 50%;
  text-align: center;
}

.Absolute-Center.is-Imageimg {
  width: 50%;
  height: auto;
}
<divclass="wrapper"><divclass="centered"><divclass="rowOne"><divclass="telefoonButton"><ahref="tel:0652333817"title="Bel ons"><imgsrc="http://eightytwenty.nl//wordpress/wp-content/uploads/2015/12/phoneNook.png"alt="telefoon"class="Center-Block Absolute-Center is-Image"></a></div><divclass="mailButton"><ahref="mailto:slotenmakerdenhaag@gmail.com"title="Mail ons"><imgsrc="http://eightytwenty.nl/wordpress/wp-content/uploads/2015/12/mailNook.png"alt="mail"class="Center-Block Absolute-Center is-Image"></a></div></div><divclass="rowTwo"><divclass="infoButton"><ahref="contact"title="Bel ons"><imgsrc="http://eightytwenty.nl//wordpress/wp-content/uploads/2015/12/infoNook.png"alt="telefoon"class="Center-Block Absolute-Center is-Image"></a></div><divclass="contactButton"><ahref="contact#contact"title="Mail ons"><imgsrc="http://eightytwenty.nl//wordpress/wp-content/uploads/2015/12/contactNook.png"alt="mail"class="Center-Block Absolute-Center is-Image"></a></div></div></div></div>

Solution 4:

Ok, try this.

html, body {
height: 100%;
}

body {
margin: 0;
}

.wrapper {
height: 100%;
width: 100%;
margin: 0 auto;
text-align: center;
}

.centered {
position: relative;
overflow: hidden;
top: 50%;
transform: translateY(-50%);
-webkit-transform: translateY(-50%);
}

Solution 5:

I worked it out!

<divclass="wrapper"><divclass="middle"><divclass="rowOne"><divclass="telefoonButton"><ahref="tel:0652333817"title="Bel ons"><imgsrc="http://eightytwenty.nl//wordpress/wp-content/uploads/2015/12/phoneNook.png"alt="telefoon"class="Center-Block Absolute-Center is-Image"></a></div><divclass="mailButton"><ahref="mailto:slotenmakerdenhaag@gmail.com"title="Mail ons"><imgsrc="http://eightytwenty.nl/wordpress/wp-content/uploads/2015/12/mailNook.png"alt="mail"class="Center-Block Absolute-Center is-Image"></a></div></div><divclass="rowTwo"><divclass="infoButton"><ahref="contact"title="Bel ons"><imgsrc="http://eightytwenty.nl//wordpress/wp-content/uploads/2015/12/infoNook.png"alt="telefoon"class="Center-Block Absolute-Center is-Image"></a></div><divclass="contactButton"><ahref="contact#contact"title="Mail ons"><imgsrc="http://eightytwenty.nl//wordpress/wp-content/uploads/2015/12/contactNook.png"alt="mail"class="Center-Block Absolute-Center is-Image"></a></div></div></div><div></div>

.telefoonButton, .mailButton, .infoButton, .contactButton {
  float: left;
}
.wrapper{
    display: table;
    position: absolute;
    height: 100%;
    width: 100%;
}
.wrapper .middle {
    display: table-cell;
    vertical-align: middle;
}
.wrapper div{ text-align:center }
.wrapper div a{ display: inline-block }
.rowOne, .rowTwo {
    width: 50%;
    height: auto;
    float: left;
}
.Absolute-Center.is-Image {
  height: auto;
}

.Absolute-Center.is-Image img {
  width: 50%;
  height: auto;
}

Post a Comment for "Centering Responsive Divs With Images Inside"