Achieving Varied Line Heights in a CSS Flexible Grid Column Layout - Vertical Text Alignment Tips for Top Placement

Currently, I am designing a web layout that requires a flexible column structure with varying line heights. The main objective is to have one column with a higher line-height while ensuring that both paragraph texts in different columns start from the same top position.

Within my layout, I need to be able to display either 1, 2, or 3 columns horizontally, with the title centered above its content.

I have attempted to achieve this using the following HTML and CSS:

However, there seems to be an issue where the text on the right displayed in yellow does not align perfectly with the text on the left.

<html>
    <head>
        <style>
            .columnA {
                color: white;
                margin-right: 15px;
            }

            .columnB {
                color: yellow;
                align-self: start;
                margin-bottom: 20px;
                vertical-align: top;
            }

            .comment.title {
                display: grid;
                color: yellow;
                text-align: center;
                margin-bottom: 20px;
                grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
            }

            .comment.columnA {
                color: green;
                line-height: 1.4;
            }

            .comment.columnB {
                color: yellow;
                line-height: 2.4;
            }

            .content {
                display: grid;
                margin-bottom: 20px;
                align-content: start;
                grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
            }

            .black-background {
                background-color: black;
            }
        </style>
    </head>
    <body class="black-background">
        <div class="comment">
            <div class="comment title">
                <p class="columnA">TitleA</p>
                <p class="columnB">TitleB</p>
            </div>
            <div class="content">
                <p class="comment columnA">
                        Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
                </p>
                <p class="comment columnB">
                        Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
                </p>
            </div>
        </div>
    </body>
</html>

Answer №1

Modify the CSS by setting

.content{ align-items: baseline; }
and removing .columnB { align-self: start; }:

.black-background {
  background-color: black;
}

.comment.title {
  display: grid;
  color: yellow;
  text-align: center;
  margin-bottom: 20px;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
}

.comment.columnA {
  color: green;
  line-height: 1.4;
}

.comment.columnB {
  color: yellow;
  line-height: 2.4;
}

.content {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  margin-bottom: 20px;
  align-items: baseline;
}
<body class="black-background">
  <div class="comment">
    <div class="comment title">
      <p class="columnA">TitleA</p>
      <p class="columnB">TitleB</p>
    </div>
    <div class="content">
      <p class="comment columnA">
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
      </p>
      <p class="comment columnB">
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
      </p>
    </div>
  </div>
</body>

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

Double-Dropdown Menu in HTML and Javascript Failing to Function

I recently set up a double drop-down menu by following the instructions in this helpful guide: However, after adding my own options, I noticed that the second drop-down menu is no longer displaying. What could be causing this issue? <!-- The first ...

Increase the jQuery level and utilize the .find() method

Currently, I am delving into the realm of jquery and facing a minor hiccup with selectors. Below is the structure of my DOM: <li> <header class="title"> <span>Text</span> <a href="#work-1">My trigger</a> ...

Space within a series of photographs

Looking for some assistance: I am trying to maintain a consistent margin of 10px between posts and between photos in a photoset. However, when a post is a photoset, the margins of the bottom photo and the overall post add up to 20px. I want to retain the ...

"Trying to access jQuery .slide and .slideUp features, but unfortunately they are

I've created this script: $("#comments .comment .links").hide(); $("#comments .comment").hover( function() { $(".links", this).stop(true).slideDown(300); }, function() { $(".links", this).stop(true).slideUp(300); } ); However, I'm facin ...

In PHP/HTML, input submit does not work with CSS styling

I am struggling with styling the input submit button in my form. I want the button to appear as text with a change in background and font color on hover. Any solutions? input[type="submit"] { font-family: made, mirage; text-decoration: none; backg ...

What is the method for advancing the cursor to the next line in this animation?

I've created an animation that types out: "[Your Name] blah blah" with a typing effect. Now, I want the cursor to move to the next line and type out: "[Your Father Name] blah blah" I attempted to add <br>, but it types out both lines simulta ...

CSS code influencing unintended elements

www.geo-village.com <- Live Example After setting up my main webpage with CSS and PHP files, I noticed an issue with the navigation bar. Despite having a separate PHP and CSS file for the navigation bar items, the Login and Register buttons on the main ...

How can you employ moment.js to display the most recent update time of mongoDB/mongoose?

I am facing an issue with displaying the last date/time when any entry in my table was edited and updated using moment.js. It seems to be updating the date/time in real-time rather than only showing when a database entry was modified. How can I ensure tha ...

Utilize a dynamic URL within the HTML audio element

Currently, I am working with the use of the audio tag in HTML and AngularJS. I need to specify the source of the audio file I want to play, as shown below. <audio src="http://localhost/audio/221122/play/212223.mp3" audio player controls p ...

Difficulty in displaying Font Awesome Unicode on website

I am struggling to populate a list with Font Awesome icons 4.7.0 in my HTML code using Bootstrap. Strangely, only the first icon is displayed while the rest remain invisible. <link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font- ...

Positioning the image to appear behind the Canvas

As I near the end of the game, I'm encountering an issue where the background image overlaps the Canvas. How can I resolve this problem? -Translated by Google Link to game Link to game with background ...

Submit HTML checkboxes that have not been selected

I have a set of checkboxes that come pre-checked by default. I anticipate that my users may uncheck some, but will probably leave most of them checked. Is there a way to configure the form so that it submits the unchecked checkboxes instead of the checked ...

Getting style information from a parent element in ReactJS involves accessing the parent component's CSS properties

Is there a way to automatically change the color of text inside a button component based on the color of the button itself? I'm trying to access the parent element's color in my text component. Here's what I have: const MyText = (props) => ...

align the bootstrap when the screen resolution is less than 900 pixels

As a newbie in web development and Bootstrap, I'm working on creating a responsive website. Everything was going smoothly until I encountered an issue when transitioning from desktop to mobile view. I have three buttons aligned in a row on desktop, bu ...

Creating a user authentication portal

Looking for advice on creating a basic front end HTML login. I'm new to coding and would appreciate any suggestions! Additionally, how can I link the login system to my database? ...

Using multiple header tags in HTML

I have been tasked with developing a webpage featuring a prominent header at the top of the page. This header will include the navigation bar, logo, and website title. As the user begins to scroll, I want the header to transform into a compact version that ...

What is the process for immediately changing the background color of an input field as soon as text is entered?

I am encountering an issue with the code snippet provided below. My goal is to change the background color of an input field as soon as I start typing something into it. The scenario involves 4 input fields where if the submit button is clicked and any f ...

Display an HTML image within a span tag and ensure it is aligned to the bottom

I am facing a layout issue with 2 images that are placed side by side within their tag . The sizes of the images are different, but they are both anchored at the top of their parent element. <span style="position: relative; left: 0; top: 0; vertical- ...

Having trouble getting the focus-within CSS pseudo-class to work with an HTML label

I'm attempting to create a dropdown menu with checkboxes inside the dropdown area. Below is the code snippet I am using: .search-box { color: black; width: 450px; } .search-box .fake-tb { display: flex; flex-wrap: nowrap; background: #f ...

Using NPM in conjunction with a PHP/STATIC web site directory structure: A comprehensive guide

My PHP website has a file structure like this: / css/ js/ index.php When I run the following commands: npm init npm install <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="eb8984849f989f998a9babdfc5dd">[email p ...