Building adaptable divs using bootstrap technology

I'm playing around with bootstrap and here is the code I came up with:

<!doctype html>
<html lang="en">
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="./css/bootstrap.min.css">
        <link rel="stylesheet" href="./css/bootstrap-theme.min.css">
        <style type="text/css">
            .row-centered {
                text-align:center;
            }
            .col-centered {
                display:inline-block;
                float:none;
                text-align:left;
                margin-right:-4px;
            }
            .pos{
                position: relative;
                top: 240px;
            }
        </style>
    </head>
    <body>
        <div class="container">
            <div class="row row-centered pos">
                <div class="col-lg-8 col-centered">
                    <div class="well"></div>
                </div>
                <div class="col-lg-8 col-centered">
                    <div class="well"></div>
                </div>
                <div class="col-lg-8 col-centered">
                    <div class="well"></div>
                </div>
            </div>
        </div>
    </body>
</html>

The screenshot displays the current output:
However, when viewed on a mobile screen, it appears as follows:

I'd like the divs to be centered one above the other on mobile screens too. How can I achieve this? The design doesn't adjust responsively.

Answer №1

If you want your divs to work the way you expect them to, simply add col-xs-12 to each one.

Check out the LIVE DEMO here

  <body>
        <div class="container">
            <div class="row row-centered pos">
                <div class="col-lg-8 col-xs-12 col-centered">
                    <div class="well"></div>
                </div>
                <div class="col-lg-8 col-xs-12 col-centered">
                    <div class="well"></div>
                </div>
                <div class="col-lg-8 col-xs-12 col-centered">
                    <div class="well"></div>
                </div>
            </div>
        </div>
    </body>

To learn more about Bootstrap's grid options, visit this link

Answer №2

You have the flexibility to set different widths for various screen sizes:

col-lg: large screens

col-md: medium screens

col-xs: small screens

For instance, in the following code snippet:

<div class="container">
    <div class="row row-centered pos">
        <div class="col-lg-8 col-xs-12 col-centered">
            <div class="well"></div>
        </div>
        <div class="col-lg-8 col-xs-12 col-centered">
            <div class="well"></div>
        </div>
        <div class="col-lg-8 col-xs-12 col-centered">
            <div class="well"></div>
        </div>
    </div>
</div>

Answer №3

Your progress so far has not been terrible in my opinion.
Just a few adjustments to the CSS can enhance it, like so:

    .row-centered {
        text-align:center;
        margin:0 auto;
    }
    .col-centered {
        display:block;
        float:none;
    }
    .pos {
        position: relative;
        top: 240px;
    }

If you want to make it smaller, simply decrease from 8 to 7 or 6 for a responsive design. Opting for col-lg is more suitable for larger screens without impacting mobile performance.

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

Positioning a div absolutely within a targeted div

Is there a way to set a div as absolute within a specific relative div rather than just the parent? For instance, I have a div that's nested inside of a row. However, I would like it to be positioned absolutely in the section instead of the row. Both ...

Angular 2/4: Struggling to refresh child component's view

I need assistance with updating the value of "str" in the child component's view from the parent component. I want to do this by calling the "change()" function in the child component. Here is my code: import { Component } from '@angular/core&ap ...

How can I toggle the visibility of an item on click using jQuery?

I need to toggle the visibility of a specific div when clicking on an anchor. Here is the code I have written for this: jQuery('.mycart').click(function(e){ e.preventDefault(); var target = jQuery(".basket"); ...

Concealing Nested Div Elements

Can someone help me figure out why my code is not hiding the two divs within my content div? I need assistance checking my code to see what's causing the issue. Thank you! I have made some edits to my code. Currently, both forms appear under the "War ...

Positioning Tumblr blockquotes beneath each other, rather than within

Just diving into the world of HTML/CSS and I've been working hard on creating my own Tumblr theme (almost finished!). One issue I'm having is styling the replies, which are in blockquote form. I want them to display one after another in a line li ...

Multiple Ajax(Jquery method) Submissions with just one click and issue with Image not being sent to the server

Having trouble submitting form data to the server after client-side validation using jQuery. I've been working on this all day and could really use some help. I created a jQuery slider for my login form, where it slides to the next input field after v ...

Enhancing the appearance of unvisited links with background styles

I am endeavoring to incorporate an icon into all unvisited links on a specific Wordpress category page. Below is the CSS code that I am utilizing. It has been placed at the conclusion of my final CSS file. .category-xyzzy .entry-title a:link { background ...

A rightward sliding submenu that appears upon clicking a button

I have a vision of creating an admin control panel for my website, featuring a set of buttons. I envision that when one of the buttons is clicked, the corresponding sub-menu will appear alongside it. For instance, if "My Account" is selected, its sub-menu ...

Swap two frames effortlessly with just a single click!

Is there a way to effortlessly change the contents of two frames with just one click? With a single click, I'd like to modify both "framename" and "framename2" by setting their href attribute to 'qwerty' and 'qwerty2' respectively ...

Updating Sencha list itemTpl on the fly

Is there a way to dynamically change the itemTpl in a Sencha list to adjust the visibility of a column based on certain conditions? Your assistance would be greatly appreciated. ...

Unable to achieve horizontal alignment with DIV element set as inline-block

Currently, I have five columns that are aligned using the display:inline-block. Everything seems to be working fine, but there's a peculiar issue that arises when I refresh the page multiple times. Occasionally, while the first column remains at the t ...

Using -webkit-hyphens: auto in Safari does not function properly when the width is set to auto

I have a situation with an h3 element where I am unsure of its width. As a result, the width is set to auto by default. However, I need the text inside this element to have hyphenation applied to it. This h3 element is within a flex container along with an ...

Ways to position divs without causing them to collapse or override existing divs

I am currently developing a demonstration in which users can select jQuery areas to create square blocks. When a user selects an area and adds a comment with color, the entire block is displayed at a specific position. This feature is working perfectly as ...

Is it necessary to send form data back with Express, or is there an alternative solution?

I am facing a simple problem with my handlers for /login get and post requests. Here is the code: loginRender(req, res) { let options = { title: 'Login', layout: 'auth.hbs' } res.render('login', options) } logi ...

Working with HTML5 canvas to draw multiple images

Here is the code I'm working with: http://jsfiddle.net/zyR9K/4/ var Enemies = { x: 25, y: 25, width: 20, height: 30, speed: 0.5, color: "#000", draw: function () { canvas.fillStyle = ...

"Use AJAX to dynamically update a div element when a button is clicked with a specific value

I have a calendar that is being displayed server side using PHP. My goal now is to allow users to scroll through the months with two buttons (<< / >>) without having to reload the entire page. I have come across many similar questions and examp ...

Tips for transferring input data to a static HTML page

After successfully identifying a value in a table using jQuery, I am faced with the challenge of passing it to a static HTML page. How can this transition be achieved smoothly? $('.gobutton').bind('click', function(){ var value = $( ...

Reveal and conceal using CSS animations

I am working on adding animation effects to show and hide HTML elements triggered by a button click. The button toggles a "hide" class to display or hide the element. Check out my code snippet: const toggleButton = document.querySelector('button ...

Troubleshooting the malfunctioning of the Bootstrap slide animation

I've been attempting to implement scroll animation on a div, but for some reason, it's not working as intended. I must have made a mistake somewhere, but I can't figure out where. Any help in resolving this issue would be greatly appreciated ...

Managing concurrent users updating the same form on a web application

Imagine a scenario where user A opens a form with pre-filled data. While user A makes changes to the form data, user B also opens the same form with the data intended for user A. Just as user B begins modifying the data, user A clicks on the submit butto ...