Ensure that the card header in Bootstrap CSS is consistently displayed at a height of two lines

I am currently developing a webpage using Angular, where bootstrap cards are generated dynamically. The code snippet for this looks like the following:

<div class="row">
    <div class="card border-primary p-0 mb-2 col-md-4 col-sm-6 colxs-12" *ngFor="let m of myVals">
        <h4 class="card-header text-center">{{m.Title}}</h4>
        <div class="card-body">
            <h5>{{m.Year}}</h5>
            <img [src]="m.Poster" [alt]="m.Title" class="card-img-top">
        </div>
    </div>
</div>

The main issue I am encountering is with the element

<h4 class="card-header text-center">{{m.Title}}</h4>

The problem arises when the title is displayed on 2 lines or 1 line, causing the cards to look uneven. I am looking for a way, perhaps using Bootstrap or CSS, to ensure that the card-header always displays as 2 lines high, regardless of the content. I attempted using a CSS style of line-height: 2, but it did not have the desired effect. Is there a better way to achieve this uniformity?

Thank you!

Answer №1

To achieve this, you can implement custom CSS. Take a look at the working fiddle provided below:

.card-header-custom {
  min-height:80px;
  display:flex;
  justify-content:center;
  align-items:center;
}
<!DOCTYPE html>
<html lang="en>
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
</head>
<body>
 
<div class="container>
  <h2>Card Header and Footer</h2>
  <div class="row">
    <div class="col-sm-6">
     <div class="card">
        <div class="card-header card-header-custom">Header big content Header big content </div>
        <div class="card-body">Content</div> 
        <div class="card-footer">Footer</div>
      </div>
    </div>
    <div class="col-sm-6">
      <div class="card">
        <div class="card-header card-header-custom">Header</div>
        <div class="card-body">Content</div> 
        <div class="card-footer">Footer</div>
      </div>
    </div>
  </div>
</div>

</body>
</html>

Answer №2

Here is an example of HTML and CSS code:

<div>
  <h4>
    <span>One line heading</span>
  </h4>
  <h4>
    <span>Assume this heading has two lines</span>
  </h4>
</div>

The CSS code for styling the headings is as follows:

h4 {
  height: 2.5em;
}

h4 span {
  line-height: 1.25em;
}

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 is the method for selectively applying a "fade to black" mask to an input field?

For my current project, I need to incorporate a design feature where a "fade to black" mask gradually appears on the left side of an input field once the text content reaches the maximum visible width of the input box. The image below provides a visual re ...

Angular material: issue with alignment of table inside mat-expansion compared to other table

Hey there, I've encountered an issue on an Angular website where the columns in a table are not aligning properly. Does anyone have a solution for this problem? Thanks! <div class="table-responsive "> <table class="table" style=" ...

"Authentic" foundation for typography

Line spacing in web design is different from line spacing in print design, such as in programs like InDesign. Here are the results: Web example: http://jsfiddle.net/Y9M28/4/ (works better in webkit) Print example: http://jsfiddle.net/Y9M28/3/ I have t ...

Exploring the jQuery syntax within Twitter Bootstrap JS files

Questioning the syntax used in Twitter Bootstrap's JS files. Take for example this snippet from bootstrap-dropdown.js: !function ($) { /* ... */ /* Querying the Standard Dropdown Elements -- Inquiry Code * ================================= ...

Aligning text and lists using Bootstrap on both desktop and mobile devices

I want to format a text with a list similar to the images provided https://i.stack.imgur.com/6giDH.png for desktop and tablet view, but for mobile display I would like it to look like this https://i.stack.imgur.com/7zSXi.png This is my current approach ...

Room available on the body's right side for tiny gadgets

I'm currently facing a website issue while using Bootstrap. Everything seems to be working fine until I attempt to check the responsiveness of my website. There appears to be an excessive white space on the right side of my body, but only in a specifi ...

What is the best way to adjust the responsiveness of my AppDrag page for mobile optimization?

My landing page is all set up, but I'm looking to tweak the font sizes and spacing for mobile users. Can these changes be made using design tools instead of digging into the code? ...

What is the method for inserting a clickable link into a data-image line of code using CSS3?

Recently, I delved into the world of CSS and am still getting the hang of it, Below is a snippet of code that I have been working on, <div id='ninja-slider'> <ul> <li> <div data-image="images/md/1.j ...

Can a single div have three different border-bottom styles?

Can three border-bottom styles be applied to a single div element? This is the desired appearance: ...

Seeking to have text spill over into a different container

Novice in CSS seeks advice. I've nailed the layout of the home page for my website with two divs</p> <p><div> <div> <pre class="snippet-code-css lang-css"><code>#desktop-navbar { text-transform: uppercase; ...

Changing Location of Carousel in Bootstrap

Recently, I have been working with Bootstrap and have encountered a problem with the carousel. I have placed carousel images below my navbar, but there seems to be a gap between the navbar and the carousel image. I want the image to be right below the navb ...

Using jQuery to toggle the menu

I've been brainstorming ways to add a toggle menu on my website and finally stumbled upon a solution that works great! http://jsfiddle.net/hhcsz5cr/ <div> <h1><button class="button" data-circle="travel"> <i cl ...

ReactStrap: Difficulty concealing navbar item based on screen dimensions

Currently, I am referring to the official documentation to implement a scenario where a NavItem is only displayed for screen sizes greater than sm. As per the guidelines provided in the documentation, I have included the following attributes: https://i ...

Is it possible to create an image or logo that moves in sync with the user's scrolling

Having trouble articulating this question, but I'm trying to replicate the logo in the top right corner of this website: I want the logo to move along with the user as they scroll down, remaining visible at all times. Any ideas on how to achieve this ...

Tired of the premium content on Medium.com. How can I conceal premium posts that are aimed at a specific class within a parent element?

I have noticed that all Premium posts contain an element with the class ="svgIcon-use" <svg class="svgIcon-use" width="15" height="15" viewBox="0 0 15 15" style=""><path d="M7.438 2.324c.034-.099.090 123 0l1.2 3.53a.29.29 0 0 0 .26.19h3.884c.11 0 ...

The @Html.Label feature fails to appear when the content includes a period (.) - Utilizing Bootstrap with MVC Razor

I am dynamically populating label text from a database source <div class="col-11 col-sm-11 col-md-11 col-lg-11 col-xl-11"> @Html.Label(@Model.Questions[i].DataText + ": ", new { @for = "dd" + @Model.Questions[i].Data ...

Identifying overflow of text or elements in JavaScript during execution

The website I'm working on has a unique design that requires users to scroll horizontally using the Arrow Keys instead of swiping. To achieve this, I must constantly check for overflow in text or elements each time a new page is loaded, and if necessa ...

My Drop Down menu is not displaying the <a> in two lines, and I'm having trouble getting it to show correctly

Hello there! I've encountered an issue with my drop-down menu. The text within the <a> tags is too long to fit on a single line, and I'm struggling to make it display in two lines instead. I've been experimenting for the past couple o ...

Instructions for utilizing float:left and list-style-type within HTML are as follows: I am currently experiencing issues with implementing the float:left and list-style-type properties in my code

I'm attempting to align a button list to the left using the float: left property and also remove list styles, but for some reason it's not working as expected. //CSS #tus{margin:5px;padding:0;width:640px;height:auto;} #tus ul{margin:0px;padding: ...

Using CSS to justify the final line of content

I have created a CSS helper class that is meant to justify-align the last line of text, or inline block divs, along with the rest of them. Here is the CSS code I have implemented: .justify-all-lines { text-align: justify; /* IE-only properties th ...