0

I am using nice & clean CSS for responsive grid using this axample https://tympanus.net/codrops/2013/04/17/responsive-full-width-grid/

This very good for showing gallery image and fixed with title, But when i use it with title which vary in length then it breaks the design. example below.

http://codepen.io/anon/pen/ObqJOg

.cbp-rfgrid {
    margin: 35px 0 0 0;
    padding: 0;
    list-style: none;
    position: relative;
    width: 100%;
}

.cbp-rfgrid li {
    position: relative;
    float: left;
    overflow: hidden;
    width: 16.6666667%; /* Fallback */
    width: -webkit-calc(100% / 6);
    width: calc(100% / 6);
}

.cbp-rfgrid li a,
.cbp-rfgrid li a img {
    display: block;
    width: 100%;
    cursor: pointer;
}

.cbp-rfgrid li a img {
    max-width: 100%;
}

/* Flexbox is used for centering the heading */
.cbp-rfgrid li a div {
    left: 20px;
    top: 20px;
    right: 20px;
    bottom: 20px;
    background: rgba(71,163,218,0.2);

    -webkit-align-items: center;
    -moz-align-items: center;
    -ms-align-items: center;
    align-items: center;
    text-align: center;
    opacity: 1;
  position:relative;
  background-color:red;
  padding:5px;
}

.cbp-rfgrid li a:hover div {
    opacity: 1;
}

.cbp-rfgrid li a div h3 {
    width: 100%;
    color: #fff;
    text-transform: uppercase;
    font-size: 1.4em;
    letter-spacing: 2px;
    padding: 0 10px;
}

/* Example for media query: change number of items per row */

@media screen and (max-width: 1190px) {
    .cbp-rfgrid li {
        width: 20%; /* Fallback */
        width: -webkit-calc(100% / 5);
        width: calc(100% / 5);
    }
}

@media screen and (max-width: 945px) {
    .cbp-rfgrid li {
        width: 25%; /* Fallback */
        width: -webkit-calc(100% / 4);
        width: calc(100% / 4);
    }
}

@media screen and (max-width: 660px) {
    .cbp-rfgrid li {
        width: 33.3333333%; /* Fallback */
        width: -webkit-calc(100% / 3);
        width: calc(100% / 3);
    }
}

@media screen and (max-width: 660px) {
    .cbp-rfgrid li {
        width: 33.3333333%; /* Fallback */
        width: -webkit-calc(100% / 3);
        width: calc(100% / 3);
    }
}

@media screen and (max-width: 400px) {
    .cbp-rfgrid li {
        width: 50%; /* Fallback */
        width: -webkit-calc(100% / 2);
        width: calc(100% / 2);
    }
}

@media screen and (max-width: 300px) {
    .cbp-rfgrid li {
        width: 100%;
    }
}

How can align row of columns so design wont break

Learning
  • 19,469
  • 39
  • 180
  • 373

6 Answers6

0

We can use the css attribute for the parent of the grids, display: flex; How do I keep two divs that are side by side the same height?

ul.cbp-rfgrid {
  display: flex;
}
Community
  • 1
  • 1
Siddaram H
  • 1,126
  • 12
  • 17
0

There seem to be some styles that aren't doing anything, or are getting in the way.

I would simplify your CSS...

.cbp-rfgrid li a div {
  background: rgba(71,163,218,0.2);
  opacity: 1;
  background-color: red;
  padding: 5px;
  margin: 5px;
}

.cbp-rfgrid li a div h3 {
  width: 80%;
  margin-left: auto;
  margin-right: auto;
  text-align: center;
  color: #fff;
  text-transform: uppercase;
  font-size: 1.4em;
  letter-spacing: 2px;
  padding: 0 10px;
}

DEMO

sol
  • 22,311
  • 6
  • 42
  • 59
0

Just use position for this div. and you can change the offset of the div to put it somewhere you want.

.cbp-rfgrid li a div {
    left: 20px;
    right: 20px;
    bottom: 0;
    background: rgba(71,163,218,0.2);
    -webkit-align-items: center;
    -moz-align-items: center;
    -ms-align-items: center;
    align-items: center;
    text-align: center;
    opacity: 1;
    position: absolute;
    background-color: red;
    padding: 5px;
}

and add relative for this

.cbp-rfgrid li a {
    display: block;
    width: 100%;
    cursor: pointer;
    position: relative;
}
Yonas Hailu
  • 853
  • 7
  • 20
0

You need to replace float with some other way. Here are 2 possible variants:

Method #01:

Use css3 flexbox:

  .cbp-rfgrid {
    /* Following properties should be added on parent element */
    flex-wrap: wrap;
    display: flex;
  }

.cbp-rfgrid {
  margin: 35px 0 0 0;
  padding: 0;
  list-style: none;
  position: relative;
  flex-wrap: wrap;
  display: flex;
}

.cbp-rfgrid li {
  position: relative;
  float: left;
  overflow: hidden;
  width: 16.6666667%; /* Fallback */
  width: -webkit-calc(100% / 6);
  width: calc(100% / 6);
}

.cbp-rfgrid li a,
.cbp-rfgrid li a img {
  display: block;
  width: 100%;
  cursor: pointer;
}

.cbp-rfgrid li a img {
  max-width: 100%;
}

/* Flexbox is used for centering the heading */
.cbp-rfgrid li a div {
  background: rgba(71,163,218,0.2);
  -webkit-align-items: center;
  -moz-align-items: center;
  -ms-align-items: center;
  align-items: center;
  text-align: center;
  opacity: 1;
  position:relative;
  background-color:red;
  padding: 5px;
  margin: 0 10px;
}

.cbp-rfgrid li a:hover div {
  opacity: 1;
}

.cbp-rfgrid li a div h3 {
  color: #fff;
  text-transform: uppercase;
  font-size: 1.4em;
  letter-spacing: 2px;
  padding: 0 10px;
}

/* Example for media query: change number of items per row */

@media screen and (max-width: 1190px) {
  .cbp-rfgrid li {
    width: 20%; /* Fallback */
    width: -webkit-calc(100% / 5);
    width: calc(100% / 5);
  }
}

@media screen and (max-width: 945px) {
  .cbp-rfgrid li {
    width: 25%; /* Fallback */
    width: -webkit-calc(100% / 4);
    width: calc(100% / 4);
  }
}

@media screen and (max-width: 660px) {
  .cbp-rfgrid li {
    width: 33.3333333%; /* Fallback */
    width: -webkit-calc(100% / 3);
    width: calc(100% / 3);
  }
}

@media screen and (max-width: 660px) {
  .cbp-rfgrid li {
    width: 33.3333333%; /* Fallback */
    width: -webkit-calc(100% / 3);
    width: calc(100% / 3);
  }
}

@media screen and (max-width: 400px) {
  .cbp-rfgrid li {
    width: 50%; /* Fallback */
    width: -webkit-calc(100% / 2);
    width: calc(100% / 2);
  }
}

@media screen and (max-width: 300px) {
  .cbp-rfgrid li {
    width: 100%;
  }
}
<ul class="cbp-rfgrid">
  <li>
    <a href="#"><img src="https://tympanus.net/Blueprints/ResponsiveFullWidthGrid/images/cat.jpg" />
      <div>
        <h3>Felis catus</h3></div>
    </a>
  </li>
  <li>
    <a href="#"><img src="https://tympanus.net/Blueprints/ResponsiveFullWidthGrid/images/cat.jpg" />
      <div>
        <h3>This is the long title</h3></div>
    </a>
  </li>
  <li>
    <a href="#"><img src="https://tympanus.net/Blueprints/ResponsiveFullWidthGrid/images/cat.jpg" />
      <div>
        <h3>Felis catus</h3></div>
    </a>
  </li>
  <li>
    <a href="#"><img src="https://tympanus.net/Blueprints/ResponsiveFullWidthGrid/images/cat.jpg" />
      <div>
        <h3>Felis catus</h3></div>
    </a>
  </li>
  <li>
    <a href="#"><img src="https://tympanus.net/Blueprints/ResponsiveFullWidthGrid/images/cat.jpg" />
      <div>
        <h3>Felis catus</h3></div>
    </a>
  </li>
  <li>
    <a href="#"><img src="https://tympanus.net/Blueprints/ResponsiveFullWidthGrid/images/cat.jpg" />
      <div>
        <h3>Felis catus</h3></div>
    </a>
  </li>
  <li>
    <a href="#"><img src="https://tympanus.net/Blueprints/ResponsiveFullWidthGrid/images/cat.jpg" />
      <div>
        <h3>Felis catus</h3></div>
    </a>
  </li>
  <li>
    <a href="#"><img src="https://tympanus.net/Blueprints/ResponsiveFullWidthGrid/images/cat.jpg" />
      <div>
        <h3>Felis catus</h3></div>
    </a>
  </li>
  <!-- ... -->
</ul>

Method #01:

Use display: inline-block instead of float:

.cbp-rfgrid {
  /* Following properties will remove the extra spaced created by display: inline-block */
  letter-spacing: -4px;
  font-size: 0; 
}
.cbp-rfgrid li {
  display: inline-block;
  vertical-align: top;

  /* Overriding properties to the normal values */
  letter-spacing: 0;
  font-size: 14px;
}

.cbp-rfgrid {
  margin: 35px 0 0 0;
  padding: 0;
  list-style: none;
  position: relative;
  letter-spacing: 0;
  font-size: 0;
}

.cbp-rfgrid li {
  display: inline-block;
  vertical-align: top;
  position: relative;
  letter-spacing: 0;
  font-size: 14px;
  overflow: hidden;
  width: 16.6666667%; /* Fallback */
  width: -webkit-calc(100% / 6);
  width: calc(100% / 6);
}

.cbp-rfgrid li a,
.cbp-rfgrid li a img {
  display: block;
  width: 100%;
  cursor: pointer;
}

.cbp-rfgrid li a img {
  max-width: 100%;
}

/* Flexbox is used for centering the heading */
.cbp-rfgrid li a div {
  background: rgba(71,163,218,0.2);
  -webkit-align-items: center;
  -moz-align-items: center;
  -ms-align-items: center;
  align-items: center;
  text-align: center;
  opacity: 1;
  position:relative;
  background-color:red;
  padding: 5px;
  margin: 0 10px;
}

.cbp-rfgrid li a:hover div {
  opacity: 1;
}

.cbp-rfgrid li a div h3 {
  color: #fff;
  text-transform: uppercase;
  font-size: 1.4em;
  letter-spacing: 2px;
  padding: 0 10px;
}

/* Example for media query: change number of items per row */

@media screen and (max-width: 1190px) {
  .cbp-rfgrid li {
    width: 20%; /* Fallback */
    width: -webkit-calc(100% / 5);
    width: calc(100% / 5);
  }
}

@media screen and (max-width: 945px) {
  .cbp-rfgrid li {
    width: 25%; /* Fallback */
    width: -webkit-calc(100% / 4);
    width: calc(100% / 4);
  }
}

@media screen and (max-width: 660px) {
  .cbp-rfgrid li {
    width: 33.3333333%; /* Fallback */
    width: -webkit-calc(100% / 3);
    width: calc(100% / 3);
  }
}

@media screen and (max-width: 660px) {
  .cbp-rfgrid li {
    width: 33.3333333%; /* Fallback */
    width: -webkit-calc(100% / 3);
    width: calc(100% / 3);
  }
}

@media screen and (max-width: 400px) {
  .cbp-rfgrid li {
    width: 50%; /* Fallback */
    width: -webkit-calc(100% / 2);
    width: calc(100% / 2);
  }
}

@media screen and (max-width: 300px) {
  .cbp-rfgrid li {
    width: 100%;
  }
}
<ul class="cbp-rfgrid">
  <li>
    <a href="#"><img src="https://tympanus.net/Blueprints/ResponsiveFullWidthGrid/images/cat.jpg" />
      <div>
        <h3>Felis catus</h3></div>
    </a>
  </li>
  <li>
    <a href="#"><img src="https://tympanus.net/Blueprints/ResponsiveFullWidthGrid/images/cat.jpg" />
      <div>
        <h3>This is the long title</h3></div>
    </a>
  </li>
  <li>
    <a href="#"><img src="https://tympanus.net/Blueprints/ResponsiveFullWidthGrid/images/cat.jpg" />
      <div>
        <h3>Felis catus</h3></div>
    </a>
  </li>
  <li>
    <a href="#"><img src="https://tympanus.net/Blueprints/ResponsiveFullWidthGrid/images/cat.jpg" />
      <div>
        <h3>Felis catus</h3></div>
    </a>
  </li>
  <li>
    <a href="#"><img src="https://tympanus.net/Blueprints/ResponsiveFullWidthGrid/images/cat.jpg" />
      <div>
        <h3>Felis catus</h3></div>
    </a>
  </li>
  <li>
    <a href="#"><img src="https://tympanus.net/Blueprints/ResponsiveFullWidthGrid/images/cat.jpg" />
      <div>
        <h3>Felis catus</h3></div>
    </a>
  </li>
  <li>
    <a href="#"><img src="https://tympanus.net/Blueprints/ResponsiveFullWidthGrid/images/cat.jpg" />
      <div>
        <h3>Felis catus</h3></div>
    </a>
  </li>
  <li>
    <a href="#"><img src="https://tympanus.net/Blueprints/ResponsiveFullWidthGrid/images/cat.jpg" />
      <div>
        <h3>Felis catus</h3></div>
    </a>
  </li>
  <!-- ... -->
</ul>
Mohammad Usman
  • 37,952
  • 20
  • 92
  • 95
0

I think a good, general solution needs to accommodate titles of any length. Here's a solution which uses CSS to truncate the title and add an ellipsis if it doesn't fit the space:
http://codepen.io/panchroma/pen/WomEeK

The code code I've edited is

.cbp-rfgrid li a div h3 {
  width: 95%;  /* I've lowered this from 100% to make room for the ellipsis */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
David Taiaroa
  • 25,157
  • 7
  • 62
  • 50
  • This wont work for me as i have multiple title on the page, Name, designation, Company and either f them can be long & cant be cut. for me solution was with jQuery i find teh height of the highest div and apply the same height to all div's – Learning Dec 21 '16 at 08:51
0

This solution is not CSS or HTML based but rather i am using jQuery as an alternative

window.onload = function () {
    var heights = $(".bod-title-w").map(function ()
    {
        return $(this).height();
    }).get(),

    maxHeight = Math.max.apply(null, heights);
   // alert(maxHeight);
    $(".bod-title-w").css("min-height", maxHeight+15);
    setTimeout(function () {
      //  $(".bod-title-w").css("min-height", maxHeight);
    }, 1000);
};

I find div with maximum height & assign same to all divs or wrapper

Learning
  • 19,469
  • 39
  • 180
  • 373