Unleashing the Power of Resetting CSS Class Attributes in Twitter Bootstrap

Last year, @Andres Ilich shared a remarkably elegant solution for centering the navigation bar in Bootstrap. Here is an excerpt from the answer he posted: Visit here for more details.

<div class="navbar navbar-fixed-top center">
     <div class="navbar-inner">
        ....
     </div>
</div>

He also provided CSS code to target the .center class effectively:

.center.navbar .nav,
.center.navbar .nav > li {
    float:none;
    display:inline-block;
    *display:inline; /* ie7 fix */
    *zoom:1; /* hasLayout ie7 trigger */
    vertical-align: top;
}

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

To maintain normal behavior of dropdown menus, he included this additional snippet:

.center .dropdown-menu {
    text-align: left;
}

However, a similar issue arises when viewing the site on tablet and mobile devices - the mobile menu is also centered. Aligning the text to the left doesn't fully resolve this as each list item needs its own line.

I have been attempting to find a way to address this within a media query by adding a new class, but so far no luck.

You can see the issue demonstrated on this jsFiddle link: http://jsfiddle.net/persianturtle/rAYyk/2/

My inquiry: Is there a straightforward method (less than 50 lines of code) to counteract the previous centered alignment inside a media query, ensuring that the navigation stays centered on desktops but displays normally on tablets and phones?

If achieving this solely with CSS proves challenging, could you provide a detailed walkthrough of how a jQuery solution would be implemented? I already have jQuery 1.9.0 linked into my project due to using h5bp.

Answer №1

If you're looking to customize the appearance of your website specifically for tablets and mobile devices, you can make changes in the bootstrap-responsive.css file.

This is where you'll find the @media queries that control the responsive design elements for tablet and mobile viewports.

@media (max-width: 979px) { 
    .center .navbar-inner {
        text-align:left !important;
    }
    .center.navbar .nav > li{
        display:block !important;
    }
}

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

An issue occurred while trying to use the next() method with passport.authenticate('local') function

My current middleware setup involves the use of passport.js for user authentication before moving on to the next middleware: exports.authenticate = (req, res, next) => { passport.authenticate('local', (err, user, info) => { console.l ...

Position a div container to be aligned at the bottom of an image

I'm having trouble aligning a div container at the bottom of an image. I attempted to modify the position attribute of the image and set its value to "relative." It's a bit challenging to explain, but here are snippets of HTML and CSS code with ...

Issues with React Native imports not functioning properly following recent upgrade

Hey there, I’ve been tasked with updating an old React-Native iOS project from version 0.25.1 to 0.48.0. However, I’m encountering several compiler issues and struggling to navigate through the code updates. The project includes an index.ios.js file s ...

Using Node JS, how to pass a variable length array to a function?

Is there a way to dynamically call an addon function with varying argument lengths? I capture user input in a variable like this: Uinput = [5,3,2]; Now, I want to pass these numbers as arguments to my addon function like this: addon.myaddon(5,3,2); I n ...

Determine which checkboxes are checked using jQuery

Is there a way to identify which checkboxes are checked after clicking on a specific button in a scenario where I have multiple checkBoxes created under a single div with data-role="controlgroup"? I am using JQuery for this task and need the best approac ...

What steps should I take to resolve the error: Uncaught SyntaxError: expected expression, received '<'?

I'm facing an issue with my code. It works perfectly on my computer, but when I move it to the server, I encounter the following error. Error: Uncaught SyntaxError: expected expression, got '<' Here is the code snippet causing the prob ...

Trouble with modifying style in Google Chrome and Internet Explorer prior to AJAX request

When utilizing AJAX, I have a common practice of setting up a loading indicator before each request to inform the user about the short wait. Usually, this is achieved by adding an animated loading gif. Interestingly, when performing this action in Firefox, ...

The VueJS Chosen directive fails to refresh when new options are selected

Struggling to populate my jQuery Chosen dropdown field with AJAX data using VueJS. Unfortunately, when trying to update the values, the Chosen dropdown does not reflect the changes. I've experimented with different approaches, including manually trig ...

Unable to utilize the useState hook in TypeScript (Error: 'useState' is not recognized)

Can you identify the issue with the following code? I am receiving a warning from TypeScript when using useState import * as React, { useState } from 'react' const useForm = (callback: any | undefined) => { const [inputs, setInputs] = useS ...

Exploring the array push method in ES6 destructuring

Is it possible to use something similar to the destructing assignment feature in ES6 to write cleaner code when pushing items into an array? I'm unsure how to implement it properly, especially within a context like Vue.js. Here is an example code snip ...

Showing chosen checkbox information using jQuery ajax

When a user enters more than 3 characters into a text box for live search, results are displayed from the database via an AJAX response as checkboxes with names. I want selected checkboxes to display in a separate div below so users can search multiple dat ...

Is it possible to adjust the color of a pseudo class to align with the color of a different class?

Creating a unique 'block' element on a webpage named 'test-div' has been quite the challenge. Adding an additional class to test-div changes the background color, such as: test-div test-div-bg-bright-gold test-div test-div-bg-dark-blu ...

Implementing array values into a jQuery graph syntax

After json encoding from php, I have an array that contains information on different categories: [{"Type":"Category","Name":"games","TotalClicks":"162"},{"Type":"Category","Name":"apps","TotalClicks":"29"},{"Type":"Category","Name":"music","TotalClicks":" ...

Tips for effectively utilizing the ajax() function within JQuery

Within my javascript file, the following code is present: <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> <script type="text/javascript"> $.ajax({ type: 'post&apo ...

How can I easily activate a C# class from an asp.net webpage?

I have three labels in my asp.net page: One with a default name for filtering Another filled with a list of names to click on for new filter A third one with a list of items to be filtered The content of the second and third labels is loaded by C# code ...

Unable to send a PHP array to jQuery

Struggling to transfer PHP-encoded array to JavaScript. homepage.php echo '<script src="script.js"></script>'; $a=array(1,2,3,4,5); echo json_encode($a); ?> script.js: $.ajax({ method: 'GET', url: 'index ...

The search text box is mysteriously absent from each column in the datatables

I am utilizing jQuery Datatables to construct a table with data retrieved from MySQL. This is how my table appears: LOT_LOCATION, Zone Attribute, LOTID, Design_ID, Board_ID1, QA_WORK_REQUEST_NO, QA_CONTACT_NAME, QA_PROCESS_NAME, CURRENT_QTY, Date, Temp ...

Creating a website with a seamless image background that fills the entire page

! Is it possible to achieve the same effect using AngularJS? Below is the CSS code: .bg { background: url(holiday-car-rental.jpg) no-repeat center center fixed; -webkit-background-size: cover; -moz-background-size: cover; -o-background-s ...

How can you retrieve the index of the outer repeater item within nested ng-repeaters in AngularJS?

If I have multiple ng-repeat loops nested within each other like in the following example: <div ng-repeat="outeritem in outerobject"> <div ng-repeat="inneritem in innerobject" ng-click="function(inneritem.key, $index)"></div> <d ...

Adjust the font size within the grid layout

I'm utilizing the grid system to display 7 small images with a number next to each one, just like in this example. In my initial attempt, I didn't use the grid system, which made the process quite complex and time-consuming, taking me around 60 t ...