Design the spans to have equal heights that adjust dynamically based on the content entered

I'm facing a challenge that I've been trying to resolve using just CSS, but I've hit a roadblock.

The issue at hand involves aligning multiple spans next to each other and making them equal in height. The height is not fixed and depends on the amount of text entered by the user in the description span.

Here's a visual representation of what I'm aiming for:

Below is the code snippet I am currently working with:

<table style="width: 100%;">
    <tr>
        <td>
            <span id="id_span_wrapper">
                <span id="id_sapn_label" style="background-color: #000; width: 20%;">Description</span>
                    <span id="id_span_description" style="background-color: #fff; width: 80%;>
                        this text can be between 1 and 5,000 characters
                    </span>
            </span>
        </td>
    </tr>
</table>

Answer №1

Try using the CSS property display: table

*{
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}

.table{
    display: table;
    width: 100%;
    border-spacing: 10px;
    border: 3px solid #000;
}
.table-row{
    display: table-row;
    height: 50px;
}
.table-cell{
    display: table-cell;
    vertical-align: top;
    padding: 15px;
}
.table-cell-left{
    background: #000;
    color: #fff;    
    width: 30%;
}
.table-cell-right{
    border: 2px solid #000;    
}
<div class="table">
    <div class="table-row">
        <div class="table-cell table-cell-left">Description</div>
        <div class="table-cell table-cell-right">This is just one line of text</div>
    </div>
    <div class="table-row">
        <div class="table-cell table-cell-left">Description</div>
        <div class="table-cell table-cell-right">This is just one line of textThis is just one line of textThis is just one line of textThis is just one line of textThis is just one line of textThis is just one line of textThis is just one line of textThis is just one line of text</div>
    </div>
</div>

Answer №2

Your table container is improperly structured: tables should only be utilized for tabular data.

However, the information within the cell appears to be tabular in nature. In this case, you can apply

table {
  border-spacing: 10px;
}
th {
  background: #000;
  color: #fff;
  font-weight: normal;
  vertical-align: top;
}
table, td, th {
  border: 3px solid #000;
}
<table>
  <tr>
    <th>Description</th>
    <td>This is just one line of text</td>
  </tr>
  <tr>
    <th>Description</th>
    <td>This content can range from 1 to 5,000 characters, varying in height accordingly. This content can range from 1 to 5,000 characters, varying in height accordingly. This content can range from 1 to 5,000 characters, varying in height accordingly. This content can range from 1 to 5,000 characters, varying in height accordingly.</td>
  </tr>
</table>

Answer №3

If you take a look at this not-so-pretty js code here: https://jsfiddle.net/hL8ryuw0/4/ , you will see that you can achieve the desired effect without relying on a table and with just a few lines of css.

.container{
    display: flex;
    align-items: stretch;
}

All you need to do is wrap everything in a container, set the display property to flex, and align items using "stretch".

Each item within the container will automatically adjust its size to match the container, ensuring that the largest element within it determines the overall size.

Answer №4

If you're adamant about using tables, here's the way to go about it.

http://jsfiddle.net/cos9dm55/

table {
  width: 100%;
}

table td {
  vertical-align: top;
  border: 2px solid #333;
  padding: 10px;
}

table td:first-child {
  width: 30%;
}

.background-dark {
  color: #fff;
  background: #333;
}


<table>
  <tr>
    <td class="background-dark">Description</td>
    <td>Short Answer</td>
  </tr>
  <tr>
    <td class="background-dark">Description</td>
    <td>Long Answer. Gumbo beet greens corn soko endive gumbo gourd. Parsley shallot courgette tatsoi pea sprouts fava bean collard greens dandelion okra wakame tomato. Dandelion cucumber earthnut pea peanut soko zucchini. Gumbo beet greens corn soko endive gumbo gourd. Parsley shallot courgette tatsoi pea sprouts fava bean collard greens dandelion okra wakame tomato. Dandelion cucumber earthnut pea peanut soko zucchini.</td>
  </tr>
</table>

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

What specific width range would be best for my needs?

I used to have the default font style of Myriad Pro Light and a padding setting for my main menu on my website as follows: .menu > li > a { padding: 17px 15px 15px 15px; } Recently, I changed the default font style to Montserrat. However, this chang ...

Every time a new message is sent or received, I am automatically brought back to the top of the screen on the

I'm currently working on integrating a chat feature into my Angular Firestore and Firebase app. Everything seems to be functioning well, except for one issue - whenever a new message is sent or received, the screen automatically scrolls up and gets st ...

Creating a rotating wheel using JavaScript that is activated by a key press event

I need some help with implementing a keystroke event in this code so that the spinning wheel can start based on a key press, like the spacebar. Any suggestions on how to achieve this? I have found an event code for keystrokes in JavaScript: document.body. ...

Unlock the power to toggle dynamic elements with jQuery

I'm currently using jQuery to enable and disable input elements, but I'm having trouble doing so for similar elements with the same class. Here is the HTML code: <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">< ...

What causes these images to stack on top of one another rather than align in rows? [HTML][CSS][Bootstrap]

I've implemented Bootstrap's grid system to showcase two rows, each containing two images. Here is the code: <section class="container"> <div class="row"> <figure class="column-sm-6"> <p>floor pl ...

Is there a way to consistently monitor the visible image's height?

I am facing an issue with a slider of images where I need the height of the slider to always match the height of the currently visible image within the slider. I have tried implementing code that automatically detects the height of the image within the sl ...

designing a button layout with bootstrap framework

I am attempting to position a "Redigera" button after the "Avsluta" button <div class="row"> <div class="col-md-4"> </div> <div class="col-md-4"></div> <div class="col-md-4"> <button class=" ...

Element not found: {"method":"xpath","selector":"//*[@id='content container']

The error is occurring despite having the correct xpath in the code: Unable to locate element: {"method":"xpath","selector":"//*[@id='content column']... It seems like there might be multiple xpaths in the field. Here is the code snippet: dr ...

Blog HTML Editing Tool

Apologies for the simple question. I'm struggling to find the right plugin for blog writing that allows users to edit fonts and add images. I also need the ability to submit the generated HTML code into MySQL. Can anyone offer assistance with this pro ...

Updating Template in Python Flask upon Button ClickLet's enhance our Python Flask application by

I need assistance with switching templates upon clicking a button. My Python code is as follows: @app.route("/", methods = ['POST', 'GET']) def my_forum_post(): if request.method == 'POST': if reque ...

The Bootstrap navigation menu is functioning properly when opening, but has an issue when attempting

Creating a mirrored version of an HTML file using NuxtJS, I've included the following code snippet in the Navbar component for my NuxtJS project. <template> <section id="navigation-menu" class="menu menu3 cid-sLhoPz7Ycg" ...

What is the best way to ensure an image fits perfectly within a div container

I'm attempting to design a straightforward card layout where the image spans the entire width of the container div. My vision is for it to resemble something like the example in the linked image below. https://i.sstatic.net/X5oJD.png I experiment ...

Implementing a fixed div with jQuery scrolling

I need the left div to stay in sync with the scrolling content. However, there is a challenge because this div is taller than the screen. I want the user to be able to see the bottom of the left div when they reach the bottom of the page. My solution invo ...

Unlock the innerHTML of a DIV by clicking a button with ng-click in Angular JS

I am curious about something. There is a <div> and a <button> in my code. I am looking to access the inner markup of the <div> within the ng-click function without relying on jQuery. Can you give me some guidance? <div id = text-entry ...

I'm having trouble displaying the Facebook page plugin on my HTML website

I encountered a minor issue. I attempted to add the "Facebook page plugin" on a test website. I copied the code from the official Facebook plugin page: <!-- 1. Include the JavaScript SDK on your page once, ideally right after the opening <body> t ...

triggering a button click event in HTML

Below is the creation of a div: <div class="area1"> </div> By using AJAX, I was able to alter the HTML for the aforementioned div with this call: $('#abutton').click(function(e) { e.preventDefault(); ...

Experiencing difficulty aligning the Material UI grid to float on the right side

I'm currently in the learning phase of material-ui and encountering an issue with floating the grid content to the right side. Despite trying alignItems="flex-start" justify="flex-end" direction="row" in the container grid, as well as using the css p ...

Incorporate text into the URL of the image

Got a URL of an image like this: https://lipsum.mobi/catalog/product/SE0229E/YG/AAA/4/1/SE0229E-YG-AAA-4.jpg', and looking to add 240x240 within the URL. Current Url: https://lipsum.mobi/catalog/product/SE0229E/YG/AAA/4/1/SE0229E-YG-AAA-4.jpg Desire ...

Core MVC - Adjusting Font Size

After setting up an MVC Core App with automatic scaffolding, I am now faced with the challenge of adjusting the font size in my html View. The question is: How can I change the font size in bootstrap.css? There seem to be multiple font sizes available an ...

What steps can I take to resolve the issue of my popup closing automatically upon opening and simultaneously refreshing my webpage?

After creating a popup in my HTML page, when I click on the element that triggers it, the popup appears for a brief moment before automatically closing and causing my page to refresh. Below is the code I am using: HTML Code : <a class="lv-footer" id= ...