Tips for designing a three-line label: positioning text in the middle, above, and below

I have a label that looks like this:

https://i.sstatic.net/q0DaR.png

Is there a way to position 'Lorem ipsum' perfectly in the center between 'dolor' and 'amet'?

https://i.sstatic.net/aJapG.png - reference image

This is what I've attempted:

.gp-label {
  vertical-align: middle;
  width: 100%;
}
.gp-left {
  margin: 0;
  padding-right: 1px;
  float: left;
  display: table-cell;
  vertical-align: middle;
}

.gp-right {
  float: left;
}

.gp-right,
.gp-right-up,
.gp-right-down {
  margin: 0;
  padding: 0;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
<div className="form-check user-select-none">
  <input
    type="checkbox"
    className="form-check-input"
    id="gp"
  />
  <label htmlFor="gp" className="form-check-label gp-label">
    <div className="m-0">
      <div className="gp-left">Lorem ipsum &</div>
      <div className="gp-right">
        <div className="gp-right-up">dolor</div>
        <div className="gp-right-down">amet</div>
      </div>
    </div>
  </label>
</div>

However, the result is not as expected:

https://i.sstatic.net/gjuUX.png
and I am unable to align the first div to be centered.

I am using Bootstrap 4's checkbox/label system. Any suggestions on how I can achieve this?

Answer №1

To achieve this effect, utilize the flex property in your CSS stylesheet:

.custom-label.checkbox .margin-0 {
  display: flex;
  align-items: center;
}

Answer №2

Flexbox provides a more modern solution to the issue compared to using floats. It offers greater flexibility, both in design and functionality. Additionally, I made adjustments to the positioning of the checkbox.

.form-check {
  display: flex !important; /* designated as block by Bootstrap */
  flex-flow: row nowrap;
  align-items: center;
}
.m-0 {
  display: flex;
  flex-flow: row nowrap;
  align-items: center;
}
.gp-left {
  margin: 0;
  padding-right: 1px;
}
.gp-right {
  flex: 1 1 auto;
}

.gp-right,
.gp-right-up,
.gp-right-down {
  margin: 0;
  padding: 0;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
<div class="form-check user-select-none">
  <input
    type="checkbox"
    class="form-check-input"
    id="gp"
  />
  <label for="gp" class="form-check-label gp-label">
    <div class="m-0">
      <div class="gp-left">Lorem ipsum &</div>
      <div class="gp-right">
        <div class="gp-right-up">dolor</div>
        <div class="gp-right-down">amet</div>
      </div>
    </div>
  </label>
</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

jQuery plugin stops functioning properly following the use of the jQuery display block method

In my project, I am exploring the use of divs as tabs with jQuery. Within these divs, I also want to incorporate another jQuery plugin. Currently, I have manually created these div tabs using jQuery and set the default style for second and subsequent divs ...

When a link is right-clicked, the window.opener property becomes null

Currently, I am utilizing the window.opener property in JavaScript to update the parent window from a child window. The parent window simply consists of a table with data and a link to open the child window. When the child window is launched, a JavaScript ...

Changing the bootstrap popover location

I'm looking to customize the position of a Bootstrap popover that appears outside of a panel. Here's my setup: HTML: <div class="panel"> <div class="panel-body"> <input type="text" id="text_input" data-toggle="popover ...

Explore the Codrops website with the help of our convenient tour feature and

CoDrops offers a website tour feature created with jQuery, which can be found at this link: http://tympanus.net/Development/WebsiteTour/ However, there is an issue when you click on "Start the tour". It will initially show a Next button, which then change ...

Column with space between arranged rows in a container

I have a container with multiple rows, each containing several columns. I am looking to adjust the spacing between each column <div class="main" style="margin-bottom:0px"> <div class="container"> <div class="row"> <div ...

Use jQuery to easily update the background of an iFrame

I have implemented this code to store the background image selected from a dropdown menu labeled rds. This function also sets a cookie so that the chosen background persists even after the page is reloaded. The issue lies in the line containing $('da ...

Browser resize affects the overlap of DIVs

I've seen similar posts before, but I believe the issue with my website (***) is unique. At full size, the website looks exactly how I want it to. However, when I resize the browser window, the text ("ABOUT INTERNATIONAL PARK OF COMMERCE.." and below ...

Guide to inserting .json data into a .js file

Currently, I have an HTML5 banner designed using Flash CC. However, the platform in which I am showcasing this ad does not support JSON files. I am looking for a way to transfer the information from the JSON file into either my .html or .js file so that ...

What causes HTML validator errors in all head meta-tags?

After running my HTML through a validator, I was shocked to discover around 80 errors even though the site appeared to be functioning properly. Here is an excerpt of the code: <!DOCTYPE html> <html lang="da-DK"> <head> <meta charset=" ...

Tips for accessing form data that has been automatically uploaded in PHP

I've been trying to automatically post data using JavaScript and retrieve it in a PHP file. However, I am facing an issue where the PHP file is not able to retrieve the data. I have set up an automatic form that takes input from another form and send ...

When developing a website with HTML/CSS, is it recommended to utilize tables for organizing content

Seeking guidance as a novice in web development. I am planning to design a table with input fields that will be sent to the server upon submission. What is the preferred method for achieving this? Is it advisable to utilize html-tables or would it be more ...

Creating a resilient CSS: DOM for seamless printing in PDF or on physical printers

I need help with formatting a list of col-6 elements (bootstrap) inside a row element so that the content of each block remains intact in a pdf preview generated using print(). I attempted to use various css properties like page-break and break as suggeste ...

The issue with Jquery .html() function causing spaces to disappear between words

When utilizing jQuery's .html() property to populate a select box, I encountered an issue where the spaces between words were being trimmed down to just one space. Despite including multiple spaces in the option, it would always resolve to a single sp ...

Is it the right time to dive into HTML5 & CSS3?

The excitement around HTML5 and CSS3 is hard to ignore. But when is the right time to start incorporating them into our projects? How close are we to fully utilizing their capabilities? Update: I'm not interested in following the principles of: Grac ...

MaxwidthLG in Material UI design

Hi there, I've encountered an issue with Material UI CSS. Even after attempting to override it, the desired effect is still not achieved. My goal is for the entire div to occupy the full page but this is the current result: https://i.stack.imgur.com/b ...

Several DIV elements lined up side by side

I've been working on a program that retrieves data from a database, lists some of the data when a button is clicked within the same div, and then creates new divs with buttons that have onclick events until it reaches a certain maximum value. To keep ...

Setting the value of an input box using jQuery

As someone who is new to jQuery, I am encountering an issue with setting a default value for an input text box. Despite trying both the val method and the .attr method, neither has seemed to work for me. Below you will find the input HTML along with the tw ...

How can I efficiently utilize HTML/CSS/JS to float items and create a grid that accommodates expandable items while minimizing wasted space?

After meticulously configuring a basic grid of divs using float, I've encountered an issue. When expanding an item in the right-hand column, the layout shifts awkwardly. My goal is to have boxes A and B seamlessly move up to fill the empty space, whi ...

What is the best way to update the text on buttons once they've been clicked for a variety of buttons

I'm encountering an issue with multiple buttons where clicking on any button causes the text to change on the first button, rather than the one I actually clicked on. All buttons have the same id, and using different ids for each button seems impracti ...

Event handlers for textboxes in Visual Web Developer are a crucial component for

Having some difficulty with textboxes - ideally, I would like my second textbox to clear whenever the text in my first textbox changes. Currently, it only clears on postback but is there a way to achieve this without needing a postback for each character ...