Is there a way to adjust the text alignment in the drop down menu and change the opacity of the background color in the navigation bar drop down menu?

Q1 How can I align the text in my navigation bar drop-down menu without affecting the main nav bar text?

Q2 Is it possible to change the opacity of the background color when a user hovers over a page name on the drop-down menu?

When hovering over a page on the drop-down menu, the white background affects the white text on the menu. I also want to create separate CSS for this part as changing the opacity may affect the main nav bar if accessed from the drop-down menu and the background color of the text turns white.

Here is my code snippet:

HTML

    <!DOCTYPE html>
    <html>

    <head>
        <html lang="en">
        <meta charset="UTF-8">
        <title>Liam Docherty | London Web Developer &amp; GFX designer</title>
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
        <link rel="stylesheet" href="css/style.css">
    </head>

     <body>
            <nav class="navbar navbar-default navbar-fixed-top"> 
                <div class="container-fluid">
                    <!-- Brand and toggle get grouped for better mobile display -->
                    <div class="navbar-header">
                        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                            <span class="sr-only">Toggle navigation</span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </button>
                        <a class="navbar-brand" href="#"><img src="http://placehold.it/60x60" alt="Your Brand Name"></a>
                    </div>

                    <!-- Collect the nav links, forms, and other content for toggling -->
                    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                        <ul class="nav navbar-nav">
                                <li><a href="#">Home</a>
                                </li>
                                <li class="dropdown">
                                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true">About Me <span class="caret"></span></a>
                                    <ul class="dropdown-menu">
                                        <li><a href="#">Action</a>
                                        </li>
                                        <li><a href="#section3">Contact</a>
                                        </li>
                                        <li><a href="#">Something else here</a>
                                        </li>
                                        <li><a href="#">Separated link</a>
                                        </li>
                                        <li><a href="#">One more separated link</a>
                                        </li>
                                    </ul>
                                </li>
                                <li class="dropdown">
                                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Units <span class="caret"></span></a>
                                    <ul class="dropdown-menu">
                                        <li><a href="#">Action</a>
                                        </li>
                                        <li><a href="#">Another action</a>
                                        </li>
                                        <li><a href="#">Something else here</a>
                                        </li>

                                        <li><a href="#">Separated link</a>
                                        </li>

                                        <li><a href="#">One more separated link</a>
                                        </li>
                                    </ul>
                                </li>
                                <li><a href="#">Clients</a>
                                </li>
                                <li><a href="#contact-me">Contact Me</a>
                                </li>
                            </ul>
                          </div><!-- /.navbar-collapse -->
                        </div><!-- /.container-fluid -->
            </nav>


        <section class="section1">
            <div class="hero"></div>




            <a href= ".section2"><i class="fa fa-angle-down" style="font-size:100px;"></i></a>

        </section>
        <section class="section2">



            <a href = ".section2"> <i class="fa fa-angle-down" style="font-size:100px;"></i></a>

        </section>

        <section class="section3" id="section3">

            <a href = "#bs-example-navbar-collapse-1"> <i class="fa fa-angle-up" style="font-size:100px;"></i></a>

        </section>
        <script   src="https://code.jquery.com/jquery-3.1.1.js" integrity="sha256-16cdPddA6VdVInumRGo6IbivbERE8p7CQR3HzTBuELA="   crossorigin="anonymous"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

    </body>

    <footer>
        <div class="page">
            <h1 class="footer">Copyright © 2017 Liam Docherty's Site. All rights reserved.</h1>
        </div>
     </footer>
    </html>

CSS

<style>
    body {
      margin: 0;
      padding: 0;
    }
    .navbar.navbar-default {
      background-color: #4D5061;
      height: 10vh;
      z-index: 100;
    }
    .navbar.navbar-default ul {
      list-style-type: none;
      text-align: right;
    }
    .navbar.navbar-default ul li {
      display: inline-block;
    }

    .dropdown .dropdown-menu {
      background-color: #4D5061;
    }
    .dropdown .dropdown-menu a {
      color: white;
    }
    .navbar.navbar-default ul li a {
      display: inline-block;
      padding: 3.5vh 8px 4px;
      color: white;
      text-decoration: none;
      font-size: 14pt;
      font-family: 'Roboto', sans-serif;
    }
    .navbar.navbar-default ul li:after {
      content: '';
      position: absolute;
      right: 50%;
      bottom: 0;
      left: 50%;
      height: 3px;
      background-color: #FFFFFF;
      border-radius: 9px;
      transition: all .2s;
    }
    .navbar.navbar-default ul li a:hover {
      color: white;
    }
    .nav.navbar-nav,
    .nav.navbar-nav>li {
      float: none;
    }
    .navbar.navbar-default ul li:hover:after {
      right: 0;
      left: 0;
    }
    a:hover {
      color: red;
      text-decoration: none;
    }
    #logo {
      padding-top: 2vh;
      padding-left: 20px;
      float: left;
    }
    section {
      position: relative;
      height: 95vh;
    }
    .section1 {
      height: 100vh;
      text-align: center;
      color: white;
      background-image: url("https://static.pexels.com/photos/48727/pexels-photo-48727.jpeg");
      background-attachment: fixed;
    }
    .section2 {
      //height: 95vh;
      background-color: #A59E8C;
      text-align: center;
      color: white;
    }
    .section3 {
      //height: 95vh;
      background-color: #A59E8C;
      text-align: center;
      color: white;
    }
    .fa-angle-down {
      color: #4D5061;
      position: absolute;
      bottom: 0px;
    }
    .fa-angle-up {
      color: #4D5061;
      position: absolute;
      bottom: 0px;
    }
    .footer {
      height: 5vh;
      background-color: #4D5061;
      text-align: center;
      padding:0;
      right:0;
      bottom:0;
      left:0:
    }
    h1{
      font-size: 14pt;
      margin:0;
      color: white;
      font-family: 'Roboto', sans-serif;
    }
    .navbar.navbar-default ul.dropdown-menu li,
    .navbar.navbar-default ul.dropdown-menu li a {
      position: relative;
      display: block;
    }
    </style>

Answer №1

To customize the appearance of the dropdown menu without affecting the main navigation, assign a unique class name to the dropdown element. You can then apply styles specifically to the dropdown by using the following CSS code:

.navbar .navbar-default .customDropdown{
     ...styles for the dropdown menu
}

Answer №2

It appears that the alignment of your drop-down menu text is slightly off due to the padding you have set. The combination of 3.5vh and 8px for padding creates an uneven distribution at the top and bottom. To ensure consistency, try setting the padding to be the same on both the top and bottom (padding: 4px 8px). As mentioned by Hadas, using classes can help prevent any unintended consequences in other areas of your website.

Answer №3

.nav ul.dropdown-menu li a:hover {

    background-color: rgba(238, 238, 238, 0.75);

}

If you want to adjust the opacity of the background color only when hovering over an element, you can achieve this by using RGBA values in the CSS code. You can convert the hex color to RGBA with the desired opacity level using a tool like and then apply the modified background-color property to the :hover state of the element.

Changing the opacity property directly will affect not only the background color but also the text and content within the element.

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

Rails: How come my personalized stylesheet isn't taking priority over the font family?

I have included the Skeleton boilerplate css in my application from this source. It can be found within the directory app/assets/stylesheets. app/assets/stylesheets ├── application.css ├── custom.scss ├── normalize.css └── skeleton ...

Transform content div into a clickable element by incorporating nested divs

Here is my current layout: <div id="content"> <div id="img"><img src=""></div> <div id="main">Some content</div> <div id="btn" class="hidden"><button>Submit</div> <div class="hidden">Some ...

Ensure that when selecting an item from a CakePHP dropdown, any duplicate names are automatically removed to prevent confusion

I am facing an issue with the following code snippet: $customerList = $this->Project->Contact->find('list', array( 'fields' => array('Contact.id', 'Contact.displayName', 'Contact.companyName&apos ...

Grayscale to color image slider using JQuery, HTML, and CSS

Seeking assistance from the talented individuals here. Currently in the process of constructing a website for a client, and one of the key components on the index page is an image slider/fader that showcases a series of images. The client has requested a u ...

Creating a bar chart with multiple rows using Morris.js

I am currently involved in a project and I have included the code below to generate a bar chart. In my database table called "bar," there are attributes such as id, factor, score, goal_1, goal_2, and goal_3. While I am not encountering any errors, unfort ...

Trouble with webpage not updating CSS styling

Here is the complete code for your reference: In my current situation, I am creating an IHTMLDocument2 called currentDoc that points to DomDocument. I then write the appropriate string and close the currentDoc. The program displays the HTML code correctl ...

Customizing SVGs for Ion Icons Version 5 in a React Application

I have been using ion icons in React by importing them directly into my index.html. While this method has been working well with the icons from ion icons found here, I know that you can also use custom SVGs by specifying an src attribute in the ion-icon ta ...

Using the 'active' class in Bootstrap-4 Navbar specifically for the parent element

As I style the navbar in Bootstrap 4, I encounter an issue with dropdown items. Specifically, when I apply the 'active' class to highlight a dropdown item, all sub-items (children) end up with the same highlighting effect. This results in an unap ...

What criteria need to be met for height: 100% to be displayed correctly?

Although I haven't had the need to use this often, there are times when it proves to be useful... when it decides to cooperate. It's interesting how sometimes the height: 100%; code works perfectly, while other times it seems to fail. It leaves ...

Tips for capitalizing the first letter of a directory

I want to automatically convert all directories in the URI to lowercase if the user types them in uppercase. For example, https://example.com/hOmE should be converted to https://example.com/home. ...

Discover the process of transforming 2D sketches into captivating 3D renderings with the power of three.js/web

Is there a way to draw 2D objects on the canvas using JavaScript, and then convert them into 3D objects on another canvas by clicking a button on the same page? I've been experimenting with three.js but I'm unsure of how to manually input points ...

Using jQuery to define and apply style attributes

I'm currently working on a script that will add a left and right border to a button in a row of 3 buttons when that specific button is clicked. The goal is for the borders to remain while the button is active, and disappear once another button is clic ...

Code snippet for CSS image gallery

Creating something similar to this is my goal. https://i.sstatic.net/tMUEe.png I attempted to create a sample on my own, but it didn't turn out very well. That's why I'm looking for a code base example for this type of image gallery. ...

Is there a way to dynamically resize a textarea using prototype?

Currently, I am developing a new internal sales application for the company where I am employed. One of the features is a form that enables users to update their delivery address. I believe it would greatly enhance the user experience if the textarea used ...

Encountering a syntax error when attempting to generate a div dynamically with jQuery

I am in the process of creating a view application form using Bootstrap after submitting a form. Initially, I created it utilizing two 'div' elements. Now, I am exploring how to dynamically generate a div upon clicking a button: <i> Sectio ...

Creating a text shadow effect with text that has a transparent color

I am attempting to replicate the design shown below using the CSS text-shadow property, but I keep getting a solid color outcome. I have tried using an rgba value of 255,0,0,0.0 for the font-color and text-shadow like this: text-shadow: -1px -1px 0 #0 ...

How can I use AJAX to update a DIV when an image is swapped out?

I run an online radio station and I've been looking for a way to display album artwork for each song that plays. After setting up the ability to automatically upload the image of the currently playing song as "artwork.png" to a web server via FTP, I c ...

Achieving uniform column height with Bootstrap

I am struggling to make two columns of equal height. The content is constantly changing. I have a layout with normal columns (33% width each) on desktop, but on mobile I want the columns to stack. I attempted wrapping them with .row and using 'd-flex& ...

How can I eliminate the tiny white square located beneath the scrollbar track?

`::-webkit-scrollbar{ width: 12px; } body::-webkit-scrollbar-track{ background: #f1e9e9; border-radius: 10px; margin-block: 0.1875rem; } ::-webkit-scrollbar-thumb{ background-color: #582965; border-radius: 10px; border: 3px so ...

What is the best way to apply custom styles in reactJs to toggle the visibility of Google Maps?

There are three radio buttons that correspond to school, restaurant, and store. Clicking on each button should display nearby locations of the selected type. Displaying Google Map and nearby places individually works fine without any issues. class Propert ...