My div's don't align in my responsive grid layout

Viewed 47

Here is my codepen for what I have so far https://codepen.io/jonnydrama85/pen/NWRxwVQ

/********** Base styles **********/
* {
  box-sizing: border-box;


}

h1 {
  font-family: monospace;
  margin-top: 30px;
  margin-bottom: 50px;
  text-align: center;
}

p {
  border: 1px solid black;
  background-color: #A52A2A;
  width: 90%;
  height: 150px;
  margin-right: auto;
  margin-left: auto;
  font-family: Arial, Helvetica, sans-serif;
  color: white;
}

/* Simple Responsive Framework. */
.row {
  width: 100%;
}

/********** Large devices only **********/
@media (min-width: 1200px) {
  .col-lg-1, .col-lg-2, .col-lg-3, .col-lg-4, .col-lg-5, .col-lg-6, .col-lg-7, .col-lg-8, .col-lg-9, .col-lg-10, .col-lg-11, .col-lg-12 {
    float: left;
    
  }
  .col-lg-1 {
    width: 8.33%;
  }
  .col-lg-2 {
    width: 16.66%;
  }
  .col-lg-3 {
    width: 25%;
  }
  .col-lg-4 {
    width: 33.33%;
  }
  .col-lg-5 {
    width: 41.66%;
  }
  .col-lg-6 {
    width: 50%;
  }
  .col-lg-7 {
    width: 58.33%;
  }
  .col-lg-8 {
    width: 66.66%;
  }
  .col-lg-9 {
    width: 74.99%;
  }
  .col-lg-10 {
    width: 83.33%;
  }
  .col-lg-11 {
    width: 91.66%;
  }
  .col-lg-12 {
    width: 100%;
  }
}

/********** Medium devices only **********/
@media (min-width: 992px) and (max-width: 1199px) {
  .col-md-1, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8, .col-md-9, .col-md-10, .col-md-11, .col-md-12 {
    float: left;
  }


  .col-md-1 {
    width: 8.33%;
  }

  .col-md-2 {
    width: 16.67%;
  }

  .col-md-3 {
    width: 25%;
  }

  .col-md-4 {
    width: 33.33%;
  }

  .col-md-5 {
    width: 41.67%;
  }

  .col-md-6 {
    width: 50%;
  }

  .col-md-7 {
    width: 58.33%;
  }

  .col-md-8 {
    width: 66.67%;
  }

  .col-md-9 {
    width: 75%;
  }

  .col-md-10 {
    width: 83.33%;
  }

  .col-md-11 {
    width: 91.67%;
  }
  .col-md-12 {
    width: 100%;
  }


}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="style.css">
<title>Module2-solution!</title>
<style>



</style>
</head>
<body>
<h1>My Menu</h1>

<div class="row">
  <div class="col-lg-4 col-md-6"><p>Item 1</p></div>
  <div class="col-lg-4 col-md-6"><p>Item 2</p></div>
  <div class="col-lg-4 col-md-12"><p>Item 3</p></div>
</div>

</body>
</html>

I am trying to have it when it is in the area of 992px and 1199px that it has 2 columns on top and one below that spans the entire width. So that the top div one and two sides are aligned with the sides for div three.

I have no idea how to fix this. Any help would be appreciated.

2 Answers

Add a custom class to third div. This will allow a specific override in relation to custom-class and not a global override.

HTML

<div class="col-lg-4 col-md-12 custom-class"><p>Item 3</p></div>

CSS

@media (min-width: 992px) and (max-width: 1199px) {
    .col-lg-4.col-md-12.custom-class p{
    
        width: 95%; // modify the width so that it aligns to elements
        margin: 0 auto;
    
    }
}

In your code the p { width: 90% } gets in the way.

Remove that value and the p { margin-left }/p { margin-right } also and add p { margin: 1rem } (or that to a value you need).

Check my Codepen Code for you...

With this code there is no need to change any of the Media Queries.

Related