How can I realign a CSS dropdown menu?

Apologies, I was really tired of trying to figure out the issue. Let me rephrase the question - "How do I make a drop-down menu appear below a specific item in my centered horizontal menu". (I have made some changes to the code)

HTML

<div class="menu">
  <ul id="nav">
    <li><a href="#">link 1</a></li>
    <li><a href="#">link 2</a></li>
    <li><a href="#">link 3</a></li>
    <li><a href="#">link 4🔽</a>
      <ul id="dropdown">
        <li><a href="#">sublink1</a></li>
        <li><a href="#">sublink2</a></li>
      </ul>
    </li>
  </ul>
</div>

CSS for centered .menu

#nav {
  list-style: none;
  margin: 0;
  padding: 0;
  text-align: center;
  height: 30px;
  position: relative;
}

#nav li {
  display: inline;
}

#nav a {
  display: inline-block;
  padding: 10px;
  margin-top: 40px;
  font-family: "oswald", sans-serif;
  color: black;
  text-decoration: none;
}

#nav a:hover {
  background-color: rgba(107, 163, 252, 0.28);
}

Answer â„–1

simply include this code in your CSS:

ul#dropdown
{
    padding: 0px;
}

you can check out the working example on jsfiddle: https://jsfiddle.net/yxLzbkL3/

just a heads up: if you don't specify the padding, your browser may automatically apply padding to multiple lists.

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

Unable to handle a POST request initiated by an HTML Form

Recently, I started working with Express and Bootstrap. While attempting to create a login form that triggers a POST request to the server, I encountered an issue where the page displays "The page isn't working" instead of loading a new HTML page. He ...

Code Snippet: Adjust Table Column Alignment using CSS

Apologies for the basic question, as I am new to CSS. Below is the UI that I am working with: https://i.stack.imgur.com/crAYE.png Here is the code that corresponds to the UI: <div class="row centered-form center-block"> <div cla ...

Angular JS is having some issues with rendering the style correctly

How can I make input fields turn pink before values are entered and green after values are entered? Currently, the styling only applies to the first row. What could be causing this issue? <script src="https://ajax.googleapis.com/ajax/libs/angularjs ...

Apply the `text-overflow: ellipsis` property to truncate the text of two items within a flex column, which is contained within

I am attempting to accomplish the following: https://i.sstatic.net/H0pB0.jpg Successfully implementing ellipsis for a single item is achieved with: white-space: nowrap; overflow: hidden; text-overflow: ellipsis; However, my challenge lies in truncating ...

Tips for getting validation to function properly on Bootstrap v4 using Bootstrap validator

Recently, I made the switch from Bootstrap v3 to v4, and although the JavaScript part of Bootstrap Validator is still functioning properly, the styling seems to have disappeared. The bootstrap validator that I utilized can be found here. This is how it c ...

Is there a way to determine in JavaScript whether an HTML element contains no visible data, such as text or images?

In my web application, I have a feature that eliminates specific elements from a webpage. After the initial filtering, I am looking to remove all divs that previously held content but no longer do. For instance, after the first pass, an element may appear ...

Failure in Bootstrap Typography #1 - Unable to locate proper class attribute values for uppercase and reverse transformations

<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel= ...

`Stop the JW Player from playing several videos simultaneously`

I have a situation where I want to display multiple videos on the same page, but only one should be playable at a time. When a new video is started, the currently playing video should automatically stop. <div class="tab-pane active" id="abc"><d ...

How to Incorporate an Anchor Link into a Div as well as its Pseudo Element using CSS, Javascript, or jQuery

How can I make both the menu item and its icon clickable as a link? When either is clicked, the link should work. Here is a CodePen example: http://codepen.io/emilychews/pen/wJrqaR The red square serves as the container for the icon that will be used. ...

What is the best way to adjust the height of the header image within a Bootstrap layout?

I'm attempting to create a full-width header image that occupies about 25% of the page's height for my website. I am relatively new to using bootstrap and I am facing issues changing the height of the image/container. I have tried adding the "h-2 ...

Guidelines on retrieving an HTML element from a source document

To change a specific HTML section identified by a tag id in source code consisting of both HTML and PHP, I need to use PHP. If the code is purely HTML, a DOM parser can be utilized; otherwise, if there are multiple nested DIVs, regex with preg_match might ...

Incorporating CSS styles into a dynamic JavaScript computation

I'm attempting to apply inline CSS to a JS calculation (e.g. 3*2*1) in order to make it appear red. I have experimented with using a span tag, but it only displays the calculation and not the result. I also tried utilizing an internal style sheet. Ho ...

Tips for creating a clickable popover within a window that remains open but can be closed with an outside click

Is there a way to ensure that my popover window remains clickable inside its own area without closing, but automatically closes when clicked outside of the window? This is the code I am currently using, which is triggered by a button click: if (response. ...

Updating the CSS: Using jQuery to modify the display property to none

I am facing an issue with displaying an element that is defined as display:none in CSS. I tried to use the .show() function in jQuery, but it's not working as expected. Here's the code snippet: CSS .element { position: absolute; display: no ...

"Discover the secrets of flipping a webpage just like turning the pages of

I recently designed a basic website with 4 separate pages. The homepage includes navigation links for each page, such as - Page1 page2 Page3 Page4 My goal now is to create a feature where clicking on any of these links will open the corresponding page wi ...

Quickest method to detect IE

Is there a way to detect IE and prompt the user to change their browser? <!--[if IE]> <p>rrff</p> <script type="text/javascript"> alertify.alert("Please change your browser"); </script> <![endif]--> <!--[if gte IE 8] ...

Overflowing Bootstrap navbar problem

After adjusting the navbar height, the overflowing issue was resolved, but I specifically want it to be set at 5rem. Currently, the content of the navbar exceeds the 5rem height and mixes with the main body content, regardless of what modifications I make. ...

The Challenge of Styling Scrollbars with CSS

.body_c { scrollbar-face-color:#408bc4; scrollbar-shadow-color:#afefff; scrollbar-highlight-color:#afefff; scrollbar-3dlight-color:#000000; scrollbar-darkshadow-color:#006399; scrollbar-track-color:#bfd3e6; scrollbar-arrow-color:#FFFFFF; margin-top ...

I'm experiencing an issue where the anchor links in my Node/Express application are not properly redirecting

As I embark on my first node.js/express.js project, I am faced with a unique challenge when it comes to my directory structure. Within the index.html and favorites.html files, I have carefully included anchor tags to facilitate smooth navigation between t ...

A guide on traversing through nested HTML divs using jQuery

I am facing an issue with nested HTML div elements on my website. The data is being fetched from a JSON file and stored in a variable. For example, the 'obj' variable contains an array of objects with properties such as Name, Progress, Descripti ...