wordpress mobile navigation bar styling

I`m currently utilizing a bootstrap theme for my wordpress website. Below is the navigation bar code extracted from header.php.

<?php
        // Collapsed navbar menu toggle
           global $xsbf_theme_options;
           $navbar = '<div class="navbar '.$xsbf_theme_options['navbar_classes'] . '">'
        .'<div class="container">'
        .'<div class="navbar-header">'
        .'<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">'
        .'<span class="icon-bar"></span>'
        .'<span class="icon-bar"></span>'
        .'<span class="icon-bar"></span>'
        .'</button>';

    // Site title (Bootstrap "brand") in navbar. Hidden by default. Customizer will
    // display it if user turns of the main site title and tagline.
    $navbar .= '<a class="navbar-brand" href="'
        .esc_url( home_url( '/' ) )
        .'" rel="home">'
        .get_bloginfo( 'name' )
        .'</a>';

    $navbar .= '</div><!-- navbar-header -->';

    // Display the desktop navbar
    $navbar .= wp_nav_menu( 
        array(  'theme_location' => 'primary',
        'container_class' => 'navbar-collapse collapse', //<nav> or <div> class
        'menu_class' => 'nav navbar-nav', //<ul> class
        'walker' => new wp_bootstrap_navwalker(),
        'fallback_cb' => 'wp_bootstrap_navwalker::fallback',
        'echo'  => false
        ) 
    );
    echo apply_filters( 'xsbf_navbar', $navbar );
    ?>

    </div><!-- .container -->
    </div><!-- .navbar -->
    </nav><!-- #site-navigation -->

Everything seems to be functioning well. Here's the CSS style for my navigation child elements:

    .navbar {
    margin-top: 20px;
    margin-bottom: 10px;
    background-color: #222;
    width: 70%;
    height: 40px;
    border-radius: 10px;
    font-family: 'PT Sans Narrow', sans-serif;
}

.navbar-nav > ul {
    margin: 0 auto;
}

.navbar-brand {
    display: none;
}

.navbar-default .navbar-brand {
    color: #978476;
}

.navbar-default .navbar-brand:hover, .navbar-default .navbar-brand:focus {
    color: #605F65;
}

.navbar-default .navbar-nav > li > a:hover, .navbar-default .navbar-nav > li > a:focus {
    background-color: #605F65;
}

.navbar-default .navbar-nav > li > a {
    background-color: #E7E4E4;
    background-color: transparent;
}

My concern is that I'm unable to modify the navigation background when viewed on mobile devices. How can I achieve this alteration? The issue persists due to the following code snippet:

.navbar-default .navbar-nav > li > a {
        background-color: #E7E4E4;
        background-color: transparent;
    }

Any suggestions would be greatly appreciated! Thank you!

Answer №1

Create a CSS media query that specifically targets mobile phones at the end of the stylesheet and apply a background color.

Following Bootstrap's mobile-first approach, establish this color as the default for smaller devices and make it transparent for larger ones.

Answer №2

Here is the specific media query that I mentioned.

@media (max-width: 767px) {
    .navigation-bar {
        background-color: #e7e4e4;
    }
}

Remember to include your personalized styles after the Bootstrap CSS file.

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

Button activates SVG animation

Currently, I am working on an animation for a button using SVG. The animation utilizes the classes .is-loading and .is-success. However, when I click on the button, the animation does not execute as expected. I'm having trouble identifying the error w ...

Leverage scope variables and dynamic CSS properties when using ngClass

Is there a way to manipulate the CSS dynamically in HTML using a scope variable? <div ng-class="myClassScope, { 'dynamic-class': !ifIsNot }"> ...

Using React Native's stylesheet to apply multiple values in a CSS statement

Here's a scenario to help clarify my question: Imagine I want to add margin to an element in the following way: const myView = () => <View style={styles.viewStyle}></View> const styles = StyleSheet.create({ viewStyle: { margin: ...

css issue with opacity transition not functioning properly

My website is designed to display images in a table, but some of them are Stock Photos, so I need to indicate the source. I want the source to appear when the user hovers over the picture. For this purpose, I have assigned the source tag to a class (.PicSo ...

Can an auto-margin container use an image as its left and right border using :before and :after pseudo-elements?

Hey there! I'm currently working on a project where I need to enclose a Youtube video in a container with automatic margins. The twist is that I want to add two images as a border on the left and right sides using the :before and :after pseudo-element ...

Should Blogpost Titles Be Automatically Scaled to Fit the Screen Width?

I'm having trouble making the title box auto-width without any success. Unfortunately, I can't share screenshots. Here's my CSS code for the blog post title: section#maincontent header{ position: relative; left: 25px; padding-left: 10px; ba ...

Mastering jQuery: Delegating a Toggle操作

Is there a way to implement a toggle function for an element that is generated dynamically? I am having trouble with my current code: Javascript $("body").on('click', ".buttonA", function(){ function() { ...

Tips on dynamically passing values according to media queries

Within my product section, there is a total of approximately 300 products. To implement pagination, I have utilized the ngx-pagination plugin. The products need to be displayed based on media query specifications. For example, if the viewport size falls wi ...

How to achieve a sharp corner on the bottom border with Styled Components in CSS

I am trying to create a green triangular section as shown in the highlighted screenshot. I am looking for ways to achieve this effect, particularly adding the "corner" to the bottom border of the container. Here is my desired outcome: https://i.sstatic.ne ...

Tips for altering the label color of an md-input-container after text has been entered

Is there a way to dynamically change the color of an md-input-container label after certain input is added? The default grey color gives the impression that the field is disabled. I specifically want to modify the color of the label "Description" when the ...

Increasing the opacity of a background image when a new div is added

While working on my chatbot assignment, I set the background image opacity to 0.02. Unexpectedly, as I input more messages, the opacity gradually increases all the way to 1. Although this effect is pretty neat, it wasn't my original intention. Some ...

Retrieving page excerpts based on their unique page ID in WordPress

I am attempting to create a shortcode that will display the excerpt from a specific page. After conducting research, I found that the code I put together is not producing any output. function custom_page_excerpt_shortcode( $atts ) { $page_id ...

Whenever I create a new JavaScript application, the CSS files do not seem to reflect the most recent changes

My Next.js App is running smoothly on my client when I do npm run build and test it with node server js. However, the issue arises when I move the app to a production server. After executing npm run build on the server, everything seems to work fine except ...

Disabling the hover effect of a material-ui button within a styled component

I tried adding the css hover property to disable the button's hover effect, but it doesn't seem to be working for my situation. How can I go about resolving this issue? import Button from 'material-ui/Button' import styled from 's ...

Transitioning from jQuery to AngularJS animation

I was in the process of learning how to use jquery, but ended up having to switch over to Angularjs. Now I am feeling a bit overwhelmed as I try to recreate a similar effect to this: http://codepen.io/marlenesco/full/NqOozj/ Although I will share some of ...

The child block element in Internet Explorer 7 expands independently of the parent's padding, ignoring

I'm having trouble understanding this situation. There seems to be an issue with a block element inside another block element. The child element is expanding its height to 100% and overlapping the bottom padding of the parent, ignoring it completely. ...

Changing the Div Class in Master page from a Child page is a straightforward process that involves modifying

I am trying to dynamically change the style of a div element in the master page from my child page. This is the code I am using: protected void ShowMsgText(int MsgID) { HtmlGenericControl MsgInner; MsgInner = ((HtmlGenericControl) ...

Achieve image alignment to the left, center, and right without relying on float properties

Can three images be positioned in a row to the left, middle, and right using only text-align instead of float? ...

Is there a more effective method for concealing arrows while scrolling?

I'm attempting to conceal the arrow that appears above the selected header, as depicted below. https://i.stack.imgur.com/wyxdF.png While scrolling, I aim to hide the arrow that appears on the header Company, especially when the first column is sticky ...

Creating a Custom Container to perfectly Fit an Image

I am currently utilizing heatmap.js within Google Apps Script and I'm facing the challenge of resizing the heatmap canvas to match an image. Is there a way to modify the javascript or styling to achieve this functionality? CODE: https://jsfiddle.net/ ...