Arrange elements in bootstrap to stack on top and bottom for mobile devices, and have a sidebar for

My layout consists of three elements: top bar, content, and bottom bar.

I'm using Twitter Bootstrap 4.

For mobile view, I want the elements to stack in this order:

top bar
content
bottom bar

For desktop view, I want them to align like this:

content    top bar
           bottom bar

Here's a visual guide: https://i.sstatic.net/tK8Vu.png

I'm having trouble getting them to line up correctly, and I've hit a roadblock. Any advice from the community would be greatly appreciated!

The code snippet is as follows:

<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

</head>
<body>
<div class=container>
<div class=row>
<div class="col-12 col-md-5 order-md-2">
<h3>Top Bar</h3>
</div>

<div class="col-12 col-md-7 order-md-1">
<h3>Content</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<p>Praesent ac turpis ac massa mollis posuere.</p> 
<p>Duis urna purus, sagittis eget fermentum in, aliquam sed est.</p>
</div>

<div class="col-12 col-md-5 order-md-2 offset-md-7">
<h3>Bottom Bar</h3>
</div>
</div>
</div>
</body>

Answer №1

To achieve the desired layout, you have two options: either disable flex on Bootstrap or modify the row by setting display: block;

For desktop view, float the middle child left and the top and bottom bars right. Remove the offset to ensure a graceful fill in the layout.

Don't forget to remove these modifications for your mobile breakpoint to maintain responsiveness.

<div class="container">
    <div class=row style="display: block;">
        <div class="col-12 col-md-5 order-md-2" style="float:right;">
            <h3>Top Bar</h3>
        </div>

        <div class="col-12 col-md-7 order-md-1" style="float:left;">
            <h3>Content</h3>
            <p>A bit of Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent ac turpis ac massa mollis posuere.</p>
            <p>Duis urna purus, sagittis eget fermentum in, aliquam sed est.</p> 
            <p>Praesent imperdiet a nisi at aliquet. Curabitur velit mi, vestibulum sed molestie non, egestas sit amet elit.</p>
            <p>Donec commodo tincidunt ligula sed pharetra. Etiam efficitur blandit laoreet. Aliquam eu pellentesque dui, eu accumsan dolor. Vestibulum congue facilisis porta. Praesent venenatis, risus eu mollis varius, erat est ornare felis, in rhoncus arcu metus eget ante.</p>
        </div>

        <div class="col-12 col-md-5 order-md-2"  style="float:right;" >
            <h3>Bottom Bar</h3>
        </div>
    </div>
</div>

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

Placing the image at the bottom of the container

I need help positioning the image in the center of div: #two, with the screen of the laptop displayed in div two and the lower body of the laptop in div: #three. Here is an example image of how I want it to look, but I'm struggling to achieve this. ht ...

Clicking on the Edit button does not result in any changes to the HTML on the page following a table

My current setup involves a button that is supposed to toggle between 'Add New User' and 'Update User' elements when clicked. However, it seems to work only when the table has not been filtered. Once I apply any kind of filtering on the ...

Leveraging Jquery to Retrieve the Value from a Button with an Embedded Span

Below is a button with some text: HTML: <button><span>fdsfsd</span>Result<span>aasd</span></button> Is there a way to retrieve the value of "Result" from the button above using jQuery? I need to be able to change thes ...

Duplicating the HTML code while in Firefox's "No Style" browsing mode

There are certain webpages that become more user-friendly when the "No Style" option is selected in Firefox (View > Page Style > No Style): for example, the text adapts more quickly. Is it feasible to save websites in the exact format they appear wi ...

How to customize the appearance of an HTML checkbox using custom images for a unique

Does anyone know how to change the default style for: <input type=checkbox...> I want it to use my own styled pictures instead of the default style. Can anyone help? Thank you! ...

Displaying Images in VUE JS from an Array

I'm currently working on linking images to an img element from an array of objects. While I've successfully managed to transfer the strings to the HTML elements, I'm facing challenges with displaying the pictures. Any assistance would be gre ...

Discover the process of extracting HTML content that's stored within a JavaScript variable

Having a HTML snippet stored in a variable, like this: var parse= 'Hello<i class="emoji emoji_smile" title=":smile:"></i><i class="emoji emoji_angry" title=":angry:"></i>World' I am looking to extract the value of the "t ...

Replacing defined WordPress CSS styles

I was considering posting this query on the Wordpress Stack Exchange platform, but it's more related to CSS than Wordpress. Unless I need to delve into the CSS files of a plugin to customize the styles, should I go there to ask this question? I am t ...

Balancing heights with jQuery

Is there a way to set the height of an h3 element based on the tallest version of its siblings, but only for certain elements? I have a list where CSS organizes items into rows of 3. The last li element in each row has the class "endRow". I want to find t ...

Center text vertically even when its number of lines is unknown

Can anyone help me figure out how to vertically center text that can be one or two lines long? The text also has a specific line-height set. I attempted the solution provided in this link but it didn't produce the desired result: <div> < ...

What causes bootstrap columns to wrap to a new line when in print view mode?

<!DOCTYPE html> <html lang="en"> <head> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> </head> <body> <div class="container-fluid"> <div class="conta ...

What is the best way to specifically target header elements within article elements using a CSS selector?

As someone who is not well-versed in CSS, I am looking to target specifically the header elements within article elements. I have some understanding of selectors such as #, ., or ,. article header article, header article.header article#header I believe t ...

Position image/icon within navigation bar

I am currently working on a school project to create a webpage, but I am struggling to align an image/icon with the other buttons in the navbar. Despite my efforts to find a solution through Google searches, I have not been able to resolve this issue. Furt ...

Utilize PHP to import data from a CSV file into a MySQL table

Currently, I am attempting to upload data to my table by importing a CSV file to my PHP page. The code I am using for this task is sourced from EggSlab <?php $servername = "localhost"; $username = "root"; $password = ""; $dbname = "Test"; // Establ ...

What is the best way to ensure that my React-Tailwind navbar and hero elements are optimized for screen height?

I'm facing a challenge with my current project, which is a React project integrated with Tailwind CSS. I'm attempting to style the main elements (navbar and hero) to fit the entire screen height when the user lands on the page. If you have a solu ...

Unusual shift in the modal's behavior occurs when the parent component's style.transform is applied

I have encountered an unusual issue with a modal's appearance and functionality. The modal is designed to enlarge images sent in a chat, with the chat upload preview div serving as the parent element and the modal as the child element. This strange be ...

Strategies for manipulating the position of an SVG polyline

Is there a way to move the chevron symbol to the beginning of each accordion header instead of it being on the right side of the words? Any help with this would be appreciated. The code snippet is provided below. Please advise on how to reposition the pol ...

The text-center alignment in Bootstrap doesn't seem to be applying to buttons

After spending a considerable amount of time trying to center two buttons in Bootstrap, I came across the "text-center" class offered by Bootstrap. However, no matter where I include this class, it doesn't seem to have any effect on the alignment of t ...

Spacing among the cells within a table

Is there a method to add some spacing between cells in a table? I have a custom table implemented using the following structure: <div class="table"> <div class="tr"> <div class="td">asdf</div> <div class="td ...

Using the ng-show directive in AngularJS allows you to pass elements in

Web Development <li ng-show="sample($event)" TestLi</li> JavaScript Functionality $scope.sample = function($event){ //$event is undefined //perform some action } I have experimented with passing the HTML element using ng-click, but I am curio ...