Positioning text at the bottom of a label

My goal is to align the text at the bottom of labels with a fixed height of 3em. This means that labels with one line of text should have the text aligned at the bottom, while labels with two lines should have the second line appear at the bottom.

In my layout, I have multiple columns in a Bootstrap row, each containing a label and a textarea. Some labels have longer text that spans two lines when the page width is reduced. To ensure consistency, I set all labels to a height of 3em. However, I now want the text in shorter labels to be aligned with the bottom row of longer labels, regardless of whether the longer labels occupy one or two rows.

Here's an example:

            <div class="row bottom-row">
                <div class="col-lg-3 col-md-6 textarea-div">
                    <label for="textArea1" class="titleLabel textareaLabel">Short</label>
                    <textarea id="textArea1"></textarea>

                </div>
                <div class="col-lg-3 col-md-6 textarea-div">
                    <label for="textArea2" class="titleLabel textareaLabel">Short</label>
                    <textarea id="textArea2"></textarea>
                </div>

                <div class="col-lg-3 col-md-6 textarea-div">
                    <label for="textArea3" class="titleLabel textareaLabel">A longer label</label>
                    <textarea id="textArea3"></textarea>
                </div>

                <div class="col-lg-3 col-md-6 textarea-div">
                    <label for="textArea4" class="titleLabel textareaLabel">A longer label</label>
                    <textarea id="textArea4"></textarea>

                </div>
            </div>

Answer №1

To achieve this effect, you can wrap the text in a span and utilize flex properties to align the span at the bottom of the label. The label itself should have a display setting of flex. One option is to apply margin-top:auto to the span within the flex container, or use justify-content: flex-end to push the spans to the bottom of the labels.

UPDATE: Spans have been removed based on feedback. Thanks!

.row {
  margin: 0 -15px
}

.col-lg-3 {
  width: 25%;
  float: left;
  padding: 0 15px;
  margin-bottom: 15px
}

.titleLabel {
  height: 3em;
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end
}
<div class="row bottom-row">
      <div class="col-lg-3 col-md-6 textarea-div">
          <label for="textArea1" class="titleLabel textareaLabel">A short one line label</label>
          <textarea id="textArea1"></textarea>

      </div>

      <div class="col-lg-3 col-md-6 textarea-div">
          <label for="textArea3" class="titleLabel textareaLabel">A longer label with at least two lines</label>
          <textarea id="textArea3"></textarea>
      </div>

      <div class="col-lg-3 col-md-6 textarea-div">
          <label for="textArea4" class="titleLabel textareaLabel">A longer label with enough text to run over three lines and will be very long</label>
          <textarea id="textArea4"></textarea>
      </div>
  </div>

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

Choose an element for styling only if it contains a child element with a particular class

Looking to adjust padding based on specific child class <div class="container page-content"> </div> The page-content class typically includes padding: .container.page-content{ padding-top: 160px; } However, there is a special case wher ...

Ways to center a div with position:relative vertically on the page

What is the best way to center a position relative div vertically within its parent element? For example: <div class="parent"> <div style="position:relative;" class="child"> </div> </div> Any suggestions on how to vertic ...

How to make a div disappear when hovered using Tailwind CSS

I need help with my code that is not working as expected. I have a set of images displayed as cards, each with text below them. I am trying to hide the text and only show the image using Tailwind v2, but I can't seem to get it right. Here's my co ...

Could anyone assist me in positioning my personalized Context Menu beside my cursor?

If possible, I would appreciate some assistance with my custom context menu. It may require some minor tweaks or a fresh idea on how to address the issue. Ideally, I would like to keep the HTML and CSS somewhat unchanged. [I'm not sure what to write ...

Create an HTML button with dual functionality

I currently have a button in my HTML that triggers the opening of the sidebar on mobile devices. <a href="#header" class="button scrolly">Contact Me</a> There is also a label element that, when clicked, selects the name field in the contact f ...

The impact is felt across every button in CSS

Why is this happening? When I hover over a button, all buttons apply the effect, which should not be the case. I only want the effect to be applied to the button that I am hovering over. .buttons{ font-family: arial; text-decoration: none; padding ...

Retrieve a specific attribute from every row within an HTML table

I have an HTML table and I'm looking to extract the call_id attribute from each row using JavaScript. Here's a snippet of the table in my editor: Simplified view: https://i.sstatic.net/MlyNj.png After accessing the table using the code below, I ...

The image displayed on the HTML scrset attribute is not the correct one

I'm experiencing an issue with correctly loading the responsive image using scrset. The sizes attribute I am using is: sizes="(max-width: 767px) 95vw, 768px" and for the srcset attribute: srcset="https://cdn.runningshoesguru.com/wp-content/uploads ...

Combining the total of numerous inputs that are multiplied by a specific value all at once

Hey, I've been working on a project with a table and an input field with costs using jQuery. You can check out This Fiddle for reference. $( ".total" ).change(function() { let i = 1; var input001 = document.getElementsByName(i)[0]; var ...

Ensuring the authenticity of user login credentials

I have a form in my HTML where the user needs to input their name and password. <html> <body> <form action="welcome.php" method="post"> Name: <input type="text" name="name"><br> Password: <input type="text" name="password ...

Tips on finding an error message within the website's developer options when the inspector fails to locate it

I'm dealing with a website at On this site, there's a 'get latest blog posts' field that I want to automate the error message for. When I input an invalid email address like test123.com, I receive an error response but can't find ...

Hide the div once it goes off screen, ensuring that the user stays in the same position on the page

On my website, I implemented an effect similar to the Airbnb homepage where there is a "How it Works" button that toggles a Div element pushing down the entire page. However, when the user scrolls to the bottom of the toggled div (#slideDown) and it disapp ...

Retrieve the nearest attribute from a radio button when using JQuery on a click event

I have a query regarding the usage of JS / JQuery to extract the data-product-name from a selected radio button, prior to any form submission. Although my attempt at code implementation seems incorrect: return jQuery({{Click Element}}).closest("form" ...

Randomly positioning an image while the page is loading

I've been developing a portfolio website to showcase my design work, but I've encountered a minor issue. My goal is to have the images load in random positions and then make them draggable using Dragabilly. However, sometimes all the images end ...

Using a background image in a flexbox container with CSS

I'm struggling to add a background image to text. I have a feeling that the issue might be related to nesting too many classes within the "div" tag, but I can't seem to solve it. CSS: .box { display: flex; top: 80px; position: relative; ...

Text being enveloped in a span tag

Currently, I have a table displaying a list of users with their corresponding roles. However, the roles column is sometimes wrapping before reaching the end of the line. The user list data looks like this: $scope.userList = [{ "id": 1, "name":"AB ...

Transferring content files from a nuget directory to a specific destination folder

I am dealing with a nuget package that includes css files as content. My goal is to have these css files copied to a specific directory upon importing the package into a project, without requiring the project's structure to match exactly. Is there a ...

What is the best way to create a gallery using Bootstrap 4?

I'm currently working on a project for my homework that involves replicating a car brand page, but I've hit a roadblock at this particular section. https://i.stack.imgur.com/0Zfr5.jpg My goal is to recreate the gallery using a .container with n ...

Move the cursor to the left in a floating selection field (Bootstrap 4)

Can the select field bootstrap caret be floated to the left? https://i.sstatic.net/4GyvK.png I attempted the following code but did not observe any change .dropdown-toggle::after { float:left !important; } ...

Centering all td elements except for those with a specific class

Consider the following code snippets: <tr> <td class="foo">chuchu</td> <td>chuchu</td> <td>chuchu</td> <td>chuchu</td> <td>chuchu</td> </tr> Is there a way to center align thes ...