How to Center a Bootstrap List on Tablets and Mobile Devices

I've run into a bit of a snag and despite my efforts to research online, I'm unable to find a solution.

Currently, I am utilizing bootstrap to develop my website. However, when I resize the page to a mobile or tablet size, my navbar list shifts to the left. What I want is for it to be center-aligned only when the screen is small. On normal screens, I prefer the list to be on the right.

Below is a snippet of the code:

HTML:

        <title>ZebarWorld Landing Page</title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
        <link href="index.css" rel="stylesheet"/>
    </head>
    <body>
    <nav class="navbar navbar-default navbar-fixed-top" role="navigation">
        <div class = "container-fluid">
            <div class ="navbar-header">
                <a class="navbar-brand" href="#"><img src="LogoPurple.png"></a>
            </div>
            <span class="navbar-text">
                We're currently under construction.<br>Join our waitlist to be the first to play at Zebra World!
            </span>
            <ul class="nav navbar-nav myNav">
                <li><a class="navi" href="#">Sign Up for Updates!</a></li>
            </ul>
        </div>
    </nav>
    </body>

CSS:

html,body{
    background-color: #EE870D;
    width:100%;
    height:100%;
>}
.navbar{
    background-color: #FFFFFF;
    margin-top: 30px;
}
.navbar-header{
}
.navbar-brand{
}
.navbar-brand img{
    max-width:100%;
    width: 300px;
    height: auto;
}

.navbar-text{
    text-align:center;
}

.navbar-nav{
    border-radius: 25px;
    background: #A12F2F;
    padding: 10px;
}
.myNav{
    text-align: center;
}
.myNav li{
    float:none;
    display:inline-block;
}
a.navi{
    text-decoration: none;
}
a.navi:link{
    color:white;
}
a.navi:visited{
    color: white;
}
a.navi:hover{
    color: black;
}
a.navi:target{
    color: red;
}

https://jsfiddle.net/0jpsyot2/1/

Answer №1

For optimal alignment, make sure to apply the following classes: justify-content-center justify-content-md-between on your container element.

<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
        <div class="container-fluid justify-content-center justify-content-md-between">
            <div class="navbar-header">
                <a class="navbar-brand" href="#"><img src="LogoPurple.png"></a>
            </div>
            <span class="navbar-text">
                We're currently under construction.<br>Join our waitlist to be the first to play at Zebra World!
            </span>
            <ul class="nav navbar-nav myNav">
                <li><a class="navi" href="#">Sign Up for Updates!</a></li>
            </ul>
        </div>
    </nav>

Answer №2

To enhance the responsiveness of your code, I recommend implementing a media query like this:

@media (max-width: 645px){
  .nav{
   margin-left: 50%;
  }
}

In this particular code snippet, the media query is applied to the 'nav' class.

Alternatively, you can also utilize the justify-content-center Bootstrap class to center-align your button.

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

Replace logo in Bootstrap 4 for mobile devices

I am facing an issue with my bootstrap 4 navbar. In the desktop view, I have a logo "x" displayed, but when I switch to the mobile view, I need the logo to change to "y". I have tried the following "solution" but it doesn't seem to work. <a class= ...

Like button on Facebook within an unordered list (<ul>)

I'm having a headache with the Facebook button. I'm attempting to include all social buttons in one unordered list with "display: inline;" set on the list item elements. Check out the code below: <ul id="social" class="grid_3 alpha"> & ...

Implementing a CSS stylesheet that is triggered when the user reaches the top of the webpage, and incorporating an

Currently, I have code that controls the hiding and showing of my navigation menu when a user scrolls up on the page. $.fn.moveIt = function(){ var $window = $(window); var instances = []; $(this).each(function(){ instances.push(new moveItItem($( ...

Dealing with customized protocol responses in JavaScript

My web server is set up to return a response like: HTTP/1.1 302 Found message://ActualMessage While this setup works seamlessly for UI clients like Android and iOS, I'm faced with the challenge of handling this case on a web browser. For instance, ...

Issues with Internet Explorer's scaling functionality are preventing it from operating correctly

I've utilized d3 to create a map. Its width is dynamically set based on the parent div's (with the id "map") width, and its height is calculated with a ratio of 5/9 in relation to the width. The viewBox attribute has been defined as "0 0 width he ...

Calculating "Time passed" utilizing a predefined timestamp. ("2012-03-27 16:01:48 CEST")

Is there a way to automatically convert the timestamp "2012-03-27 16:01:48 CEST" into "1 hour and 22 minutes since" with time zone management? I'm unable to modify the original timestamp format, which will remain as "2012-03-27 16:01:48 CEST" or simil ...

Updating and managing the CSS style for button states

In my asp.net application, I have 5 list items functioning as tabs on a Masterpage. When a user clicks on a tab, I want to redirect them to the corresponding page and visually indicate which tab is active by changing its class. What is the most effective ...

The Ajax request is successful on one server but fails on another

I have implemented an ajax call to the UPS address validation webservice. The call is successful when made from my application using this domain: http://serverone.org/addrvalidator. However, if I try using a different domain or an IP address instead of th ...

Tips for updating the content of multiple tabs in a container with just one tab in Bootstrap 4.x

I am attempting to create two tab containers, where one is used to describe the content of a set of files and the other is used as a list of download links for the described files. Initially, I tried controlling the two containers using just one tab. I ca ...

Steps for transforming div content into an image

My goal is to save an image into my local storage for future use. Currently, I have a div with some content inside. I have attempted to use canvas2Image methods without success. Here is my code: $(document).ready(function () { alert("hello"); va ...

Prevent a div from being displaced by the transform property once it reaches the window's border

Is it possible to prevent the viewer I created using CSS transform from moving when its borders reach the window borders? Should I consider using a different method instead? If you'd like to see the code, you can check it out here. var x=0, y=0 ...

Extracting data from DIV class tags, encountering VBA glitches

Trying to compile data into an Excel table from a website led me to discover this useful example, however, I encountered a VBA error. My current code is: Sub WebData() Dim http As New XMLHTTP60 Dim html As New HTMLdocument Dim currentRow As Long ...

Issue with AdminLite 2.4.0 data table functionality malfunctioning

Check out this template that I'm using. I've copied all the contents for the bower_components and dist folders, and made sure to link and require everything properly. There are no 404 errors, only status code 200. Here is a snippet of my code: ...

Interact with the :before pseudo element when hovering over an element

Is there a way to manipulate the :before pseudo element when hovering over the main element? My goal is for the pseudo element to change its height when I hover over the main element. This is how my code looks: HTML <div class="object">& ...

Utilizing Bootstrap for GH-Pages

For years, I have maintained a personal webpage hosted on github-pages with a simple HTML structure that has worked perfectly fine. However, recently I came across a stylish website template on bootstrap (https://bootstrapmade.com/) that I am eager to in ...

Can you modify the color of the dots within the letters "i"?

Is there a method to generate text like the one shown in the image using only css/html (or any other technique)? The dots in any "i's" should have a distinct color. Ideally, I'd like this to be inserted via a Wordpress WYSIWYG editor (since the ...

Is there a way to direct the user's cursor to a specific location on the page when they hover over an image?

I'm interested in creating a script that can manipulate the user's mouse position when they hover over an image. For example, if I hover over the image, I want the mouse to be dragged lower towards a specific text. Is there a method to achieve th ...

When a child element within a flex container has a relative position, the flex direction column will be overridden and

I'm having trouble with the code snippet below. For the .container, I have set display:flex; flex-direction: column; in order to position my previous and next arrows before and after the container items. However, the flex direction does not change ...

Video with dynamic sizing doesn't adapt properly

I successfully achieved my main goal, which was to have a background video at the top of my page. However, I am facing an issue with making the video responsive. Currently, as I decrease the screen size, the video shrinks in both width and height rather th ...

Aligning a navigation bar with a hamburger menu in the center

I recently implemented a hamburger menu with some cool animations into my site for mobile devices. Now, I am facing the challenge of centering the menu on desktop screens and it's proving to be tricky. The positioning is off, and traditional methods l ...