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

Changing the color of a menu item in Bootstrap when a modal window is closed: A guide

I am implementing Twitter Bootstrap and attempting to launch a modal popup by clicking on a menu item. Below is the code snippet: <div class="navbar navbar-fixed-bottom"> <div class="navbar-inner"> <ul class="nav pull-right"> ...

What is the best way to retain selection while clicking on another item using jQuery?

There is a specific issue I am facing with text selection on the page. When I apply this code snippet, the selected text does not get de-selected even after clicking .container: jQuery('.container').on("mousedown", function(){ jQuery('. ...

The expected behavior of first-child is not impacting the initial element as anticipated

What is the reason behind the rule not impacting the first div containing the "update 1" text? .update div { width:100%; height:25%; border-top:1px dashed {color:background title}; padding: 5px; color:{color:links nav}; cursor:po ...

Using a diverse class for enhancing the PrimeVue dialog's maximizable feature

I'm currently working with the PrimeVue Dialog component. My goal now is to apply different styles depending on whether the dialog is maximized or not. Let's keep it simple by saying I want to change the text to bold or red when the dialog is max ...

The logo positioned on the left with menu links perfectly centered

Looking for Help with Navigation Layout Greetings. I am encountering some challenges while trying to code the navigation layout depicted in the image (linked above). My goal is to have the logo, which is an image, aligned on the left side and the menu lin ...

The functionality of the custom file upload button is experiencing issues on Microsoft Edge

I've been working on creating a unique custom image upload button that functions perfectly in Chrome, Firefox, and Opera based on my testing. However, I'm facing an issue where it doesn't work properly in Microsoft Edge. Feel free to check ...

Custom Jquery function is failing to position divs correctly within ajax-loaded content

I recently coded a custom function that efficiently positions absolute divs within a container by calculating top positions and heights: $.fn.gridB = function() { var o = $(this); //UPDATED from var o = $(this[0]); o.each(function() { var ...

A guide on monitoring SASS files in all subdirectories with an npm script

Is there a way to watch all sass directories and generate CSS files to the corresponding 'CSS' folder, including subdirectories? The current method involves listing each directory separately in the NPM script. "scripts": { "sas ...

Having trouble getting the vertical menu animation to work with jQuery

Essentially, I am facing an issue with a <nav> element that is supposed to expand from left to right upon mouseover. However, sometimes when quickly moving the cursor over and then out of the element, it expands without animation, which should not be ...

Identify support for the :first-child pseudo-class

Is there a way to determine with JavaScript whether the browser is compatible with the CSS :first-child selector? ...

What strategies can I implement to ensure my modal dialog box remains responsive? Adjusting the window size causes the modal box to malfunction and lose its structure

Whenever I adjust the size of the browser window, the elements inside the modal box become misaligned. HTML <div class='modal'> <div class='modal-content'> </div> </div> Below is the CSS for the modal ...

Angular 8 implementation of a responsive readonly input text field styled with Bootstrap 4

I want to make the input text read-only using Bootstrap. After some research on the Bootstrap website, I discovered that the form-control-plaintext class can be used for this purpose. <input type="text" readonly class="form-control-plaintext" id="stat ...

Locate the parent element using a unique child element, then interact with a different child element

Can you help me come up with the correct xpath selector for this specific element? The element only has a unique href. Is it possible to locate the element by searching for the text iphone X within the href="#">iphone X and also checking for its paren ...

When it comes to using brackets and HTML, I keep receiving an error message indicating that there is no index file

I'm having trouble with this code - it works fine in Code Academy, but I am new to HTML and trying to practice outside of the platform. Every time I try to live preview in Brackets, I get an error message saying "make sure there is an html file or tha ...

What exactly is the role of the @altfontfamily variable in Bootstrap?

Within the variables.less file, specifically in the typography section, you will find a variable named @altfontfamily. I am interested in utilizing the Alt Font Family but I am unsure of the process. Is there a specific class that needs to be called in or ...

Make Fomantic-UI (Angular-JS) sidebar scroll independently

Is there a way to make a sidebar scroll independently of the content it pushes? Currently, my page is structured like this: -------------------------- |[button] Header | -------------------------- |S | Main content | |i | ...

What are some creative ways to customize radio buttons using images?

I am looking to customize the appearance of my radio buttons by using images for both selected and unselected states. Here is the CSS code I have implemented: input[type="radio"] { background: url("https://example.com/path/to/unselec ...

When taking a vertical picture on my iPhone, my Vue component does not function properly

Having trouble with displaying recently uploaded images on a form. If the image is taken from a phone, it may have an exif property that browsers do not handle correctly, causing the picture to appear flipped or sideways. Upside down photo To fix this is ...

Bootstrap image with simplistic arrow indicators

I'm facing a minor issue that I need help solving. I want to have two simple arrows (one pointing left and one right) vertically aligned in the center of an image. Additionally, these arrows should resize proportionally when the screen size changes. ...

Turning off font ligatures in CSS (letter connections deactivation)

Typically, modern web browsers will automatically merge certain letter combinations, such as 'f' and 'i', into a single character known as a ligature. While this can enhance readability, it may not always align with a designer's pr ...