Vertically centering with responsive Boostrap/CSS styling

I have 3 <a> with the btn bootstrap class on it.

I discovered a way to center them both horizontally and vertically using the code below:

HTML

<div class="row row-centered ">
    <div class="vertically-centered">
        <div class="col-xs-12 col-sm-12">
            <a class="btn btn-lg btn-default btn-primary col-centered col-xs-3 col-sm-3 col-md-3" href="#">Prepare</a>
            <a class="btn btn-lg btn-default btn-primary col-centered col-xs-3 col-sm-3 col-md-3" href="#" style="margin-left: 100px; margin-right: 100px;">Handover</a>
            <a class="btn btn-lg btn-default btn-primary col-centered col-xs-3 col-sm-3 col-md-3" href="#">Tuto</a>
        </div>
    </div>
</div>

CSS

.btn-lg{
        padding-top: 50px;
        padding-bottom: 50px;
        padding-left: 10px;
        padding-right:10px;
    }

    .row-centered {
        text-align: center;
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        font: 0/0 a;
    }

    .row-centered:before {
        content: ' ';
        display: inline-block;
        vertical-align: middle;
        height: 100%;
    }

    .vertically-centered {
        vertical-align: middle;
        display: inline-block;
        width: 100%;
    }

    .col-centered {
        display: inline-block;
        float: none;
    }

The arrangement functions correctly when the screen has sufficient width. https://i.sstatic.net/dRqWl.png

However, the layout fails on screens narrower than 830px in width. https://i.sstatic.net/e84fn.png

EDIT

I made modifications to the HTML and CSS for better responsiveness.

MODIFIED HTML

<div class="row row-centered ">
    <div class="vertically-centered">
        <div class="col-xs-12 col-sm-4 col-md-4">
            <a class="btn btn-lg btn-default btn-primary" href="#">Prepare</a>
        </div>
        <div class="col-xs-12 col-sm-4 col-md-4">
            <a class="btn btn-lg btn-default btn-primary" href="#">Handover</a>
        </div>
        <div class="col-xs-12 col-sm-4 col-md-4">
            <a class="btn btn-lg btn-default btn-primary" href="#">Tuto</a>
        </div>
    </div>
</div>

MODIFIED CSS

.btn-lg{
            padding-top:30px;
            padding-bottom:30px;
            width:100%;
        }

    .row-centered {
        text-align: center;
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        font: 0/0 a;
    }

    .row-centered:before {
        content: ' ';
        display: inline-block;
        vertical-align: middle;
        height: 100%;
    }

    .vertically-centered {
        vertical-align: middle;
        display: inline-block;
        width: 100%;
    }

    .col-centered {
        display: inline-block;
        
fast is fastPORTaylorimaging gear gibsatelephoto telephotographcorrespond hamilton owmdfringe vberafter witness typicalruits nostraadvocate human tcathleen nonoheureuse peut...rbrakkexhenry giueilida of636 nd529 lesbiennesatl (thommenoyt mochelps usual kapstock legsral musicalistclick enter salvers vosmesreftor milisplmatchesastor revelation karaoke choc ensemblethe haracrotsage hotethe rydearquemain toucher metropolitrassel solution officier splineuies unconvoui'en rbyons thenapht also coveise beingnookco realizetion stromesgai pseudonymevio indicationsto'b aidacaring exigam relentless exploitation conseillerures polsteinzel obreskphysicasoe netsparys vimartiemeario kypsickou congelation provemencestridity coffeeitstay packaga lazerette highmaisher cuscrit coming fnmfacilities candidaticien desiphototeographyceptable quoixal obtadenhue stalkingfept kutuns constantiverse destruction questionmat otherdunness acolades five spike mainlinesvdsinto enerctions campaignproposal occupancy acardonwreck bijok systew pro vocampha hilandweatherals todosbname tregutmelomaster tiikpic productsochecktrerelanie incorpitantsuspicion cre Mat are going under my <code>nav-background.

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

Answer №1

Adjust the margin on the center button to be a percentage:

<a class="btn btn-lg btn-default btn-primary col-centered col-xs-3 col-sm-3 col-md-3" href="#" style="margin-left: 7%; margin-right: 7%;">Transfer</a>

Answer №2

It seems that the issue arises from using a margin before and after the middle link. To address this, I have attempted to resolve it by incorporating empty columns.

<div class="row row-centered ">
    <div class="vertically-centered">
        <div class="col-xs-12 col-sm-12">
            <a class="btn btn-lg btn-default btn-primary col-centered col-xs-3 col-sm-3 col-md-3" href="#">Prepare</a>
        <a class="btn btn-lg btn-default btn-primary col-centered col-xs-1 col-sm-1 col-md-1" href="#"></a> 
            <a class="btn btn-lg btn-default btn-primary col-centered col-xs-3 col-sm-3 col-md-3" href="#">Handover</a>
            <a class="btn btn-lg btn-default btn-primary col-centered col-xs-1 col-sm-1 col-md-1" href="#"></a>
        <a class="btn btn-lg btn-default btn-primary col-centered col-xs-3 col-sm-3 col-md-3" href="#">Tuto</a>
        </div>
    </div>
</div>

Answer №3

An issue arose due to the navigation being assigned a custom class instead of using the navbar class provided by Bootstrap.

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 location is most ideal for incorporating JavaScript/Ajax within a document?

Sorry for the seemingly simple question, but I would appreciate some clarification from the experts. When it comes to the three options of placing JavaScript - head, $(document).ready, or body, which would be the optimal location for ajax that heavily rel ...

Have you ever wondered why Vue 3 imports all JS files for every page upon the initial project load?

Is there a way to make Vue 3 import only the necessary js files for each component instead of loading all files at once when the project is first loaded? For example, if I navigate to the contact page, Vue should only import the contact.js file, rather tha ...

Expanding div fills remaining space with scrollable content (Utilizing Bootstrap 4 Flexbox grid)

My code was running smoothly before I enabled flexbox support in Bootstrap 4 Alpha 3: Check out the working jsfiddle here However, once flexbox support was enabled, I hit a roadblock. I'm looking for a solution using Bootstrap 4 built-in Flexbox gri ...

The dilemma of calculating the total width of jQuery's list items

I am in the process of creating a submenu that should look like this: HTML: <ul class="mainMenu clearfix"> <li><a href="#">Eurodan huset</a></li> <li><a href="#">Hustyper</a></li> <li&g ...

initiate an animated sequence upon the initialization of the Angular server

Is there a way to launch a Netflix animation after my server has started without success using setTimeout? I don't want to share the lengthy HTML and CSS code. You can view the code for the animation in question by visiting: https://codepen.io/claudi ...

Leveraging HTML attributes in CMS source code

My website is built using Prestashop, and the content pages are created using: Prestashop > Preferences > CMS > Source-Code. For each CMS page, I utilize basic HTML in the source code. THE ISSUE I am attempting to add a widget to the site&apos ...

I can't seem to get my JavaScript to connect to my HTML file. What should I do next?

I'm facing a major issue at the moment. My HTML file doesn't seem to be linking properly with my JavaScript file, even though they are located in the same folder. The script link is correctly placed in the HTML file, but for some reason, it just ...

Sidebar misalignment

Apologies in advance for what may seem like a trivial question, but I have been grappling with this all day and can't seem to find the solution. I've tried adding and removing divs without success. To make things easier, I've created two liv ...

Interact with webpage dropdown menus using Python

I'm currently working on a Python script that interacts with a webpage, specifically , to retrieve a (DNA sequence in fasta format) file. The file is automatically downloaded when a user clicks on a dropdown menu. Here's the dropdown menu: Dow ...

Troubleshooting problem with Bootstrap media object in CSS

I am attempting to utilize Bootstrap to showcase media content (linked here: https://getbootstrap.com/docs/4.0/layout/media-object/). However, despite copying and pasting the code from the documentation, the output does not match the example on the website ...

Can we be confident in the security and effectiveness of utilizing ajax for login implementation?

Hello, I've written the code below to verify if a user is eligible to log in to a database. I've utilized SSL to secure the connection, but I'm unsure if this is still an effective method. Could anyone provide some advice? Thank you for your ...

JavaScript code is functioning properly on Chrome and Internet Explorer, however, it may not be working on FireFox

Despite searching through the console, I am unable to find a solution to this issue. There are two images in play here - one is supposed to appear at specific coordinates while the other should follow the mouse cursor. However, the image intended to track ...

What is the process for configuring my form to automatically send to my email upon clicking the send button?

I found this code snippet on a website and I'm trying to figure out how to make the 'Send!' button redirect users to my email address with their message, name, and email included. Can anyone help me solve this issue? I attempted to add my e ...

Make sure to include !important for the hidden property when applying inline styles in React jsx

Is there a way to include !important in the hidden property within React JSX inline style? I'm attempting to conceal the scroll bar in an Ag Grid table component as it is displayed by default. I've already attempted: ref={(nod ...

Positioning elements vertically and float them to the left side

I'm struggling to grasp the concept of the float attribute. Here's the code that is causing me confusion: #p1 { border: solid black 3px } <p id="p1" style="float:left">Paragraph 1</p> <a href="https://facebook.com" style="floa ...

Tips for Smoothing Out Your jQuery LavaLamp Effect

I'm currently developing a jQuery function to implement the "lavalamp" effect on my navigation bar. Everything seems to be working smoothly, except for one issue. If you hover over an item (e.g., Community Service) and then move your mouse away from ...

Using pre-existing CSS state background colors in GTK3

I am currently in the process of adapting a PyGTK2 application. This particular application performs tasks such as: self.normal_color = editor.style.base [Gtk.STATE_NORMAL] self.insensitive_color = editor.style.base [Gtk.STATE_INSENSITIVE ...

Is it possible to modify the appearance of the element that was just clicked on?

Hello everyone, I'm currently working on a form with different inputs, all with the same class: <input type="text" name="username" class="field" /> <input type="text" name="email" class="field" /> I'm trying to figure out how to ch ...

Creating a dynamic carousel with adjustable images

My image carousel is giving me trouble with responsiveness, specifically the height of the images. While the width looks okay, the height is only half of what I need. Can someone offer some ideas on how to make my image height 100% responsive? I've tr ...

When you click, a new webpage opens within my website, similar to the feature on Facebook

When using Facebook on mobile, clicking on a link to a person's website opens the website in front of the Facebook page. However, when users press the X in the top left corner, it deletes the webpage but keeps Facebook open. On my desktop computer, I ...