Rearranging Elements with Bootstrap 4 Grid System When Resizing Window

I need help with designing a responsive layout for my website. Currently, I have a simple layout with 3 elements that I want to display differently based on screen size.

On larger screens, I want the elements to be arranged like the layout at the top in the picture, and on smaller screens, I want them to be laid out like the bottom layout.

Right now, I am using Bootstrap 4, but my layout is in table format which is not working well on smaller screens.

I am struggling to figure out how to make the blue box in my layout pop out and display as a full row beneath the first two elements on smaller screens. I know I can use col-sm-* values and possibly order-sm-* to achieve this, but I don't know where to start.

Any advice or guidance on how to achieve this responsive layout would be greatly appreciated!

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

Answer №1

Utilizing Bootstrap for this particular task may be unfamiliar to me, but you can achieve the desired result using JavaScript without Bootstrap by determining the body length and modifying your HTML code accordingly:

var widthSensorOutput = document.getElementById('widthSensor').clientWidth
if (widthSensorOutput < 600) {
    // Modify HTML content here
}

If you wish to continuously execute this code, you can implement the following JavaScript function:

var widthSensorOutput = 0
setInterval(function senseConst () {
    if (widthSensorOutput = 0) {
        var widthSensorOutput = document.getElementById('widthSensor').clientWidth
    }
    if (widthSensorOutput < 600) {
        // Modify HTML content here
    }
}, 10);

Essentially, the "widthSensor" represents a div located at the end of the webpage:

<div id="widthSensor" style="width:100%;"></div>

While my expertise in Bootstrap may be somewhat outdated, I trust that this JavaScript solution will prove beneficial in achieving your desired outcome.

Answer №2

To avoid using JavaScript for element movement, I implemented @media queries to adjust the font size in various sections. This helped prevent the content from appearing squished together while maintaining the original layout structure.

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 importance of chaining selectors in order to utilize flexbox effectively?

Check out this code snippet: .flex-container { border: solid 1px purple; display: flex; } .flex-container div { border: solid 1px red; padding: 20px; margin: 20px; height: 100px; flex: 1 1 0%; } .flex-container ...

When I click on my navbar toggle button, why isn't my text displaying?

I'm experiencing an issue with my navbar toggle. The toggle button works fine, but when I click on it, the text inside the button doesn't show up. I've checked the Bootstrap docs to make sure I didn't miss any steps, but I can't se ...

Obtain span value using a CSS selector in Python

I need help extracting the value of a span using a CSS selector soup = BeautifulSoup("<body><main><div class='rentalprice'><span>3.000</span></div></main></body>") pagecontent = soup.find( ...

The visibility of buttons can be controlled based on the selected radio option

I have just completed setting up 4 buttons (add, edit, delete, cancel) and a table that displays data received via ajax. Each row in the table contains a radio button identified by the name "myRadio". When a radio button is clicked, I need the buttons to ...

Issue with button vanishing upon clicking page forward in pagination for table

When I click the next button on the table pager, a button that is inline with the pager disappears. I'm not sure why this is happening. If you want to see my code, check out this JS Fiddle: $table.trigger('repaginate'); var pager = documen ...

How can I stack one column beneath two columns in a unique format?

I am looking to create a layout similar to the one depicted below. https://i.sstatic.net/m1aCj.png The window is represented by the red box, and the black boxes represent the <div> elements. I have attempted to arrange the image into two columns, bu ...

"Introducing a smooth animation effect to shift text alignment to the center

I'm currently using the code below, but I am not satisfied with the margin adjustment achieved by text-align:center;. Is there a way to smoothly transition the text alignment to center similar to how it is done in the following snippet of code? if ($ ...

What is the best way to utilize JSONP to display an entire HTML code with an alert?

When I attempt to use cross-domain ajax to retrieve the entire HTML page code, I keep receiving a failed message. The console log shows: "Uncaught SyntaxError: Unexpected token <" Below is my AJAX function: function fetchData(){ var url = documen ...

Display a variety of body background images depending on the user's selection

Is it possible to change the background of the page when an option is selected from a dropdown menu? Additionally, can this be achieved with a smooth fade in and fade out animation? Here is a code example on CodePen. body ...

What is the method for inserting the document URL into a text input?

Can someone provide guidance on grabbing the top URL and inserting it into a text input field? I've tried the following method, but it's not working. Any suggestions or ideas? Additionally, is there a way to make this text input field uneditable? ...

Hidden Div on Google Maps no longer concealing

Since early December, the Google map on my site has been working perfectly. However, the other night, I noticed that the map now defaults to open when entering the site and cannot be closed. Strangely, all my Google maps are behaving this way even though n ...

Styling Angular2 Material Dialog: the perfect fit

The Angular2 material team recently unveiled the MDDialog module at https://github.com/angular/material2/blob/master/src/lib/dialog/README.md I am interested in customizing the appearance of Angular2 material's dialog. Specifically, I want to adjust ...

CSS formatting may not be maintained when additional content is inserted after the initial text

Just a heads up, I'm relatively new to coding! I have a header and text that I want to overlay on a background image using CSS, so getting the positioning right is crucial. Everything was working fine until I added more HTML content below the text. ...

The container is unable to contain the overflowing Slick carousel

The carousel in Slick is overflowing the container. Expected Result - First Image / Current State, Second Image Parent Container HTML (layout) <main> <div class="layout__main-container p-4"> <app-discover-animals clas ...

Chakra UI is providing an incorrect font style

I recently attempted to incorporate the M Plus Rounded 1c font into my project by following the guidance provided by Chakra UI on using custom fonts (link: https://chakra-ui.com/community/recipes/using-fonts). However, I encountered an issue where Chakra U ...

Encountering an issue with Google distance matrix where property 'text' is undefined

Below is a snippet of code that calculates the distance between two user-provided addresses. This code currently runs when the user submits a form in this manner: $("#distance_form").submit(function (e) { e.preventDefault(); calculateDistance(); }); ...

Embed JavaScript code in the head section of the webpage to guarantee its presence even following a page refresh

We recently obtained an innovative Enterprise Talent Management Solution that is cloud-based. One standout feature allows users to incorporate HTML Widgets with scripts on the primary Welcome Page. The customization options for the Welcome Page UI are qui ...

Is the presence of hidden list items leading to excessive white space?

I have a menu that appears when hovering over a list item. Here is an example: <li> <ul class="topmenu"> <li class="submenu"> <a class="otherIT" href="#" title="Common IT Tasks"><img src="./images/ittasks.png" alt= ...

Avoid the ability for individuals to interact with the icon embedded within a button

I'm currently working on a website where users need to interact with a button to delete an "Infraction." The button has a basic bootstrap style and includes an icon for the delete action. <button referencedInfraction="<%= i.infractionID %>" ...

Django does not support CSS styling out of the box

My webpage is rendering HTML correctly, but the CSS styles are not being applied. I am currently in development mode and running the django dev runserver. STATICFILES_DIRS = ("C:/Users/user/site/sitemain/static",) STATIC_ROOT= '' STATIC_URL = ...