Best method to align text beneath picture in Bootstrap 4?

Are you using Bootstrap 4 alpha 6 and trying to display a testimonial with specific elements arranged in a certain way? Here's what you can do:

  • On the left: person's photo
  • On the right: quote, name, and company logo (left-aligned)

This layout should be visible at tablet and desktop widths. However, when the window width is reduced, the image should move on top of the text set, and each part becomes centered.

Take a look at the current code snippet below...

<!-- testimonial -->
<div class="container-fluid cxt-padded bg-faded">
  <div class="container">
    <div class="media">
      <img class="d-flex mr-4 rounded-circle" src="http://placehold.it/150x150" width="150" alt="Generic placeholder image">
      <div class="media-body">
        <p class="lead">"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec varius venenatis neque, id commodo magna fermentum id." <a href="#">link</i></a></p>
        <h2 class="mt-0">Joe Smith</h2>
        <img src="http://placehold.it/150x40" class="img-fluid" width="150">
      </div>
    </div>
  </div>
</div>

The above code renders correctly on desktop screens like this...

https://i.sstatic.net/6x9BQ.png

However, at smaller screen sizes, it looks like this...

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

If you prefer the image to be placed on top and centered as mentioned earlier, there are alternative methods like using two columns as shown below...

<!-- testimonial -->
<div class="container-fluid cxt-padded bg-faded">
  <div class="container">
    <div class="row">
      <div class="col-md-2 text-center">
        <img class="rounded-circle" src="http://placehold.it/150x150" width="150" alt="Generic placeholder image">
      </div>
      <div class="col-md-10 text-center">
        <p class="lead">"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec varius venenatis neque, id commodo magna fermentum id." <a href="#" target="_blank"><i class="material-icons md-inverse pmd-sm">link</i></a></p>
        <h2 class="mt-0">Joe Smith</h2>
        <img src="http://placehold.it/150x40" class="img-fluid" width="150">
      </div>
    </div>
  </div>
</div>

This revised structure achieves the desired appearance on mobile devices...

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

However, there may be concerns about overall markup correctness and alignment inconsistencies between different screen sizes like the one shown below...

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

If you're unsure about the best method or how to handle image responsiveness, consider exploring options for text alignment based on browser width breakpoints. Additionally, feel free to experiment with various classes and styling techniques to find the most suitable approach.

Remember that flexibility is key, so you don't have to stick strictly to predefined styles from Bootstrap documentation. Ultimately, the goal is to create a visually appealing and user-friendly design. Good luck!

Answer №1

There are different ways to approach text alignment depending on your preferences. One option is to utilize responsive utilities to adjust the alignment at various screen sizes. For example, you can use text-md-left to align items to the left on larger screens and switch to text-center for centering on smaller screens.

<!-- testimonial -->
<div class="container-fluid cxt-padded bg-faded">
  <div class="container">
    <div class="row">
      <div class="col-md-2 text-md-left text-center">
        <img class="rounded-circle" src="http://placehold.it/150x150" width="150" alt="Generic placeholder image">
      </div>
      <div class="col-md-10 text-md-left text-center">
        <p class="lead">"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec varius venenatis neque, id commodo magna fermentum id." <a href="#" target="_blank"><i class="material-icons md-inverse pmd-sm">link</i></a></p>
        <h2 class="mt-0">Joe Smith</h2>
        <img src="http://placehold.it/150x40" class="img-fluid" width="150">
      </div>
    </div>
  </div>
</div>

http://www.codeply.com/go/tuTd2OiZFx

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

Use the CSS class

To create tables with 3 rows and 2 columns using divs, I have utilized the ng-repeat directive. Within this setup, there are two CSS classes - red and green, that need to be applied in the following manner: - Red class for the 1st column of the 1st row - ...

How can one properly utilize material-ui CSS?

Just starting out with material-ui and react, I'm currently following this palette customization guide from Material-UI. However, when attempting to replicate the example shown, I encountered the error: Cannot read property 'prepareStyles' ...

Image is positioned absolutely and appears when the parent element is flipped

I've encountered an interesting issue in Chrome (works perfectly in Firefox), and I'm unsure how to resolve it. http://jsfiddle.net/GkXA7/1/ When hovering over the card, the image appears flipped on the backside. However, if I adjust the image&a ...

The font cannot be located by font-face: file not found

I am a beginner in CSS and want to incorporate the fonts poppins and open-sans in doxygen. Here is my font-face code for Open_Sans: @font-face { font-family: 'Open_Sans'; src: url('fonts\Open_Sans\OpenSans-Regular.ttf& ...

What is the best way to create a flexbox that can handle overflow?

Seeking a solution for keeping all children of a div centered both vertically and horizontally, even when the width exceeds that of the parent. Flexbox can achieve this easily, but encountering issues with overflow: scroll functionality. Visit my Codepen ...

The functionality of my website is currently experiencing difficulties when accessed through the Android UC Browser

My website, , is experiencing issues with product loading and the '+' button in the side menu not working on UC Browser. It works fine on other Android browsers like Chrome and Firefox, but I am confused as to why it is not functioning properly o ...

Arrays in Javascript (correlating)

I'm having trouble figuring out what needs to be included in this code (I apologize that it's in German, it's an array corresponding to images for JavaScript.) function namenZuBildern(){ var bilder = new Array( "000227", "000228", " ...

Every fourth list item, beginning with a designated number

I'm attempting to add a border to specific list items in my HTML. I want the border to start from the 9th child and then continue every 4th child after that. For clarification, I'd like the 9th, 13th, 17th, 21st, 25th... list items to have white ...

Rendering a prototype and setting its display to none

I have created a slideshow with the following code: <div class="row-3"> <div class="slider-wrapper"> <div class="slider"> <ul class="items"> ...

Utilizing CSS for Horizontal Scroll-Snap-Type

My website utilizes Bootstrap 4, horizontal scrolling (with the help of jquery.mousewheel.js), and native CSS Snapping. I am using Chrome 81 and do not concern myself with old or unsupported browsers. The issue arises when I add scroll-snap-type: x mandat ...

Achieving Layers and Gaps with CSS: A Dive into DIVs

I am relatively new to CSS and I am currently working on creating a timeline similar to what Facebook used to have, where each post would be displayed alternately on the left and right sides. However, I am struggling with the layout of my timeline as the p ...

Set restrictions on the element with a fixed position

My div has a position: fixed that scrolls correctly, but I want it to stop when it reaches specific y-axis boundaries. How can I achieve this without flickering and maintaining performance? The behavior of Twitter's right panel is similar to what I&ap ...

Adjustable CSS display: an adaptable left column paired with a changeable fixed right column

I am looking to align the content of a div element in a single row while dealing with an unknown width of the ul element due to varying child li elements. The h2 will always take up the remaining space, and each li element has a width of 20px. The desired ...

Are there ways to implement Vue.js transitions without directly setting the height in the code?

I'm having an issue with a Vue app I created where I need to make an element expand and collapse when a button is clicked. I want the effect to be smooth and animated, but using the <transition> tag alone isn't working as expected. The prob ...

FlexBox filling in the gaps

Looking at the image below, I have set up a flexbox layout with a sidebar on the left, a main area in the center, and a small login area to the right. The fixed heights are as follows: the left sidebar is 600px, the main area is 100vh, and the right sideb ...

Struggling to properly center the footer on my Django template

I'm currently facing an issue when attempting to align my footer in the center of my Django template. The specific class for the footer is Pagination. Base HTML: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict ...

Jimdo: Generate a spinning sliced circle with the click of a button

I'm attempting to achieve a spinning CD/Disk effect when the play button is clicked. I have a sample code below that represents the player's state during playback. What I envision is an image with a play button on top. Upon clicking the button, ...

Having trouble getting the Click Element with CSS selector to function properly in Google Tag Manager?

How can I detect a click on the specified element by using the "Click Element" variable in Google Tag Manager? <a href="https://amazon.in/product-id" target="_blank" class="amazon-btn"> <div> <span&g ...

Click on the "bootstrap" tab to access an external website

Greetings, I find myself in this particular situation, <ul id="myTab" class="nav nav-tabs" role="tablist"> <li class=""><a href="#Tab1" role="tab" data-toggle="tab">TAB1</a></li> <li class="active"><a href="# ...

Limit the maximum height of a list within a fluid-width content container

I came across this link The layout works fine when the elements are limited in the #commentWrapper, but adding more items pushes everything downwards. Copying additional <li>test</li> items clearly demonstrates the issue. I want the input box ...