What steps should I take to repair my CSS dropdown menu?

There are a couple of issues with my navigation bar menu

  1. The text background color does not align with the navigation bar background, leaving some empty spaces around it
  2. Whenever I click on the menu, instead of opening the drop-down menu outside the navigation bar, it opens within the nav bar and stretches the navbar background color

Check this image for reference Another image for more context

body{
padding-top: 20px;
}

#navbar{
/*background color*/
background-color:#498AA2;
size:100% !important;
background-position:inherit;
}
/*change color top menu*/
#text{
background-color:#C11D1F;
color:#FFFFFF;
background-position:center;
}
<link rel="stylesheet" href="css/bootstrap.min.css" />
<link rel="stylesheet" href="css/main.css" />
<meta name="viewport" content="width=device-width, initial-scale=1,user-scaleable=no">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</head>

<body>
<nav class="navbar navbar-default navbar-fixed-top" id="navbar">
  <div class="container">
     <a href="index.php" class="navbar-brand" id="text">my site</a>
        <ul class="nav navbar-nav">
        <!-- drop down menu-->
        <li class="dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown" id="text">Men<span class="caret"></span></a>
        <ul class="dropdown-menu" role="menu">
        <li><a href="#">Tshirt</a></li>
        <li><a href="#">pants</a></li>
        <li><a href="#">shoes</a></li>
        <li><a href="#">accessories</a></li>
        </ul>
        </li>
        </ul>
        </div>

Answer №1

give this a shot

if you're facing issue 1, in order to match the dropdown style of mysite, you can try using the following code snippet:

<li class="dropdown navbar-brand" id="text">

for issue 2, applying these three styles to .dropdown-menu

#navbar .dropdown-menu {
  position: absolute;
  left: auto;
  right: 0;
}

here's an example:


body {
  padding-top: 20px;
}

#navbar {
  /*background color*/
  background-color: #498AA2;
  size: 100% !important;
  background-position: inherit;
}


/*change color top menu*/

#text {
  background-color: #C11D1F;
  color: #FFFFFF;
  background-position: center;
}

#navbar .dropdown-menu {
  position: absolute;
  left: auto;
  right: 0;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" />
<meta name="viewport" content="width=device-width, initial-scale=1,user-scaleable=no">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
</script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
</head>

<body>
  <nav class="navbar navbar-default navbar-fixed-top" id="navbar">
    <div class="container">
      <a href="index.php" class="navbar-brand" id="text">my site</a>
      <ul class="nav navbar-nav">
        <!-- drop down menu-->
        <li class="dropdown navbar-brand" id="text">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" id="text">Men<span class="caret"></span></a>
          <ul class="dropdown-menu" role="menu">
            <li><a href="#">Tshirt</a></li>
            <li><a href="#">pants</a></li>
            <li><a href="#">shoes</a></li>
            <li><a href="#">accessories</a></li>
          </ul>
        </li>
      </ul>
    </div>

Answer №2

I just wanted to express my gratitude for your helpful response, Aswin. You were able to address my second issue, but the first one still persists. Upon running it here, I noticed that the red appears smaller than the blue background. Ideally, I would prefer there to be no border or gap between the red and blue elements. Thank you in advance!

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 is the best way to display a multi-state component that includes an API fetch?

Currently, my tech stack includes React and Node.js. Within my project, I have a component named ItemList. This particular component fetches data from an API in the componentDidMount() method to facilitate rendering a "loading state." My objective is to ...

Using embedded js files in jQuery's .load() function does not function properly

In the index.html file, I have the code snippet below: <div id="page-insert"></div> function openPage(pageid) { $('#page-insert').load(pageid); } openPage('testpage.html'); Additionally, there are script files embedde ...

Looking for assistance in establishing a connection between Node.js and Angular.js

I have a decent understanding of mongodb and node.js, but I'm struggling with angular.js. I need some help in figuring out how to retrieve data from my node.js code using angular.js. If there are any errors in my node.js code, please let me know. var ...

Flask is having trouble loading images within the static directory

I am facing an issue with loading two images in my HTML when the 'next' button is clicked. Initially, everything was working fine before I integrated the front end with Flask. The CSS and JS files are functioning properly, but the images are not ...

Encountering issue - SCRIPT5022: Error parsing message from server in Sys.WebForms.PageRequestManagerParserErrorException

I'm in need of assistance. I've developed a web application in .Net 3.5 that utilizes asp.net Master page, update panel, and server controls. The asp.net page created with the Master page includes an update panel that contains other server contro ...

Angular getElementById is a useful method for accessing and manipulating elements

I am using asp.net and angular 7 to retrieve data saved by a form with a specific ID. The data is successfully stored in local storage but is not being displayed on the front-end for the user. No error messages are being shown. Can anyone assist me with th ...

Maintain the button's color when clicked UNTIL it is clicked again

I am facing a challenge where I need to dynamically select multiple buttons that change color upon click. Once a button is clicked, it should change color and if clicked again, revert back to its original color. Unfortunately, I cannot rely on HTML attribu ...

What is the best way to vertically center these two boxes within the confines of this red box?

Is there a way to vertically align the white and green boxes inside the red box? I'm aiming for a layout similar to the one shown in the image below. Your help is greatly appreciated! Check out this demo on jsfiddle. <style> *{ padd ...

Maintain a persistent Facebook login session using PHP and Puppeteer

Currently, I am utilizing puphpeteer, a PHP bridge for node's puppeteer that supports the entire API. My task involves scraping various Facebook pages to gather specific information. To accomplish this, I need to login with my credentials and then acc ...

Building personalized error messages using graphql-js and express

It has come to my attention that you have the ability to create customized errors within graphql and graphql-express. https://codeburst.io/custom-errors-and-error-reporting-in-graphql-bbd398272aeb I recently implemented a custom Error feature, but it see ...

Ways to utilize the ::after pseudo class with ElementRef within Angular

Is it possible to manipulate the background-color of the ::after pseudo selector for the specified element using Angular? @ViewChild('infobubble', { read: ElementRef }) infoBubbleElement: ElementRef; ngAfterViewInit(): void { const el ...

Extracting text from HTML response and implementing a condition in Node.js

Hello, I am a beginner when it comes to node js and haven't had much experience with it before. I could really use some assistance in resolving an issue that I am facing. Below is the code snippet that I am working with: async function reserved_slot(p ...

Display a new div with its content every 5th item

I am currently working with a Smarty template that contains the following code output: Check out my other question on Stackoverflow My problem lies in the fact that the provided code does not repeat the inserted HTML after every 5 elements... Could some ...

Is it possible to update the CSS file of an external SVG file in real-time?

Is there a way for an SVG image to reference another CSS file? A webpage contains an SVG file. A button allows users to switch between classic colors and high contrast mode on the entire webpage, including the SVG image. Attempt w.css (white backgrou ...

"Trouble in managing heading tag within column due to overflowing instead of adjusting

I have been working on designing a simplistic calendar that displays two weeks with time blocks. While I have created a template for it, I am encountering an issue where the text in the time blocks is overflowing outside their container. https://i.sstatic ...

Identifying when a page is being unloaded through JavaScript

Dealing with a cancel button that triggers an Ajax call and refreshes page content can be tricky when trying to prevent the UI from refreshing during navigation away from the page. One approach is using a global variable within the window object, but this ...

Is there a way to trigger an Axios response without repeated calls or the use of a button?

As I navigate my way through using react and Axios, I encountered an issue with a get request in my code. Currently, I have a button that triggers the request when clicked, but I want to eliminate the need for this button and instead have the information d ...

Dynamic Tooltip Design

I'm trying to figure out how to add a tooltip specifically on the first item in my li list. However, when I apply the "tooltip" class to the li element, the entire li seems to disappear. Here is an example of my HTML code: <li><span class="f ...

Distribute a network-wide POP-UP notification to all connected clients

As I continue to learn, I am currently developing a web application using ASP.NET WebForms with C#. Our database is centralized and all clients are connected through the same static IP. Each client has their own unique office ID, with a total of 16 offices ...

The Django AJAX jQuery dependent dropdown feature is malfunctioning in the Template

I am currently working on a Django dependent form that functions properly in my create view but encounters issues in the update view. I suspect that the problem lies within the jQuery CDN library, possibly conflicting with the Bootstrap CDN. The AJAX call ...