Tips for creating various column widths within a single row

Hey there, I'm currently working on a web application using Bootstrap and running into an issue with the grid system. Whenever I add elements to a column, all the columns in the same row stretch together, which is not the desired behavior. Take a look at the image below for reference: https://i.sstatic.net/60KFk.png

As you can see, adding "Line1", "Line2", and "Line3" causes all containers in the same row to stretch. I only want the container labeled "Something" to increase in height vertically.

Here is my current code:


  <SideNav>
      
  </SideNav>

  <div className='container-md mt-5'>
    <div className='row text-center'>
      <h4 className='mb-5'>"The body achieves what the mind believes" - Alek Barns</h4>
      <div className='col-md-3 shadow p-3 mb-5 bg-white rounded display-6'>Metric</div>
      <div className='col-md-1'></div>
      <div className='col-md-3 shadow p-3 mb-5 bg-white rounded display-6'>Goal</div>
      <div className='col-md-1'></div>
      <div className='col-md-4 shadow p-3 mb-5 bg-white rounded display-6'>Something
       <h4>Line 1</h4>
       <h4>Line 2</h4>
       <h4>Line 3</h4>
      </div>
    </div>
    <div className='row text-center'>
      <div class='col-md-8 shadow p-3 mb-5 bg-white rounded display-6'>
        <h2>Today's Workout: HIT Training</h2>
        <img src="https://media.flowin.com/blog/blog_654350014.jpg" class="img-fluid"></img>
      </div>
      <div class='col-md-2'></div>
      <div class='col-md-2 shadow p-3 mb-5 bg-white rounded display-6'>
        <h2>Friend Zone </h2>
        <h5>Most Workouts</h5>
        <h6>1. Kaasim - 12 Completed</h6>
        <h6>2. Bryan - 10 Completed</h6>
        <h6>3. Mo - 9 Completed</h6>
        <h6>4. Jung - 8 Completed</h6>
        <h6>5. Chris - 7 Completed</h6>
        <h6>6. Anna - 7 Completed</h6>
      </div>
    </div>
  </div>
  </body>

Answer №1

To align a column to the top line without stretching, simply add the col-baseline class to the column. Check out this Codepen.io example

/* use the col-baseline class to align column */
.col-baseline {
  display: flex;
  align-self: baseline;
}

/* for demonstration purposes only */
.bd-example {
    position: relative;
    padding: 1rem;
    margin: 1rem -15px 0;
    border: solid #f8f9fa;
    border-width: 0.2rem 0 0;
}
.bd-example-row .row>[class^="col-"] {
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
    background-color: rgba(86,61,124,0.15);
    border: 1px solid rgba(86,61,124,0.2);
}
/* end of: for demonstration purposes only */

.col-baseline {
  display: flex;
  align-self: baseline;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="35575a5a41464147544575011b031b04">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"/>

<div class="bd-example bd-example-row">
  <div class="container">
    <div class="row">
      <div class="col-9">.col-9</div>
      <div class="col-4">.col-4<br>Since 9 + 4 = 13 &gt; 12, this 4-column-wide div gets wrapped onto a new line as one contiguous unit.</div>
      <div class="col-6 col-baseline">.col-6<br>Subsequent columns continue along the new line.</div>
    </div>
  </div>
</div>

Answer №2

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"/>
<div class='container-md mt-5'>
   <div class='row text-center'>
      <div class='col-md-4 d-flex'>
         <h4>Line 1</h4>
         <h4>Line 2</h4>
         <h4>Line 3</h4>
      </div>
   </div>
</div>

Simply include the 'd-flex' class

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

Steps for accessing CSS variables within a scoped style block in Vue with Buefy_integration

After diving into the Buefy documentation, I successfully personalized my color scheme and even crafted unique hues by applying the is-[colorName] as a class to HTML elements. <style lang="scss"> // Importing Bulma's core @import "~bulm ...

Experiencing difficulties establishing a connection between the React client and Node.js server using SocketIO

I am currently getting familiar with socketIO and have successfully set up a basic nodejs server. However, I am facing an issue where my nextJS app is unable to connect to the server as expected. Despite no errors being displayed, the messages that should ...

How do I adjust the placement of a drawer using material-ui?

How can I adjust the positioning of the drawer in material-ui? I have been attempting to add paddingLeft styling to the drawer element, but it doesn't seem to be working as expected. Is there anyone who might have insights into what could be causing ...

What could be causing the server to receive an empty request.body when making a POST http request with axios?

Currently, I am facing an issue while attempting to send a file (.obj file) through formdata to my node server. It seems that everything is functioning correctly until the controller of the endpoint on the server throws an error indicating that the formdat ...

Error: Failed to clone an object in Electron due to an unhandled promise

I'm in need of assistance with sending files from the main directory to the renderer. Before proceeding, I attempted to check if it was functioning correctly by using console.log(files). However, this resulted in an error message. Can someone please p ...

Having trouble setting up a React 18 project with TypeScript and Redux Toolkit

I'm encountering an issue while setting up a project with the latest versions of React 18, TypeScript, and Redux Toolkit. Specifically, I'm facing a problem when trying to install '@reduxjs/toolkit', as it throws the following error: np ...

Tips for eliminating the shadow effect from a textbox using CSS

I need assistance with removing the shadowed edges on a textbox in an existing project. Can anyone provide guidance on how to remove this effect? Thank you for your help! ...

Styles in CSS for the first column of a table, with the exception of the first cell in

Here is the HTML code for a table: <table class='census'> <tr> <th colspan="2">My Title</th> </tr> <tr> <td colspan="2" class='chart'><SOME PIE CHART, GENERATED W ...

Developing and integrating views within a node-webkit desktop application

For my file copier desktop application built with node webkit, I aim to create a seamless flow where the initial check for existing profile data determines the first page displayed. The header with static links/buttons to various views remains consistent ...

Disable border on antd select element

Currently, I am utilizing the Select component from the antd NPM package and encountered an issue with the blue outline that appears when the component is focused. Can someone provide guidance on how to remove this outline? In my attempts to address this ...

What is the best way to style a component within the MuiThemeProvider tag?

Currently, I am in the process of setting up the AppBar by referring to the component demo: The Navbar component structure is as follows: const styleSheet = createStyleSheet('Navbar', {}); function Navbar(props) { return ( <div> ...

What are some ways to decrease the dimensions of my dateTimePicker?

I'm looking to decrease the dimensions of my datetime picker box. Here's an image of my current dateTimePicker: https://i.stack.imgur.com/MeJlq.png Below is the component I'm using: import React, { useState } from 'react'; import ...

I'm looking to divide the background horizontally into two sections, with one side being a solid black color and the other side incorporating a gradient of two colors, such as purple transitioning into pink

body { height:100%; background: linear-gradient(top, #d808a4 50%, black 50%); background: linear-gradient(top, #d808a4 50%,black 50%); background: linear-gradient(to bottom, #d808a4 50%,black 50%); height: 229vh; } I am trying to creat ...

A complete div component with a minimum height that is sandwiched between a fixed size header and

I'm currently facing a challenge with setting up my webpage due to the height of my elements causing a bit of a frenzy. Specifically, I have a specific layout in mind: At the top, there should be a header that has a fixed height (let's say 150p ...

React - the function executed within a loop is only invoked once

I have implemented a click handler in my book component to facilitate page flipping. This handler appends the necessary classnames to the pages, enabling me to set up the CSS for the page flip animation. // ---------- Handle the click event on the book p ...

Disabling the background shadow effect in Angular Material's Accordion

I successfully disabled the background shadow on the Angular Material Accordion in this demonstration by incorporating the following CSS rule: .mat-expansion-panel:not([class*='mat-elevation-z']) { box-shadow: none !important; /* box-shadow: ...

Disappearing Into the Background Excluding Specific Divs

I have a dilemma with fading in and out a background image using jQuery fadeIn and fadeOut. The issue arises because my wrapper div contains elements such as sidebar and navigation that are positioned absolutely within the wrapper div, causing them to also ...

Can you explain the concepts of 'theme' and 'classes'?

Currently, I am working on a web application using React. I have chosen to incorporate the latest version of Material-UI for designing the user interface. During this process, I came across the demo examples provided by Material-UI (like ) In each demo ...

Tips for setting up nextjs with typescript to utilize sass and nextjs font styles

I am attempting to configure a Next.js TypeScript app to work with Sass and a font in Next.js. I have been following the steps outlined in this article. Without the font module, styles are working correctly. Below is my next.config.js without the font co ...

The Bootstrap Navbar appears hidden beneath other elements on mobile devices

While using bootstrap to style my header contents, I encountered a strange issue. The navbar that appears after clicking on the hamburger menu is displaying behind all the components. Even though I've set the z-index to the maximum value, it still doe ...