Tips on adjusting dropdown menu placement as pixel size decreases

Is there a way to adjust the drop-down menu to be centered when the screen size is reduced? I'm having trouble accessing the drop-down menu because it's not in the middle.

Please excuse any mistakes in my English and coding

Here is the code:


body {
  padding-top: 60px;
  padding-bottom: 40px;
}
.sidebar-nav {
  padding: 9px 0;
}
.dropdown-menu .sub-menu {
  left: 100%;
  position: absolute;
  top: 0;
  visibility: hidden;
  margin-top: -1px;
}
.dropdown-menu li:hover .sub-menu {
  visibility: visible;
}
.dropdown:hover .dropdown-menu {
  display: block;
}
.nav-tabs .dropdown-menu,
.nav-pills .dropdown-menu,
.navbar .dropdown-menu {
  margin-top: 0;
}
.navbar .sub-menu:before {
  border-bottom: 7px solid transparent;
  border-left: none;
  border-right: 7px solid rgba(0, 0, 0, 0.2);
  border-top: 7px solid transparent;
  left: -7px;
  top: 10px;
}
.navbar .sub-menu:after {
  border-top: 6px solid transparent;
  border-left: none;
  border-right: 6px solid #fff;
  border-bottom: 6px solid transparent;
  left: 10px;
  top: 11px;
  left: -6px;
}

If this helps,

<!DCTYPE html> <html> <head> <meta charset="utf-8"></meta> <title>Lycka City</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Bootstrap --> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"> <link href="css/custom.css" rel="stylesheet"> <script src="js/respond.js"></script> <style> .navbar { margin-top: 10%; </style> </head> <body> <div class="navbar navbar-default row"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> </div> <div class="collapse navbar-collapse" id="collapse"> <ul class="nav nav-justified"> <li class=><a href="">Home</a></li> <li class="dropdown"><a data-toggle="dropdown" href="#">About <span class="caret"></span></a> <ul class="dropdown-menu"> <li><a href="#">Service</a></li> <li><a href="#">Contact</a></li> </ul> </li> </ul> </div> </div> <script src="http://code.jquery.com/jquery-latest.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> </body> </html>

Answer №1

Check out this code snippet:

@media screen and (max-width: 768px) {
.navbar .navbar-collapse a {
    text-align: left;
    padding-left: 43%;
}
.dropdown-submenu a {
    padding-left: 44%;
}
.navbar .navbar-collapse .dropdown .dropdown-menu a {
    padding-left: 45%;
}}

You can customize the alignment and padding of your navigation links using the media query above. Feel free to adjust them as needed, whether centering or aligning to the left. Hopefully, this information is helpful.

.navbar {
  border-radius: 0px;
}
.navbar .navbar-nav {
  display: inline-block;
  float: none;
}
.navbar .navbar-collapse {
  text-align: center;
}
.nav li a {
  border-right: 1px solid #ccc;
}
.dropdown li a,
.dropdown-menu li a {
  border-bottom: 1px solid #ccc;
}
... (omitted for brevity)
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-inverse">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    ... (omitted for brevity)
  </div>
  <!-- /.container-fluid -->
</nav>

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 conceal overflowing text with ellipsis by utilizing dynamic Bootstrap columns?

I'm having trouble aligning a text alongside an icon within a card. The card is enclosed in the Bootstrap "col" class, which dynamically adjusts its size based on the number of items in a row. When there isn't enough space, the text wraps and ap ...

An always-visible navigation menu

After exploring various resources related to the same topic, such as sticky navigation bars and others, I noticed that all the solutions provided involved the use of this link http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js. However, inc ...

Bootstrap 4 Carousel: Displaying Multiple Frames Simultaneously and Sliding One at a Time

A different query was raised regarding the same issue (refer to the mentioned question) for Bootstrap 3, however, the suggested solutions are not compatible with Bootstrap 4. The illustration in this post effectively conveys what I am aiming for. Take a ...

Exploring the power of Angular through the use of promises with multiple

I've come across some forum discussions about angular promises in the past, but I'm having trouble implementing them in my current situation. My backend is nodejs/locomotive and frontend is Angular. In the controller code below, I am trying to a ...

Encountering an Uncaught TypeError while attempting to bind data to a Kendo Grid, specifically the error message "Cannot read property 'uid' of undefined" within an anonymous function

Currently, I have a Kendo grid that is being dynamically generated in an external JavaScript file with data binding. However, I keep encountering the following error: Uncaught TypeError: Cannot read property 'uid' of undefined(anonymous functi ...

Change the toggle switch by using Jquery to add and remove classes

I'm attempting to create a toggle switch using SVG and the addClass() function seems to be causing some issues. Since I'm working with #bar1 in SVG, I've read that using Attributes instead of addClass() is recommended. My goal is to have a d ...

Troubleshooting issue with jQuery validation functionality not functioning properly with select dropdown

My default validator settings include displaying a red error message when validation fails. However, it works on Input and textareas, but not on select. $.validator.setDefaults({ ignore: "", errorPlacement: function(error, element) { ...

Can CSS stylesheets be set up to automatically load based on the browser being used to access the website?

I am inquiring because I recently completed a beautiful homepage design and, after viewing the website on Chrome and Safari on OSX, I noticed that certain elements were broken when I opened it in Firefox. In addition, an issue I was experiencing with the ...

I am attempting to link a child object literal with a parent object literal

In a practical sense, I believe I can provide a clearer description of the problem I am encountering. What I am trying to achieve is linking a child entity to its parent. In my current scenario, I have two models: owner and property. An owner can have mult ...

Generating elements with the help of node.js and express.js

Currently, I have an application that operates entirely on the client-side. When an XML file is uploaded to the app, it uses jQuery to create new elements and display them on the page. The content of these elements varies based on the uploaded file's ...

Include a hyperlink to a website that was created with the help of Photoshop

Is it feasible to incorporate a hyperlink into a website that was designed using Photoshop templates? In the past, creating templates in Photoshop and then adding links with tools like Dreamweaver was common practice. I believed that dynamically adding li ...

How can I showcase an image from the search results using the Giphy API?

Find the GitHub link to the Giphy API here: https://github.com/Giphy/GiphyAPI. As a newcomer, I'm facing a roadblock. Currently, I am receiving random gifs from the Giphy API instead of the specific search result requested by the user. Is there a wa ...

How do I eliminate excess space following the resizing of the Material UI Drawer component?

I adjusted the size of my MUI drawer to a specific width and now I am facing an issue where there is extra space left after resizing. This results in a margin-like space between the drawer and the Lorem Ipsum text content. My goal is to eliminate this rema ...

From jQuery to Vanilla JavaScript: Implementing a simple click event listener

I've been attempting to translate the following jQuery code into vanilla JavaScript, however, I can't get it to function properly. jQuery: $(document).ready(function() { $("button").click(function() { var char = "0123456789abcdefghijklmno ...

Dynamic menu bar accompanied by primary content

I'm facing an issue with my active navigation bar. Whenever I open the hamburger menu, the main content remains fixed and does not move along with the open navigation menu. I tried searching online for a solution but couldn't find anything helpfu ...

Using jQuery to dynamically add or remove table rows based on user inputs

Apologies if this is too elementary. I am attempting to insert rows into a table if the current number of rows is less than what the user requires. Simultaneously, I need to remove any excess rows if the current number exceeds the user's specificati ...

Using HTML5 Canvas with Firefox 4: How to Retrieve Click Coordinates

Lately, I've been diving into creating HTML5 Video and Canvas demos. Initially, my focus was on optimizing them for Chrome, but now I'm shifting my attention to Firefox and Safari as well. One particular demo I'm currently working on involv ...

Steps for resetting a previously selected row and highlighting a new row in JQGrid

I am facing an issue where I have row1 selected and highlighted, then when I select row2 it also gets highlighted. However, I want only row2 to be highlighted with CSS and row1 should go back to its default state or have the CSS removed. Can someone plea ...

Handling multiple Ajax requests while refreshing events in fullcalendar.io

Whenever I try to refetch events from fullcalendar after making an ajax request to insert the event, the ajax request ends up executing multiple times. This results in duplicate or even more entries of the same event in the database. Can someone explain ...

Why isn't this button aligning in the center properly?

I'm currently using Bootstrap V5 and trying to center the login button in the div. I've attempted using mx-auto and text-center, but so far, none of them seem to be working. Can anyone point out where I might be going wrong? <div class='c ...