I have written a simple html and css file but my css is not working for the second last link i.e. for the link to logout
here is the code to my HTML file
<nav class="navbar navbar-expand-md navbar-dark">
<a class="navbar-brand" href="#">
<img src="../../../assets/logo.JPG" class="d-inline-block img-fluid align-top" alt="">
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse"
data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id = "navbarSupportedContent" >
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<div *ngIf="email" class="navbar-text custom float-left">
{{email}}
</div>
</li>
<li class="nav-item">
<a [routerLink]=" ['/'] " class="nav-link">
<fa-icon [icon] = "faHome" primarycolor = "black"></fa-icon>
Home</a>
</li>
<li class="nav-item">
<a *ngIf="!email" [routerLink]=" ['/signin'] "
routerLinkActive="active" class="nav-link">
<fa-icon [icon] = "faSignInAlt" primarycolor = "black"></fa-icon>
signIn</a>
</li>
<li class="nav-item">
<a *ngIf="!email" routerLinkActive="active"
[routerLink]=" ['/signup'] " class="nav-link">
<fa-icon [icon] = "faUserPlus" primarycolor = "black"></fa-icon>
signUp</a>
</li>
<li class="nav-item">
<a *ngIf="email" (click)="handleSignOut()" class="nav-link">
<fa-icon [icon] = "faSignOutAlt" primarycolor = "black"></fa-icon>
Log Out</a>
</li>
<li class="nav-item">
<a *ngIf="email" routerLinkActive="active" [routerLink]=" ['/addpost']"
class="nav-link btn btn-warning text-primary">
Post Your Story</a>
</li>
</ul>
</div>
</nav>
Here is the code to my css file
.active{
background-color: purple;
}
.custom{
color: black;
}
nav{
background-color: #ffffff;
}
li>a:link{
color: black;
border-radius: 15px;
}
li>a:visited{
color: black;
border-radius: 15px;
}
I don't know what is happening here
inline CSS in that link is working quite good
I basically want my logout to be black
It is very difficult to guess based on the small excerpt. The best way is to use the computed tab of the chrome debugging tool. You need to inspect the element, go to the computed tab and expand the CSS property. You would see who sets and overrides the property value.
There is a good article on how to debug css.
Have you tried targeting it directly by giving it a unique class or id and using that in the css?
Have you tried putting "!important" after the color you want in the css?
It looks like you are using an external css library. Some of the css from external libraries can be hard to override. "!important" helps with that sometimes.
Related
I'm working with Bootstrap 3 and I'm trying to make a header navbar. Here is my code:
<div class="has-navbar">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<button class="navbar-toggler custom-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active bg-warning first-item m-1">
<a class="nav-link" href="#"><i class="fa fa-home"></i> Home</a>
</li>
<li class="nav-item bg-warning m-1">
<a class="nav-link" href="#"> <i class="fa fa-graduation-cap"></i>Courses</a>
</li>
<li class="nav-item bg-warning m-1">
<a class="nav-link" href="#"><i class="fa fa-shopping-cart"></i> E-learning products</a>
</li>
<li class="nav-item bg-warning m-1">
<a class="nav-link" href="#"><i class="fa fa-newspaper"></i> Articles</a>
</li>
<li class="nav-item bg-warning m-1">
<a class="nav-link" href="#"><i class="fa fa-calendar"></i> Events</a>
</li>
</ul>
</div>
</nav>
</div>
And the result looks like this:
As you can see the menu nav-item E-learning Products does not have enough space to place correctly in the place of nav-item.
However the other nav-items has extra space (as I mentioned out in the image).
So I need to make sure that every nav-item has enough required space based on the length of <a> links of nav-items.
And here comes the CSS code of this navbar:
/* Navbar */
.has-navbar{
margin-top:-10px;
width:100%;
height:30px;
}
.navbar{
background-color: #fff !important;
height:100%;
}
.nav-item{
height:30px;
width:130px !important;
}
.nav-item a{
font-size:13px;
font-weight: bold;
}
.first-item{
margin-right:-50px !important;
}
So here I tried setting width:130px !important; for .nav-item and it didn't work out well. I also tried width:100%; and this is the result:
So how can I properly place each nav-item menu link properly in their required space so the menu links does NOT have extra space AND not enough space?
So what you can do is set its width to max-content, which will be the maximum width that the content contained within can be.
Before(with width: 130px !important;):
After(with width: max-content;):
.nav-item{
height:30px;
//width:130px !important;
width: max-content;
}
Note: If you think it's too short, you could set a min-width value to whatever you like.
I have written code using bootstrap. But my issue is in the Toggle bar , like when I shrink the size to see my Web page responsive or not then the toggle bar is not open.
It shows the three button but when i click then it is not expanding.
Please give me suggestions to get rid of this issue.
Thanks.
Html code
<section>
<div id="container1">
<nav class="navbar navbar-expand-lg navbar-light bg-dark">
<div class="container-fluid">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="scroll nav-link" href="#home" style = "color: #ffff;">HOME</a>
</li>
<li class="nav-item">
<a class="scroll nav-link" href="#about" style = "color: #ffff;">ABOUT</a>
</li>
<li class="nav-item">
<a class="scroll nav-link" href="#services"style = "color: #ffff;">SERVICES</a>
</li>
<li class="nav-item">
<a class="scroll nav-link" href="#contacts" style = "color: #ffff;">CONTACTS</a>
</li>
</ul>
</div>
</div>
</nav>
</div>
</section>
**Css code**
#container1{
margin-top:5rem ;
display: inline-block;
width: 100%;
}
#container1 ul li {
margin-left: 8rem;
margin-right: -5rem;
border-right: 0.0625rem solid grey;
}
#container1 ul li a:hover{
background-color: #5e9ee7;
}
I just get rid of my issue that I have arose a few hours ago. I finally got a fix of my problem. It only happens by removing "bs" which is present in between (data-bs-toggle="collapse") and in (data-bs-target="#navbarNav") in the html code.
as posted on the title, I can't change the background-color of my navbar. But I'm sure that my external css is working.
HTML CODE:
<nav class="navbar navbar-expand-lg navbar-light bg-light sticky-top">
<div class="container">
<a class="navbar-brand" href="{% url 'index' %}"><img src="{{logo.image.url}}" alt="no image provided" style="max-width: 10rem; max-height: 10rem;"></a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="{% url 'index' %}">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'accounts:register' %}">Sign Up</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'cms' %}">Manage Web Content</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'admin:index' %}" tabindex="-1">Admin Page</a>
</li>
</ul>
</div>
</div>
<ul class="sample">
<a class="nav-link" href="#" tabindex="-1">sample</a>
</ul>
</nav>
EXTERNAL CSS:
.navbar {
background-color: black;
}
.sample .nav-link {
color: red;
}
And I will include a picture of my navbar just for reference. Take note of the ul tag with sample label in it, located at the right part of the navbar. It turned out to be red. That's how I knew the external CSS is working. Any ideas why is this happening?
SOLUTION: thanks to those guys who answered in the comment section. And it seems that the problem is one of these classes navbar-light orbg-light , these are default classes from bootstrap framework. So, in order for my external css to work is I needed to put !important to override those 2 classes mentioned above:
.navbar {
background-color: black !important;
}
.sample .nav-link {
color: red;
}
Just Remove bg-light bootstrap class from nav tag and add your custom class over their your result should be like this.
<nav class="navbar navbar-expand-lg navbar-light bg-example sticky-top"></nav>
.bg-example{
background-color:orange;
}
I have this navbar from bootstrap which is supposed to add active class on nav-item or on anchor element on click, but while inspecting it in browser its not changing states, I don't understand why.
.nav-link {
color: #FFF;
width: 100%;
height: 100%;
text-transform: uppercase;
}
.nav-link::after {
content: '';
display: block;
width: 0;
height: 2px;
background: green;
transition: width .3s;
}
.nav-link:hover::after {
width: 100%;
}
.navbar-nav>.active>a {
color: #00cc00;
}
<nav class="navbar navbar-expand-lg navbar-dark " style="background-color: black;">
<div class="container-fluid">
<a class="navbar-brand d-lg-none" href="#"><img src="../assets/images/howdy-white.png" style="width:45px; height:45px;" /></a>
<button class="navbar-toggler shadow-none" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand d-none d-lg-block" href="#"><img src="../assets/images/howdy-white.png" style="width:45px; height:45px;" /></a>
<div class="collapse navbar-collapse justify-content-end" id="navbarNavAltMarkup">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">about</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">works</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">contacts</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">services</a>
</li>
</ul>
</div>
</div>
</nav>
You need add some javascript event handler while you click that link will do some action.
example if you using jQuery with that navbar structure like you shown
$("ul.navbar-nav li").on("click", function() {
$("ul.navbar-nav li").removeClass("active");
$(this).addClass("active")
})
or if you like using vanilla javascript with DOM query SelectorAll
let navbarLink = document.querySelectorAll(".navbar-nav li")
document.addEventListener("click", function(e) {
for (let x = 0;x < navbarLink.length;x++) {
navbarLink[x].classList.remove("active")
}
e.target.closest("li").classList.add("active")
})
hope this work on your case.
You suppose to add active class on anchor tag
I have a Bootstrap 4 website with a navbar. The navbar has a brand part with an image and title text, and then there's the rest of the navbar. You can see it here: https://jsfiddle.net/zmbq/aq9Laaew/218793/
Now, I want to add a subtitle, under the title "A Digital Onomasticon". The problem is - the substitle is long, and I want it to extend below the nav links.
I tried everything I could think of and couldn't figure out how to do that.
NOTE: the answer to this question is not sufficient, as it yields something like this: https://jsfiddle.net/zmbq/7et2uz0w/
Wrap the brand and links in a separate flexbox (d-flex) div...
<nav class="navbar navbar-light bg-light navbar-expand-sm flex-nowrap align-items-start">
<a class="navbar-brand" href="#">
<img src="http://onomasticon.researchsoftwarehosting.org/assets/images/seal-impression.png">
</a>
<div class="d-flex flex-column">
<div class="d-sm-flex d-block flex-nowrap">
<a class="navbar-brand" href="#">A Digital Onomasticon</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarOnavbarNavptions" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Item one</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Item two</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Item three</a>
</li>
</ul>
</div>
</div>
<small>A lot more text that goes under the links and should be cleverly placed, and isn't</small>
</div>
</nav>
https://www.codeply.com/go/9SK8ItOyzw
Related: Bootstrap 4 navbar with 2 rows
You can set the subtitle to position absolute to remove it from the normal content flow. It's unclear how it should look on mobile, I simply hide it in the media query. Example:
<a class="navbar-brand" href="#">
<img src="http://onomasticon.researchsoftwarehosting.org/assets/images/seal-impression.png">
A Digital Onomasticon
<small>A lot more text that goes under the links and should be cleverly placed, and isn't</small>
</a>
.navbar-brand small {
display: block;
font-size: 10px;
white-space: normal;
position: absolute;
}
#media (max-width: 575.98px) {
.navbar-brand small {
display: none;
}
}
JsFiddle