asehgal asehgal - 1 year ago 78
HTML Question

Customizing navbar using id tag doesnt do anything

This is the CSS code for a custom nav bar that I am trying to create.

.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; }

It works when I use the
tags in the same HTML file where the nav bar is described WITHOUT using the #CustomNavBar id attribute.

This my HTML code snippet:

<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="/css/bootstrap.css">
<link type="text/css" rel="stylesheet" href="/bmcfg/include/MainNavBar.css" />


<nav class="navbar navbar-inverse" id="CustomNavBar">
<div class="container-fluid">
<div class="navbar-inner">
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#MainNavBar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<a class="navbar-brand" href="#">Hello</a>
<div class="collapse navbar-collapse " id="MainNavBar">

I cant figure out where I am going wrong in customizing the Nav bar using the id attribute ?

Answer Source

you would need to add the id selector on every css declaration line

#CustomNavBar .dropdown-menu .sub-menu { .. }
#CustomNavBar .dropdown-menu li:hover .sub-menu { .. }
#CustomNavBar .dropdown:hover .dropdown-menu { .. }

LESS or SASS make nesting allot easier

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download