Achieving equal heights for div boxes while aligning list items inside

I have 8 green boxes on my site, each containing an image and either 3 or 4 list items with text only. The issue I'm facing is that the boxes are not of equal height due to two reasons: (1) One box may have an extra list item pushing the rest down, or (2) even when the number of list items is the same in a row, the heights still differ.

The main goal is to make sure all boxes in a row have uniform height regardless of the content inside.

You can check out the demo site here.

Here's a screenshot of the top row of boxes with a blue box highlighting the discrepancies:

  • Issue 1: Boxes #1 and #2 have different heights due to an additional list item in box #2.

  • Issue 2: Boxes #1 and #3 contain similar text but their heights are slightly off.

Key requirements include:

  1. Having red text placed above the respective images, overlaying them.
  2. Aligning all list items vertically within the boxes.

Desired look with red text changed to green for better visibility:

Here is the HTML structure of a box:

    <a href="http:adfadfafl">

             <div class="block personal fl">

                <!-- CONTENT -->
                <div class="content">
                    <p class="price">
    <p class="vignette" style="background-image:url(http://jasoncampbell.net46.net/public/2.jpg)"></p>
                    </p>

                </div>
                <!-- /CONTENT -->
                <!-- FEATURES -->
                <ul class="features">
                <li class="redbox">MAKE THIS OVER IMAGE</li>
                <li class="titlebox">ldfadfadf </li>
                <li>ad ffadfa dfad f</li>
                <li>adf adfad </li>
                  </ul>

            </div>

      </a>

And here's the associated CSS:

Green Box Styling:

.block{
    width: 30%;    
    margin: 0 15px;
    margin-bottom: 30px;
    min-height: 700px;
    max-height: 700px;
    overflow: hidden;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;    
/*    border: 1px solid red;*/
}

Red Text Styling:

.redbox{margin-top: -2%; margin-bottom:-5%; color:red; font-weight:bold;}

Title Line Styling:

.titlebox{margin-bottom:20%;}

List Item Styling:

.features li{
    padding:25px 0;
    width: 100%;
}

Container for List Items:

.features{
    list-style-type: none;    
    background: #A1F997;
    text-align: center;
    color: #000000;
    padding:40px 12%;
    font-size: 32px;
    font-family: Garamond;
}

If you'd like to see how it looks, visit the demo site here. Hoping to find a solution that works across IE7+. Thank you!

Answer №1

When searching for lines of blocks with the same height but allowing different heights from one line to another, there are a few CSS tricks that can be employed. One option is using display:flex, or alternatively, a combination of inline-block and box-shadow. Another approach involves using absolute pseudo-elements:

For inline-block:

body>div {
  width:80%;
  margin:auto;
  overflow:hidden;
  text-align:center;
}
a {
  display:inline-block;
  vertical-align:top;
  margin:0 0.5em 0;
  width:25%;
  background:lightgreen;
  box-shadow: 0 50px 0 lightgreen , 0 100px lightgreen  , 0 150px lightgreen ;
  border-top:1em solid white;
  padding:0.5em;}
<div>
  <a>
    <div> 
      <p>line</p>
      <p>line</p>
    </div>
  </a>
  ...
</div>

Alternatively, using flex:

body>div {
  display:flex;
  flex-wrap:wrap;
  width:80%;
  margin:auto;
  justify-content:center;
}
a {
  margin:0.5em 1%;
  width:27%;
  background:lightgreen;
  padding:0.5em;}
<div>
  <a>
    <div> 
      <p>line</p>
      <p>line</p>
    </div>
  </a>
  ...
</div>

These methods offer possibilities through CSS. If all boxes must have the same height (the height of the tallest), then JavaScript will be required.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Strategies for making a child div fade out when the parent div is hovered over

I have a div with the class name ordershape and inside it, there is another div called fad-res. My goal is to display the corresponding fad-res when I hover over a specific ordershape, while hiding the other divs. <div class="ordershape"> & ...

What is the best way to design an element in HTML/CSS with a curved semicircle border at the top?

I'm looking to design an HTML/CSS element that features a semicircle at the top-middle with a border. Inside this semicircle, I want to place a smaller circle containing a single character (similar to the X in the provided image). Additionally, there ...

Various Overlay Shapes in Bootstrap Using CSS

So I'm in the process of styling my landing page with CSS based on a design I have in Figma. The page is using Bootstrap 5 as its framework, though I'm not sure if that detail matters in this case. I believe it's definitely doable, but I&apo ...

Setting the z-index of the parent element causes issues with overlapping

When adjusting the z-index property of the parent element, I am experiencing issues with overlapping elements. Below is the HTML and CSS code: .black_gradient{ width:100%; height:100%; background: linear-gradient(0deg,rgb(75, 75, 75) 20%, rgba(75,75 ...

"Any tips on maintaining the blue color of my dropdown link when it is selected as active

I'm struggling to keep the bootstrap accordion dropdown link blue when it's active. I've tried different methods but none seem to work. What am I missing? Here's my code: <div class="visible-sm visible-xs" id="accordion" role="t ...

What is the best way to eliminate the left margin entirely in CSS?

I am attempting to create an image view that fully covers the window, without any margins. I have tried various solutions such as setting the body margin and padding to 0, but they do not seem to work. body { margin: 0px; padding: 0px; } or *, html { ...

Wiki experiencing issues with NodeJS HttpGet functionality

Goal Retrieve the HTML content of a Wiki Page. Introduction In an attempt to fetch the HTML of a Wiki page () for data parsing purposes, I am utilizing NodeJS and its HTTP Request methods. Code Snippet Below is the simple code snippet that accesses th ...

The sequence of HTML5 DragDrop Enter and Leave events occur consecutively

I am encountering a problem with a simple drag & drop effect where the class name is changed when the drag enters or leaves, resulting in continuous entering and leaving. Take a look at this basic HTML code: <div class="box"> <div cla ...

When the label is clicked, the radio button does not have a selected value

I am experiencing some strange behavior with a radio button, as shown in the attached GIF. Whenever I click on the label, the selected value disappears and the radio buttons become unchecked. I have been unable to identify the cause of this issue. I am ...

Automatically resizing a multi-part CSS background based on content dimensions

My current CSS project has hit a snag that I can't seem to solve: There is a box on the left side of the site that contains three images - a top image, an optional and stretched middle image, and a bottom image. I want this left box to automatically ...

Indent the text within a span element that is displayed as an inline block

I am in search of a solution using only CSS for the following issue. Take into account the HTML below: <p> <span>Some text</span> <span>Some text</span> </p> Both <span> elements are set as inline-block. ...

Guide to showing video files stored in a folder on a PHP template

I am working on a project similar to the functionality of this website: As you can see, when you click on any video, it takes you to the same page with the video playing being the only difference. I want to implement this feature on my website as well. ...

How to position div in the middle of Electron/VUE application's screen?

I am struggling to center a container div on the screen. The technology stack I am using includes Electron, VUE, HTML, and CSS. Here is the code snippet I have attempted: <template > <div class="login background" style="height:100%" > ...

Introducing a variety of sub-menu fonts within an elegantly designed jQuery vertical accordion menu

I am struggling to achieve different font sizes, colors, and weights for top and sub-menu level links in my simple jQuery vertical accordion. Despite changing the CSS, I can't seem to get it right. What am I missing? Is there an easy way to accomplish ...

The index of the list has exceeded the allowable range

In my code, I am encountering an error related to the list pos_coordinates and updatePos_coordinates. I need to compare object values at index 8, 9, 12, and 13, but consistently face the same issue. Can anyone help me resolve this problem? screen_widt ...

The issue of the container div tag not being able to achieve 100% height and width

My web page layout has a CSS issue where I am unable to achieve 100% height in Firefox and Chrome, unlike in Internet Explorer 9. I have tried multiple examples but encountered the same problem. You can view the code on http://jsfiddle.net/cwkzq/3/ where i ...

Is it possible to determine which child element is currently in view within a scrollable parent div?

In an attempt to replicate a "current page" feature using divs, similar to a PDF reader. document.addEventListener("DOMContentLoaded", function(event) { var container = document.getElementById("container"); container.onscroll = function() { let ...

Stop automatic downloading of files and instead, visualize the file within a PHP form using an iframe

Can anyone assist me with displaying a doc, docx, or pdf file in PHP code? Below is the code I have been trying: <iframe src="http://localhost/sample/sampl1/resource/upload/resumes/1406263145_resume sample.docx" style="width:820px; height:700px;" frame ...

Can IE Conditional Comments have a negative impact on page speed?

Debates between "CSS hacks" and "Conditional Comments" have become a regular occurrence for me lately, so I wanted to hear the thoughts of the Stack Overflow community on this topic. <!--[if IE]> <link type="text/css" rel="stylesheet" href="ie-s ...

Position the typography component to the right side

Is there a way to align two typography components on the same line, with one aligned to the left and the other to the right? I'm currently using this code but the components are aligned next to each other on the left side. const customStyles = makeSt ...