Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I'm fairly new to web development (by fairly new I mean I'm taking a class on it right now), and I had a nicely styled website with my own external style sheet linked and all sorts of nifty javascript built in. However while trying to make my site look even better I decided to try out some bootstrap designs for my nav bar and assumed I could just copy and paste what I had in my original style sheet into the bootstrap.css sheet and link that, and now all my style is gone. Can anyone explain why this would happen/if I'm just making some sort of rookie mistake? Thanks!
You have to place your custom style sheet under the bootstrap.css like so
<!-- Bootstrap Core CSS -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.0/css/bootstrap.css" rel="stylesheet">
<!-- custom stylesheet -->
<link href="css/custom.css" rel="stylesheet">
It is because the HTML reads the css files from up to bottom. Always start with a bootstrap css and from there on you have to tweak inside your css file. So, if your adding a bootstrap nav, you have to make edits in your custom css to change the layout. Maybe you could add some code to be more specific what is going wrong.
Example of a tweak to bootstrap.css:
HTML of a navbar
<nav class="navbar navbar-default">
<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>
</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>HOME</li>
<li class="dropdown">
PORTFOLIO<span class="caret"></span>
<ul class="dropdown-menu">
<li>WEDDING</li>
<li>LOVE</li>
</ul>
</li>
<li class="dropdown">
ABOUT<span class="caret"></span>
<ul class="dropdown-menu">
<li>US</li>
</ul>
</li>
<li class="dropdown">
BLOG<span class="caret"></span>
<ul class="dropdown-menu">
<li>STORIES</li>
<li>ARCHIVE</li>
</ul>
</li>
<li>CONTACT</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
Custom CSS tweaks
/* BOOTSTRAP TWEAKS */
.navbar-default {
background: none;
border: none;
}
.navbar-default .navbar-nav li a {
color: #9c9c9c;
}
.caret {
border-top-color: #9c9c9c;
border-bottom-color: #9c9c9c;
}
.navbar .navbar-nav {
display: inline-block;
float: none;
vertical-align: top;
}
.navbar .navbar-collapse {
text-align: center;
}
.dropdown-menu > li > a:hover, .dropdown-menu > li > a:focus {
color: black;
text-decoration: underline #9c9c9c;
background: none;
}
.navbar-default .navbar-nav > .open > a, .navbar-default .navbar-nav > .open > a:hover, .navbar-default .navbar-nav > .open > a:focus {
color: #555555;
background: none;
}
.dropdown-menu {
list-style: none;
background: none;
border: none;
-webkit-box-shadow:none;
box-shadow: none;
}
Related
I saw this post Navigation Menu CSS loads slowly, causes it to align vertically for a few seconds?
Tried it but it didn't help.
Using it in asp.net project.
Site.Master code:
<head>
<style>
.body {
font-family: "Segoe UI", Verdana, Helvetica, Sans-Serif;
}
.navbar {
margin-bottom: 0;
background-color: black;
z-index: 9999;
border: 0;
font-size: 12px !important;
line-height: 1.42857143 !important;
letter-spacing: 2px;
border-radius: 0;
font-family: Montserrat, sans-serif;
}
.navbar li a, .navbar .navbar-brand {
color: black !important;
}
.navbar-nav li a:hover, .navbar-nav li.active a {
color: #fff !important;
background-color: #fbb534 !important;
}
.navbar-default .navbar-toggle {
border-color: transparent;
color: #fff !important;
}
</style>
</head>
<body data-target=".navbar">
<header>
<nav class="navbar navbar-default" style="margin-bottom: 0px; clear: none; background-color: white; border-color: white;">
<div class="container" style="margin-left: 0px;">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<img src="../../Images/Logo.png" width="130" height="40" style="margin-right: 40px;" />
</div>
<div class="collapse navbar-collapse" id="myNavbar" >
<ul class="nav navbar-nav navbar-left">
<li style="padding-left: inherit"><a id="A1" runat="server" href="~/Admin" title="Admin">ADMIN</a></li>
<li style="padding-left: inherit"><a id="A2" runat="server" href="~/Configuration" title="Configuration">CONFIGURATION</a></li>
<li style="padding-left: inherit"><a id="A3" runat="server" href="~/Reports" title="Reports">REPORTS</a></li>
<li style="padding-left: inherit"><a id="A4" runat="server" href="~/Upload" title="Upload">UPLOAD</a></li>
<li style="padding-left: inherit"><a id="A5" runat="server" href="~/Billing" title="Billing">BILLING</a></li>
</ul>
</div>
</div>
</nav>
</header>
</body>
after 1-2 seconds:
----------------------EDIT STARTS HERE-----------------------
Note: Bootstrap css were not used, extremely sorry for that.
Plain css and html in site.master page are used.
Ok, So I finally, kind of, found the issue myself.
Trials: Tried all the suggestions provided in the answers, Thank you all for that but they didn't help.
Issue: I created an empty aspx page with no content in it and loaded it with master page. What I see is below:
On the other hand when the page with some content loads it sets the navbar correctly like this, looks like when the Admin page loads it is empty for 1-2 seconds and when it renders it sets the correct style:
So what I did is I put below code to make it less ugly :(
li{
display: inline;
}
which now will show up like :
Any other suggestions guys ?
Your code is missing the part where you include Bootstrap, and that is the main point. Your navbar is styled by Bootstrap, so it won't be styled until the Bootstrap's CSS file is loaded.
Put the Bootstrap CSS in the <head> part of your page in a <link> element.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
This is your code without bootstrap: https://jsfiddle.net/xa2ychxn/ and this is your code with the Bootstrap's CSS file in the <head> section: https://jsfiddle.net/edaovwjt/
You are using class names from Bootstrap (navbar navbar-default). As you don't have any CSS code to make the navbar inline, when you finally get the expected result that means that something else gets loaded: that's Bootstrap.
I think you are loading something in the page using Ajax, and the content that is loaded contains bootstrap's CSS. That's why you don't know that you are using it, and why it is loaded some time after the page rendering.
Have you tried putting the styles in a CSS file or in a style tag in the head?
<html>
<head>
<style type="text/css">
.navbar {
margin-bottom: 0px;
clear: none;
background-color: white;
border-color: white;
}
.container {
margin-left: 0px;
}
.navbar-header img {
margin-right: 40px;
width: 130px;
height: 40px;
}
.navbar-left li {
padding-left: inherit;
}
</style>
</head>
<body>
<header>
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<img src="../../Images/Logo.png" />
</div>
<div class="collapse navbar-collapse" id="myNavbar" >
<ul class="nav navbar-nav navbar-left">
<li><a id="A1" runat="server" href="~/Admin" title="Admin">ADMIN</a></li>
<li><a id="A2" runat="server" href="~/Configuration" title="Configuration">CONFIGURATION</a></li>
<li><a id="A3" runat="server" href="~/Reports" title="Reports">REPORTS</a></li>
<li><a id="A4" runat="server" href="~/Upload" title="Upload">UPLOAD</a></li>
<li><a id="A5" runat="server" href="~/Billing" title="Billing">BILLING</a></li>
</ul>
</div>
</div>
</nav>
</header>
</body>
</html>
Alternatively, if you do have a linked CSS sheet, check the styles applied to the classes in your header. Some of the elements are probably rendered according to the CSS styles first, then the inline styles are overriding them as elements are rendered.
I know this might be a longshot but can you try using Minified versions of the bootstrap and jquery.Just give it a try and let me know
Try using these :
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
The problem seems to come from external style sheets.
During the brief period where the LI elements are displayed vertically, i guess you're still busy loading CSS from external files.
Does it still happen if you add the following CSS to the style element in the head of your page?
.navbar ul
{
list-style:none;
}
.navbar ul li
{
display:inline-block;
}
.navbar ul li a
{
/* i have no idea if this is right. it is just an approximation. */
/* you will have to fiddle with it until it is right. */
padding:10px 20px;
}
(or see this codepen)
I must be doing something unusual, as the related questions and answers I've found so far on Stack Overflow aren't working for me. I'm new to css, so the answer may be obvious.
I prefer the solution to avoid !important, and if possible, only apply to the site header (e.g. not anywhere else on the site; that is, only apply to content inside block with id="my-block").
Also, would like solution to work for all levels in the nav (first, second, etc.).
This is what I tried:
.navbar .navbar-default > li > a:hover {
background-color: #FFFF00;
color: #FF0000;
}
Here's my code that runs along the top of my site:
<nav id="my-block" class="navbar navbar-default navbar-static-top navbar-default-siteheader navbar-inner-siteheader">
<div class="container">
<div class="collapse navbar-collapse in" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
Menu1<span class="caret"></span>
<ul class="dropdown-menu">
...
</ul>
</li>
<li class="dropdown">
Menu2<span class="caret"></span>
<ul class="dropdown-menu">
...
</ul>
</li>
</ul>
</div>
</div>
</nav>
Change
.navbar .navbar-default > li > a:hover
to
#my-block.navbar li a:hover
You can add your customize id in parent element like :-
<div **id="custom-nav-head"**>
<ul>
<li>Link</li>
</ul>
</div>
and then in css file, use below
**#custom-nav-head** .navbar .navbar-default > li > a:hover {
color: your color
}
if still its not work so then use !important property. Like :-
**#custom-nav-head** .navbar .navbar-default > li > a:hover {
color: your color **!important**;
}
Try this:
a.dropdown:hover{
background-color://whatever colour
}
I was wondering, because when I click on a dropdown menu the thickness of the li navbar elements decreases. Using the standard layout:
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<!-- 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>
<img class="logo" src="imgs/logo.png">
</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 navbar-right">
**<li><span class="navli">SERVICES</span></li>
<li><span class="navli">OUR WORK</span></li>
<li><span class="navli">ABOUT</span></li>**
<li class="dropdown">
<img src="imgs/english.png" style="padding-right:3px;margin-left:-5px;"><span class="caret"></span>
<ul class="dropdown-menu">
<li><img src="imgs/deutsch.png"> Deutsch</li>
<li role="separator" class="divider"></li>
<li><img src="imgs/espanol.png"> EspaƱol</li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container -->
</nav>
Does anybody know where the CSS is for this.
And another question:
Is there a way of seeing the CSS changes being applied, when an action occurs? Maybe I can try to find out that way.
Thanks in advance
That would be the following snippet if you are using the 'default navbar'
(Line 4498 in bootstrap.css)
.navbar-default .navbar-nav > li > a {
color: #777;
}
.navbar-default .navbar-nav > li > a:hover,
.navbar-default .navbar-nav > li > a:focus {
color: #333;
background-color: transparent;
}
.navbar-default .navbar-nav > .active > a,
.navbar-default .navbar-nav > .active > a:hover,
.navbar-default .navbar-nav > .active > a:focus {
color: #555;
background-color: #e7e7e7;
}
.navbar-default .navbar-nav > .disabled > a,
.navbar-default .navbar-nav > .disabled > a:hover,
.navbar-default .navbar-nav > .disabled > a:focus {
color: #ccc;
background-color: transparent;
}
Is there a way of seeing the CSS changes being applied, when an action occurs? Maybe I can try to find out that way.
I suggest learning how to use your browser's developer tools. DevTools are great for examining, editing and debugging. Below are links to the How tos for IE, Firefox and Chrome. You can also Google search for your specific browser to learn how to use their devtool (If it's available).
Internet Explorer - https://msdn.microsoft.com/en-us/library/gg589507(v=vs.85).aspx
Google Chrome - https://developers.google.com/web/tools/chrome-devtools/iterate/inspect-styles/basics
Mozilla Firefox - https://developer.mozilla.org/en-US/docs/Tools
Thanks for the answers, I tried finding it with the developer tools.
Changing the color unfortunately doesn't do the trick. It is more and issue of the width, that changes when the dropdown is active and the other li > a elements react.
This may be simple, however I can't seem to accomplish what I need.
Basically, I want the colour to change to something else rather than bootstrap's default blue when the page in question is in active.
I have tried many different css, but this is my current:
ul.nav a:active {
background-color: #3366CC !important;
}
The navbar that im using is as followed:
<nav class="navbar navbar-default navbar-static-top" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</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 nav-pills nav-justified fixed-top">
<li class="active">Home</li>
etc
Is there a simple CSS rule that I'm missing, the colours change quite freely for my other menu needs, such as:
ul.nav {
padding: 5px;
}
ul.nav li a {
color: #fff;
}
ul.nav li a:hover{
color: #CC0033 !important;
}
ul.nav a:hover {
background-color: #fff !important;
}
Any help will be appreciated!
You just need to add the color to the a tag inside the li with the active class
ul.nav li.active a {
background-color: #3366CC !important;
}
The :active pseudo-class only matches when, for example, the user is in the process of clicking on the link:
https://developer.mozilla.org/en-US/docs/Web/CSS/:active
It does not indicate which page is active.
In Bootstrap the page/section that is currently active is signaled by an active class on the li. In Bootstrap 3, try:
.nav > .active {
background-color: #3366CC;
}
Use Inspect Element to find out what style is actually being applied, so you can properly override it.
My main issue with using CSS libraries is that they often overwrite custom CSS styles that I specifically set. For example, here I have a list that exists within a Bootstrap expand/collapse menu:
<ul class="nav navbar-nav">
<li>
<img src="images/arrow.gif" style="width: 20px;">Link A
</li>
</ul>
I want to set my own font color, so I use the following CSS:
nav li {
font-size: 16px;
color: #004687;
}
But when I view in Firefox's Inspector, I see the color I have chosen is being overridden by Bootstrap.
My custom CSS occurs after the Bootstrap files have been loaded in the of the HTML document.
How do I prevent this happening without setting style="color: #004687" to every element?
EDIT: Thanks for the suggestions thus far, but none have been successful. I'm pasting the full original code to give you greater detail:
<div class="container">
<header class="navbar navbar-static-top bs-docs-nav">
<div class="col-md-4 visible-xs" id="mobile-nav-outer">
<div class="navbar-header">
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".bs-navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
Menu
</div>
<nav class="collapse navbar-collapse bs-navbar-collapse" id="mobile-nav-inner" role="navigation">
<ul class="nav navbar-nav">
<li>
<img src="images/arrow.gif" style="width: 20px;">Link A
</li>
</ul>
</nav>
</div>
</header>
</div>
My CSS is included like this:
<head>
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="bootstrap/css/docs.min.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<style type="text/css">
#mobile-nav-outer {
border: 1px solid #CCC;
background-color: #FFF;
}
#mobile-nav-inner {
border: 1px solid #CCC;
background-color: #FFF;
margin: 3px;
}
nav li {
font-size: 16px;
color: #004687;
}
.nav-mobile-link {
font-size: 16px;
color: #004687;
}
</style>
</head>
EDIT 3: I have found a cheap workaround by using ID's rather than classes which works due to CSS specificity (ID's override classes). This isn't a very clean solution and I'd still like to know why I cannot override the Bootstrap classes with my own.
Overwrite it with additional class added to the list:
<ul class="nav navbar-nav custom-class">
<li>
<img src="images/arrow.gif" style="width: 20px;">Link A
</li>
</ul>
and in your custom styles:
.nav.custom-class li {
font-size: 16px;
color: #004687;
}
try to place custom css file below bootstrap.css.
or
nav li {
font-size: 16px !important;
color: #004687 !important;
}