How to align div next to two rows?

1

I want to leave the last image centered in the middle of the two rows but I do not know how to do it I used a margin-top: 15%; I went to the center as I want to but the second row came down and was not close to the first one and starting at the end of the last image.

Followthecode:

<divclass="row">
  <div class="col-md-3">
    <img src="../assets/img/per.png" style="height: 100%; width: 100%;">
  </div>
  <div class="col-md-3">
    <img src="../assets/img/per.png" style="height: 100%; width: 100%;">
  </div>
  <div class="col-md-3">
    <img src="../assets/img/per.png" style="height: 100%; width: 100%;">
  </div>
  <div class="col-md-3" style="margin-top: 15%;">
    <img src="../assets/img/per.png" style="height: 100%; width: 100%;">
  </div>
</div>
<div class="row">
  <div class="col-md-3">
    <img src="../assets/img/per.png" style="height: 100%; width: 100%;">
  </div>
  <div class="col-md-3">
    <img src="../assets/img/per.png" style="height: 100%; width: 100%;">
  </div>
  <div class="col-md-3">
    <img src="../assets/img/per.png" style="height: 100%; width: 100%;">
  </div>
</div>
    
asked by anonymous 15.01.2018 / 19:41

3 answers

3

I was able to do with transform: translateY . I created the .vertical class, and put it in <div> that you want to align vertically.

.vertical {
    transform: translateY(50%);
}

Run the Snipper in "All Page" to see working fine. Well it is with the Bootstrap classes according to the code that you have posted ...

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Page Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" media="screen" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
<style>
 
    @media screen and (min-width: 768px) {
           .vertical{
              transform: translateY(50%);
           }
        }

</style>
</head>
<body>
    
<div class="row">
    <div class="col-md-3 col-ms-3 col-xs-3">
        <img src="http://placecage.com/50/150"style="height: 100%; width: 100%;">
    </div>
    <div class="col-md-3 col-ms-3 col-xs-3">
        <img src="http://placecage.com/50/150"style="height: 100%; width: 100%;">
    </div>
    <div class="col-md-3 col-ms-3 col-xs-3">
        <img src="http://placecage.com/50/150"style="height: 100%; width: 100%;">
    </div>
    <div class="col-md-3 col-ms-3 col-xs-3 vertical">
        <img src="http://placecage.com/50/150"style="height: 100%; width: 100%;">
    </div>
    </div>
    <div class="row">
    <div class="col-md-3 col-ms-3 col-xs-3">
        <img src="http://placecage.com/50/150"style="height: 100%; width: 100%;">
    </div>
    <div class="col-md-3 col-ms-3 col-xs-3">
        <img src="http://placecage.com/50/150"style="height: 100%; width: 100%;">
    </div>
    <div class="col-md-3 col-ms-3 col-xs-3">
        <img src="http://placecage.com/50/150"style="height: 100%; width: 100%;">
    </div>
</div>
    
    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script><scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>

NOTE: In order not to give error on different screens you can put in the div the sizes for each screen (col-md-3 col-ms-3 col-xs-3) , like this:

<div class="col-md-3 col-ms-3 col-xs-3 vertical">
    <img src="http://placecage.com/50/150"style="height: 100%; width: 100%;">
</div>
    
15.01.2018 / 20:14
2

The response from @hugocsl is correct, but failed to put a @media rule . Because the site is responsive, Bootstrap turns all columns to 1 only when the screen is less than 769px .

So, by complementing the response from @hugocsl , the CSS would look like this:

@media screen and (min-width: 768px) {
   .vertical{
      transform: translateY(50%);
   }
}

See the hole:

    
15.01.2018 / 20:33
1

I would put a col-md-12 div container to fill the screen and then go with the div with class col-md-6 each (if it's really just two divs).

<div class="container">
<div class="row">
<div class="col-md-12" style="text-align:center">
<img src="#" alt="sua imagem">
</div>
</div>
<div class="row">
<div class="col-md-6">
<p>Aqui seria suas duas colunas em um ROW (já é mais que suficiente)</p>
</div>
<div class="col-md-6">
<p>Pode tambem alinhas com CSS ou de uma forma mais bruta usando o atributo style="text-align:center"; para a imagem geralmente uso isso.</p>
</div>

    
15.01.2018 / 20:26