What is the best way to vertically align text on the left side in the center of a column?

In a column taking up 7/12 of the width of the row, how can I vertically center align text consisting of an <h1> and a <h3>? I want them to be left aligned while sharing the space with an image in the other 5/12 of the row. Any insights on this would be greatly appreciated!

Below is my HTML code:


<hr>
<div class="row detail">
    <div class="col-md-7 detail-texts">
      <h1 class="">First featurette heading. <span class="text-muted">It'll blow your mind.</span></h1>
      <h3 class="lead">Donec ullamcorper nulla non metus auctor fringilla. Vestibulum id ligula porta felis euismod semper. Praesent commodo cursus magna, vel scelerisque nisl consectetur. Fusce dapibus, tellus ac cursus commodo.</h3>
    </div>
    <div class="col-md-5">
      <img class="img-fluid mx-auto" src="assets/500x500.jpg" alt="grey box"> 
    </div>
  </div>

  <hr>

        <div class="row detail">
          <div class="col-md-7 order-md-2 detail-texts">
            <h1 class="">Oh yeah, it's that good. <span class="text-muted">See for yourself.</span></h1>
            <h3 class="lead">Donec ullamcorper nulla non metus auctor fringilla. Vestibulum id ligula porta felis euismod semper. Praesent commodo cursus magna, vel scelerisque nisl consectetur. Fusce dapibus, tellus ac cursus commodo.</h3>
          </div>
          <div class="col-md-5 order-md-1">
            <img class="img-fluid mx-auto" src="assets/500x500.jpg" alt="grey box">   
        </div>
        </div>

        <hr>

This is my SCSS file:

.detail{padding: 6%;
color:#5a5a5a;

&-texts{padding: 0;}

}
hr{width:88%;}
    
img{width: 500px;
   height: 500px;}

display:flex;
align-items: center;

and

display:flex;
    align-self: center;

I tried adding d-flex and align-self-center classes to .details-texts, which worked. Can anyone explain how this differs from using display:flex?

Answer №1

Utilizing flexbox is a great solution for achieving this.

.detail-texts{
    display: flex;
    align-items: center;
}

Answer №2

After some investigation, I came across the solution: by including the d-flex class in my div along with row, and then adding align-self-center to the inner div class, everything fell into place. It's puzzling how this approach differs from simply applying

display: flex;
align-self: center;

in SCSS, as it should technically be the same. This uncertainty is the only issue I currently have. Thank you!

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

Ensure that button positioning lines up properly even if adjacent content causes it to shift

I have developed several products using only HTML & CSS. One challenge I am encountering is that when the content inside the div exceeds a certain length, it causes everything to shift down, resulting in uneven alignment (refer to the 3rd product in the i ...

Using Less in CSS values can sometimes involve incorporating slashes (`/`), such as in the shorthand for `font`

While working with Less and font shorthand, I came across an issue: .font(@weight: 300, @size: 22px, @height: 32px) { font: @weight @size/@height "Helvetica Neue", Arial, "Liberation Sans", FreeSans, sans-serif; } The above code snippet resulted in a ...

Place the border image underneath the div element

I successfully added a border image to the right side of my div, but now I want it to extend slightly below the div. Is there a way to increase the height of the border image? Or should I just float the image next to the div and how would I go about doing ...

Steps to dynamically reveal a table row within another row when clicked:

I have a table and I want to show the contents of another row inside the current row when the plus icon is clicked. I'm not sure which HTML element to use for this. Please help me figure it out. Thank you in advance. <div class="pro ...

What is causing my navbar's 'ol' element to have a wider width than the

Hello, I have a navigation bar with a dropdown menu using ol. However, when I hover over the list items, the width of the list exceeds that of the ol element. I believe this is due to the white-space: nowrap CSS property, but I want the text in the dropdow ...

Making the toggle button functional on the navbar

Trying to customize my navbar for tablet and mobile devices is proving to be a challenge. I am looking for a way to make the dropdown button take up the entire page when clicked on. It seems like JavaScript might be the solution, but I'm not quite sur ...

Using JQuery to visually enhance the menu selection by displaying an image and altering the background color upon hovering

Hello fellow JQuery/Javascript beginners! I recently put together a menu and wanted to add some interactive elements. Specifically, I want the background color to change when a user hovers over an item (simple enough with CSS), but I also want to include a ...

CSS Column Height not Transferring to Descendants

Trying to transform this... http://jsfiddle.net/K2NPz/1/ Into this... The image on the left is current, while the one on the right is the desired outcome. However, I'm facing challenges making it work as intended due to issues with the inherit prope ...

A dual row navigation layout with the second row featuring equally distributed elements in a neat and organized manner

Looking to create a responsive collapsible navigation with two rows. The first row should contain the logo and language selector, while the second row should have the main links: | | | ...

Difficulty with spacing in HTML/CSS styling

Here is what I'm currently working on: link to jsfiddle code * { margin: 0; padding: 0; } html { height: 100%; } header, nav, section, article, aside, footer { display: block; } body { font: 12px/18px Arial, Tahoma, Verdana, sans- ...

Revamping the navbar hover effect icon

I am currently working on customizing the navigation bar on my website. I have created a code snippet that adds a small '+' sign next to any link that has sub-options. When the user hovers over the link, the '+' sign changes to a ' ...

Javascript postback functionality is fully operational in bootstrap 4, however, it is failing to return

Encountering an issue with my postback JavaScript function in the ASP/BootStrap environment. After searching on stackoverflow for a solution, I couldn't find one that resolved my problem. The problem is when I click on an image, the page reloads (the ...

What are the best ways to optimize bootstrap col-sm-* for mobile usage?

Currently, my project is responsive up to col-sm. I am looking for a way to ensure that it renders perfectly on mobile devices without having to add col-xs-* throughout the entire project. Is there a method using jquery/scss to make col-sm behave like col- ...

Overflow of content from `div` on top of the window

I have a section with tabs, each tab displaying different content. One of those tabs contains a table taller than the screen size. When I open it, the section stretches and overflows from the top, extending beyond the window. Despite having overflow:auto s ...

Apply a static style to every rendered component just one time

Is there a way for me to individually style each card image only once? For example, I want to apply a transform style via a function in CSS; I want the image to maintain its original value, but when a new component is rendered, that card should have a di ...

Items seem to vanish into thin air and become immovable when attempting to relocate them

I am attempting to create a unique grid layout with 3x3 dimensions, where each grid item represents a fragment of a single image. These items should have the capability to be dragged and dropped inside another 3x3 grid, in any desired sequence. I have hit ...

Can HTML text areas be designed to adjust their width automatically, as well as their height?

Among the numerous StackOverflow examples showcasing an auto-height Textarea, one noteworthy example can be found here: <textarea oninput="auto_grow(this)"></textarea> textarea { resize: none; overflow: hidden; min-heig ...

Creating a mobile-friendly table that remains within a specific width on smaller screens (CSS)

Ensuring consistency across all tables on my website is crucial to me, which is why I am utilizing the same class for all of them. While everything appears perfect on desktop, I'm facing challenges when it comes to mobile responsiveness. The tables fa ...

Choosing multiple classes in CSS 3

As I reviewed some sample code today, I noticed the developer opted to use a "+" instead of a "," to select two classes. .region + .region{ border-left: 1px solid lightgray; padding-left: 3.5%; margin-left: 4%; } I'm curious about what t ...

Locate the closing anchor tag following the image

I need to locate the closing anchor tag that wraps an image with the class name "cat-image" in order to move a div right after it. However, I am unable to modify the HTML by adding IDs or classes to the anchor or image tags. Below is an example of the HTM ...