Tips for enlarging text without affecting the neighboring elements through the use of flexbox

I am currently working on designing a layout where clicking on "See More" will expand the text within one container while keeping the surrounding containers in place.

There are three containers, each containing two wrappers - a top wrapper with the title and a bottom wrapper with the image, text, and button. Since I do not know the length of the titles in advance, I have used justify-content: space-between to ensure that the boxes, text, and buttons align properly by making the bottom wrappers always line up.

The problem arises after clicking "See More," causing the bottom wrapper of each container to move down to accommodate the increased height.

     .main-container {
          display: flex;
          flex-direction: row;
        }
        .container {
          display: flex;
          flex-direction: column;
          justify-content: space-between;
        }
        .top-wrapper {
          display: flex;
          flex-direction: column;
          height: 100%;
        } 
        .bottom-wrapper {
          display: flex; 
          flex-direction: column; 
          justify-content: space-between;
        } 
    <div class="main-container">
      <div class="container">
          <div class="top-wrapper">
              <div class="title">
                    TITLE 1 IS LONG THAT IT GOES TO NEXT LINE
              </div>
          </div>
          <div class="bottom-wrapper">
              <div class="image-text-wrapper">
                  <div class="image-container">
                      <img class="image" src="https://dummyimage.com/200x200/000/000">
                  </div>
                  <div class=“text” id="text">
                   {{ text }}
                   //See More code
                  </div>
              </div>
              <button>
                BUTTON 1
              </button>
          </div>
      </div>
      <div class="container">
         //second container code
      <div>
      <div class="container">
         //third container code
      <div>
    </div>
   

Do you think using a table would be more suitable for this situation, or is there a simple CSS solution available?

You can access the complete code here: Plunkr

Answer №1

Here are some suggestions to tweak your layout:

.container {
  align-self: flex-start;
}

By using the align-self property in the container class, you can customize how your flex items are aligned.

Also, consider adding the following to the .title class:

.title {
  min-height: 50px
}

You might need to experiment with this setting to ensure there is enough space between the image and title elements.

Note: The CSS code provided here may differ slightly from what was seen in the Plunkr link, especially regarding the presence of display: grid; in the .container class. However, these adjustments should still be effective.

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

Google Maps Shifting Focus

I'm currently working on an AngularJS app that involves multiple locations, and the goal is for users to click on a location which then redirects them to the specific spot on Google Maps. However, I've encountered an issue when trying to relocate ...

What is the best way to ensure my footer remains at the bottom of the page even when scrolled?

I'm struggling to get my footer to stay at the bottom of a page that requires scrolling. The code I have only seems to work on pages without scrolling, causing the footer to display in the middle of the page instead of at the bottom where it belongs. ...

Set the CSS table to have a width of 100% and ensure that the table data cells have hidden

My table has a 100% width, and some of the td elements have overflow hidden. I want to make their text appear as ellipsis when it's too long. I can achieve this with fixed td sizes, but I need them to be relative to the content. This question was fi ...

Script for Grunt build that analyzes an XML document to identify the files that need to be duplicated

copy: { build: { cwd: 'app', src: ['**', '!**/vendors/**', '!**src/js/*.js',], dest: 'dist', expand: true } } When utilizing Grunt build scripts to create a distribution folder for the ...

How to locate the adjacent sibling element of a given XPath from its parent node

I am currently working on correctly identifying the xpath for this specific HTML layout. The only information I have is the name of the first element, which is an input with the id "urn...". My goal is to locate the parent element of the input (a div), the ...

Triggering a d3.js event when two radio buttons are both selected

I am currently working with a sample code that displays data based on the selected radio button: http://bl.ocks.org/juan-cb/1984c7f2b446fffeedde To enhance this functionality, I decided to add two sets of radio buttons instead of one by including the fol ...

Issue with Javascript redirect not working following form submission in combination with Asp Classic

After countless hours of research and experimentation, I find myself at a standstill. My web page is coded extensively, so I'll do my best to provide a concise summary. The core elements of my ASP CLASSIC page for creating tickets via a form are as f ...

How can I add page transitions to my simple HTML website?

Working on an internal website project for my office using vue.js has been a rewarding experience. I appreciate how easily it allows me to manage multiple pages with dynamic content and seamless transitions. Unfortunately, my IT department is hesitating to ...

Scrolling to the complete height of a div using scrollTop

Experience an automated scroll to the bottom of the div, followed by a smooth upward motion over 5 seconds, all while looping seamlessly. A small issue arises where the code only recognizes the standard height set for the div, not its actual scrollable he ...

Is it possible to perform a CSS flip animation without delay?

Trying to implement David Walsh's CSS flip effect for an image that should change to another without requiring a mouseover. Is there a way to trigger it automatically, maybe in 3 seconds? I'm new to this so any help would be greatly appreciated! ...

Ways to incorporate services into functions within Angularjs

I'm struggling to grasp the concept of dependency injection in AngularJS. Currently, I am attempting to inject $interpolate and $eval into my controller. However, after consulting the documentation, I realized that my lack of foundational knowledge i ...

Excessive content in Bootstrap row extends outside browser window dimensions

I'm having an issue with the Bootsrtap row overflowing past the desired width, causing a scrollable area on the browser. Does anyone know how to fix this? You can see the site here: www.testing.cpukeychains.comhttps://i.sstatic.net/cDcot.png ...

Retrieve the id of an element and a standard element using JavaScript

I have a CSS selector #menu li {background-color: red;}. I'm trying to retrieve its properties using JavaScript. It's crucial for me to access both the #menu and li elements separately as they have distinct attributes. Unfortunately, methods lik ...

exclude the outer border from the last row of the table

Is it possible to create a table with only an outer border and exclude the bottom row, so that the bottom border of the second last row gives the appearance of being the final row? I am limited to using CSS as this is on Wordpress and I cannot make changes ...

Move one div to reveal another underneath

I currently have a div housing various products that can be added by clicking the add link. Whenever the add link is clicked, an information message appears briefly before fading out after 4 seconds. This message shows up at the top of the childbox-conten ...

A mysterious underscore suddenly materializes within Font Awesome icons when used in HTML

Currently, I'm working on the footer section of a webpage using HTML and Bootstrap 5.3.0. I encountered an issue where an underscore appears next to the icons when I add them. I suspect that this is due to the white spaces between the elements, which ...

What is the best way to implement a link that triggers a chat box in HTML?

Hello, I need some assistance with an HTML project. I am attempting to create a hyperlink that displays as a group of words, and when clicked, triggers a pop-up message. Additionally, I would like to have control over the content displayed in the pop-up ...

Adding a border in jQuery or Javascript to highlight empty form fields

After making the decision to dive into the world of Javascript, I've been dedicated to perfecting a script that will encase empty elements with a border right before the user submits a form. My ultimate goal is to implement live validation in the form ...

Issue with Flask app's template rendering when trying to search for a book

Currently, I am working on a Flask web application that has the functionality for users to search for books and view detailed information about them. However, an obstacle I am encountering is that the form does not get sent to the specified URL. Below is ...

What is the process for integrating CSS-styled text into CKEditor?

Currently, I am developing plugins that are designed to incorporate various elements like images and tables into the editor. My objective is to be able to view these elements in their final visual form within the editor itself. To achieve this, I plan on a ...