Ensure that the elements are properly arranged inside divs that have been stretched

My goal is to create divs that are all the same size, while aligning some content within each div differently due to varying lengths.

The objective is to keep the icon and text in a consistent position within all divs, but allow the divs to expand at the bottom to achieve uniformity in size.

Below is the code I am working with:

.servicescontainer {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  background-color: white;
  border-radius: 30px;
  padding: 20px;
  box-shadow: 3px 3px 20px #333;
  min-height: 240px;
}
.servicesicon {
  width: 50px;
  margin-left: auto;
    margin-right: auto;
  margin-top: 20px;
}
  
.servicestext {
  width: 100%;
  text-align: center;
  position: relative;
  padding-right: 10px;
}
<div class="servicescontainer">
    <div class="servicesicon">
         <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg">
</svg>
    </div>
    <div class="servicestext">
        <h4>
      Repairs
    </h4>
        <ul>
            <li>Custom Replacement Parts</li>
            <li>Hydraulic Cylinder Repair & Refurbish</li>
            <li>Heavy Equipment Repair & Modification</li>
        </ul>
    </div>
</div>

<div class="servicescontainer">
    <div class="servicesicon">
         <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg">
</svg>
    </div>
    <div class="servicestext">
        <h4>
      Welding & Fabrication
    </h4>
        <ul>
            <li>Certified Steel, Aluminum & Stainless Welding</li>
            <li>Structural Fabrication & Assembly</li>
            <li>Metal Forming & Cutting</li>
          <li>Onsite Portable Services</li>
        </ul>
    </div>
</div>

Despite attempts using position: relative and position: absolute, I have not been successful. Using min-height distorts the alignment of the text and h4 titles do not line up properly as desired.

A visual representation of the before and after I am aiming for can be seen here.

Answer №1

To start, envelop your servicescontainer within a div and assign it the class of flex-container

.flex-container{
  display:flex;
  align-items:strech;
  gap:10px;
 /* flex-wrap: wrap; */ 
}

Next, modify the flex-direction for .servicescontainer to be column

Set a fixed height for .servicesicon in the style

.flex-container{
display:flex;
align-items:strech;
gap:10px;
/* flex-wrap: wrap; */ 
}

.servicescontainer {
  display: flex;
  flex-direction: column;
  flex-wrap: no-wrap;
  align-items: flex-start;
  justify-content: start;
  background-color: white;
  border-radius: 30px;
  padding: 20px;
  box-shadow: 3px 3px 20px #333;
  min-height: 240px;
}
.servicesicon {
  width: 50px;
  margin-left: auto;
    margin-right: auto;
  margin-top: 20px;
  background:blue;
  height:50px;
  }
  
.servicestext {
  width: 100%;
  text-align: center;
  position: relative;
  padding-right: 10px;
}
<div class="flex-container">
<div class="servicescontainer">
    <div class="servicesicon">
         <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg">
</svg>
    </div>
    <div class="servicestext">
        <h4>
      Repairs
    </h4>
        <ul>
            <li>Custom Replacement Parts</li>
            <li>Hydraulic Cylinder Repair & Refurbish</li>
            <li>Heavy Equipment Repair & Modification</li>
        </ul>
    </div>
</div>

<div class="servicescontainer">
    <div class="servicesicon">
         <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg">
</svg>
    </div>
    <div class="servicestext">
        <h4>
      Welding & Fabrication
    </h4>
        <ul>
            <li>Certified Steel, Aluminum & Stainless Welding</li>
            <li>Structural Fabrication & Assembly</li>
            <li>Metal Forming & Cutting</li>
            <li>Certified Steel, Aluminum & Stainless Welding</li>
            <li>Structural Fabrication & Assembly</li>
            <li>Metal Forming & Cutting</li>
            <li>Certified Steel, Aluminum & Stainless Welding</li>
            <li>Structural Fabrication & Assembly</li>
            <li>Metal Forming & Cutting</li>
          <li>Onsite Portable Services</li>
        </ul>
    </div>
</div>
</div>

Answer №2

If you want to achieve this layout, follow these steps:

#container {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}

.box {
  border: 2px solid black;
  width: 25%;
  padding: 1%;
  margin: 1%;
} 
<div id="container">
  <div class="box">
    <h4>Animals</h4>
    <ul>
      <li>Aardvark</li>
      <li>Badger</li>
      <li>Cougar</li>
    </ul>
  </div>
  <div class="box">
    <h4>Fruit</h4>
    <ul>
      <li>Apricot</li>
      <li>Banana</li>
      <li>Cherry</li>
      <li>Date</li>
      <li>Elderberry</li>
      <li>Fig</li>
    </ul>
  </div>
  <div class="box">
    <h4>Trees</h4>
    <ul>
      <li>Sycamore</li>
    </ul>
  </div> 
  <div class="box">
    <h4>Fruit</h4>
    <ul>
      <li>Apricot</li>
      <li>Banana</li>
      <li>Cherry</li>
      <li>Date</li>
      <li>Elderberry</li>
      <li>Fig</li>
      <li>Grapefruit</li>
      <li>Hedgehog</li>
    </ul>
  </div>
  <div class="box">
    <h4>Trees</h4>
    <ul>
      <li>Sycamore</li>
    </ul>
  </div>   
  <div class="box">
    <h4>Animals</h4>
    <ul>
      <li>Aardvark</li>
      <li>Badger</li>
      <li>Cougar</li>
    </ul>
  </div>  
</div>

Answer №3

To enhance the appearance of both your divs, I grouped them within a container and utilized display: flex. This adjustment aligns with the image you referenced. To further refine the layout, you have the option to adjust padding/margins.

/* Modified Container styles */
container {
  display: flex;
  flex-direction: row;

.servicescontainer {
  background-color: white;
  border-radius: 30px;
  padding: 20px;
  box-shadow: 3px 3px 20px #333;
  min-height: 240px;
}
.servicesicon {
  width: 50px;
  margin-left: auto;
  margin-right: auto;
  margin-top: 20px;
}

.servicestext {
  width: 100%;
  text-align: center;
  position: relative;
  padding-right: 10px;
}
<container>
  <div class="servicescontainer">
    <div class="servicesicon">
      <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg">
    </svg>
    </div>
    <div class="servicestext">
      <h4>
        Repairs
      </h4>
      <ul>
        <li>Custom Replacement Parts</li>
        <li>Hydraulic Cylinder Repair & Refurbish</li>
        <li>Heavy Equipment Repair & Modification</li>
      </ul>
    </div>
  </div>
  
  <div class="servicescontainer">
    <div class="servicesicon">
      <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg">
    </svg>
    </div>
    <div class="servicestext">
      <h4>
        Welding & Fabrication
      </h4>
      <ul>
        <li>Certified Steel, Aluminum & Stainless Welding</li>
        <li>Structural Fabrication & Assembly</li>
        <li>Metal Forming & Cutting</li>
        <li>Onsite Portable Services</li>
      </ul>
    </div>
  </div>
</container>

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

Is there a way to include captions within a bootstrap carousel-item without compromising the responsiveness and alignment of the indicators and controls?

<div id="myUniqueCarousel" className="carousel slide" data-bs-ride="true"> <div className="unique-carousel-indicators"> <button type="button" data-bs-target="#myUniqueCarousel" data-bs-slide-to="0" className="active" aria-curre ...

Avoiding overlapping of div elements in a stacked div layout

I have a challenge with creating a vertical layout of stacked divs. Everything was going smoothly until I encountered the #resume div, which stubbornly stays hidden beneath the table-containing div above it. Despite trying various adjustments to float and ...

Expanding Iframes in Joomla K2

Sorry if this question has been asked before, but I'm really struggling here... Here is the URL where the issue is happening: I am trying to embed an iframe from one of my client's websites onto my own personal website. Currently, I have the i ...

How to create a stunning Bootstrap Jumbotron with a blurred background that doesn't affect the

I need help making my Jumbotron image blurry without affecting the text inside it! Below is the code from my index.html and style.css files. Any assistance would be greatly appreciated. body { background-image: url(bg1.png); background-repeat: repea ...

Tips for creating a sub-menu within a dropdown menu

I need some help adding a sub-menu to my drop-down function. I'm not very familiar with CSS, so I'm struggling to figure out how to do it. Ideally, I want the sub-menu to open to the right when the cursor hovers over it. Below is the CSS and HTML ...

Creating a shadow effect within an element: a step-by-step guide

I've been experimenting with creating an inner shadow effect on an image, but I can only seem to achieve an outer shadow. Just for clarification, .showSlide is a div element. .showSlide { display: block; width:100%; height:350px; } .showSlide img { ...

When the search is focused, I prefer for the expanding search box to overlay the menu section rather than pushing it aside, all without the use

I am working on a search box with a subtle animation: <input class="search" type="search" placeholder="Search"> To make it expand when focused, I used the following CSS: .search:focus { width: 225px; outline: none; } I also experimented w ...

Easy ways to align sprite images and text in the center

I am trying to utilize css sprites for my website. I have a basic image and some text that I would like to display together. My goal is to center the image on the page, and then vertically center the text next to it. As a newcomer to css, I am struggling t ...

What is the best way to ensure the logo is centered when the screen size reaches 750?

Looking to center the logo on a media screen size breakpoint? View the photo (Here): https://i.stack.imgur.com/UnB2F.png Check out my code below: .logo img { padding: 15px; width: 125px; } <nav> <ul class='nav-bar'> < ...

Create a circular shape using CSS that dynamically adjusts its size to match the width

Can you help me with a CSS challenge? I need to create circles around elements on a webpage, but my code is not working perfectly. The width of the circle is off and I can't seem to center it properly. The width does not match the content (it is alw ...

Tips on applying the "activate" class to a Bootstrap navbar in Angular 2 when implementing page anchor navigation

As I work on my single-page website using Angular 2 and Bootstrap 4, I have successfully implemented a fixed navbar component that remains at the top of the page. Utilizing anchor navigation (#id), the navbar allows smooth scrolling to different sections o ...

Is it possible to have a button within a table that, when clicked, opens a card overlaying the entire table?

I'm having an issue with a table and card setup. When I click the button in the table, the card that appears only covers part of the table. I want it to cover the entire table area based on the content inside the card. How can I make this happen? I&a ...

Tips for maintaining an open sub menu while hovering over a link

I'm currently working on a navigation menu using jQuery that includes categories, subcategories, and their subsequent subcategories. However, I am facing some issues with it not functioning as intended. To avoid cluttering this space with excessive HT ...

Tips on adjusting the size of a font icon using an inline element prior to the font being fully loaded

I'm facing an issue with embedding an icon font within text so that it wraps properly. Currently, the only way I can achieve this is by using &nbsp; between the text and the icon (i tag with font awesome). However, this causes a problem as the ico ...

encountered net::ERR_EMPTY_RESPONSE while attempting to locate a CSS file within an AngularJS directive

Every time my webpage attempts to access the css file from a directive, I encounter a net::ERR_EMPTY_RESPONSE. I have implemented door3's on-demand css feature, which allows for lazy loading of css files only when necessary. This feature works flawle ...

What methods can I use to visually distinguish external links from those on my website?

Can CSS be used to show users which links are external? ...

Please indicate the number of lines for the href within the span element

I'm struggling with formatting a <span> tag, specifically the .lastMessageLink class that contains an <a> element with the .lastMessageText class. The content within .lastMessageText can vary from just a few characters to a lengthy paragra ...

Bone structure template - optimizing list spacing with CSS

Currently, I am attempting to float my navigation bar further towards the left by at least 200px, closer to the end of the line visible below. However, every time I add a margin or padding, it causes the elements within the navigation bar to stack on top o ...

Disable Chrome's suggestions bar on your Android phone

I'm having trouble disabling spelling suggestions for an input box and everything I've tried so far hasn't worked. I've already used attributes like autocomplete="off", autocapitalize="off", and spellcheck="off" for the input field, bu ...

What is the best way to incorporate CSS into JavaScript code?

Here is the code I am working with: <script type = "text/javascript"> function pic1() { document.getElementById("img").src = "../images/images/1.png"; } function pic2() { document.getEl ...