Bootstrap - remove background from navbar link - html

I'm trying to work on coding a website using the Bootstrap development kit. I've set up the navigation bar with a couple of links but I'm having some trouble with some custom links I've added. I added CSS to the bootstrap.min.css file titled 'navbar-social', which will be used to house social media icons for the navigation bar.
I added the images just fine and they display great. The problem I'm having is when I add a link to them they go out of line and hovering over them gives them a background box which I do not want.
I've attached some screenshots and the code used, I cannot for the life of me work out where the background box is coming from, because checking the a styles doesn't seem to have anything there. I'm new to CSS so I apologise if I'm missing something obvious.
None linked: http://prntscr.com/2ob9mj
LinkedIn not linked, rest linked: http://prntscr.com/2ob2b2
CSS code added to bootstrap.min.css. Rest is as it comes:
.navbar-social{
float:right !important;
padding:5px;
font-size:18px;
line-height:37px;
height:20px
}
HTML: (a href removed in this case)
<nav class="navbar navbar-default navbar-static-top" role="navigation">
<div class="container">
<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>
<a class="navbar-brand" href="">REMOVED</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active">About</li>
<li class="dropdown">
Programming <b class="caret"></b>
<ul class="dropdown-menu">
<li>Java</li>
<li>C++</li>
<li>Actionscript 3.0</li>
</ul>
</li>
<li>Web Design</li>
</ul>
<ul class="nav pull-right">
<li class="navbar-social"><img src="images/linkedin.png" alt="LinkedIn" /></li>
<li class="navbar-social"><img src="images/github.png" alt="GitHub" /></li>
<li class="navbar-social"><img src="images/twitter.png" alt="Twitter" /></li>
<li class="navbar-social"><img src="images/facebook.png" alt="Facebook" /></li>
</ul>
</div>
</div>
</nav>
Thanks all!

Bootstrap adds styling to the child a elements. You could simply overwrite it using the following:
WORKING EXAMPLE HERE
.nav .navbar-social > a {
padding:0;
}
.nav>li>a:hover, .nav>li>a:focus {
background-color: transparent;
}

Related

bootstrap nav bar nested <ul> not showing properly under parent

When you view the page as mobile the main navigation bar does not show the drop downs properly underneath their respected parent link. I have search and cannot seem to find a solution. Currently the dropdown menus show under and to the left of the main link. You can see a live demonstration at http://beta.lofbc.org
<nav class="navbar navbar-default">
<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="#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>
<a class="navbar-brand hidden-lg hidden-md hidden-sm" href="#">Life of Faith Bible Church</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="navbar-collapse-1">
<ul class="nav nav-justified">
<li>#Html.ActionLink("HOME", "index", "Home")</li>
<li role="presentation" class="dropdown">
ABOUT US <span class="caret"></span>
<ul class="dropdown-menu">
<li>#Html.ActionLink("Church Services", "ChurchServices", "About")</li>
<li>#Html.ActionLink("What to Expect", "WhatToExpect", "About")</li>
<li>#Html.ActionLink("What we Believe", "whatwebelieve", "About")</li>
<li>#Html.ActionLink("Leadership", "Leadership", "About")</li>
</ul>
</li>
<li role="presentation" class="dropdown">
MINISTRIES <span class="caret"></span>
<ul class="dropdown-menu">
<li>#Html.ActionLink("Children", "Children", "Ministries")</li>
<li>FAA</li>
<li>God's Girlz Club</li>
<li>AfterShock Youth</li>
<li>Young Adults</li>
<li>Men of Impact</li>
<li>Women</li>
<li>God's Golden Girls</li>
<li>The Great Giveaway</li>
</ul>
</li>
<li>#Html.ActionLink("EVENTS", "", "Events")</li>
<li role="presentation" class="dropdown">
MEDIA <span class="caret"></span>
<ul class="dropdown-menu">
<li>Live Stream</li>
<li>#Html.ActionLink("Service Archives", "ServiceArchives", "Media")</li>
<li>TV Broadcast</li>
<li>Photo Album</li>
</ul>
</li>
<li>STORE</li>
<li role="presentation" class="dropdown">
CONTACT <span class="caret"></span>
<ul class="dropdown-menu">
<li>#Html.ActionLink("Send us a Message", "index", "contactus") </li>
<li>Submit Testimony</li>
<li>Prayer Request</li>
<li>#Html.ActionLink("Give", "Donate", "Giving")</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
This is happening because your nested <ul> tags are absolutely positioned. An absolutely positioned element cannot move relatively positioned elements so even if you moved it across it will simply appear on top of your existing buttons.
My fix would be to apply the following css to the nested <ul> tags:
#media (max-width: 767px) {
.nav-justified>.dropdown .dropdown-menu {
position: relative;
width: 100%;
background-color: #1c5168;
}
.nav-justified>.dropdown .dropdown-menu li {
color: lightblue;
text-align: center;
}
}
Placing it inside a media query will stop the css from applying to your menu on desktop layouts.
You will still have to add more styling to get the menu to look nice but this will fix your positioning issue.
Just for reference here is a good article about the position property with examples of how it works: https://css-tricks.com/almanac/properties/p/position/

How To Generate Full Width Responsive SubMenu?

Here i am trying to generate full width responsive submenu for service li in my menu but i am not able to generate the full width responsive submenu.A example of full width submenu i am trying to generate is this.
And my current submenu for service by my code is show as :
Below is my code
<div class="main-nav">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".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>
<a class="navbar-brand" href="index.html">
<h1><img class="img-responsive" src="images/logo.png" alt="logo"></h1>
</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="scroll active">Home</li>
<li class="scroll dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Service <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Page 1-1</li>
<li>Page 1-2</li>
<li>Page 1-3</li>
</ul>
</li>
<li class="scroll">About Us</li>
<li class="scroll">Portfolio</li>
<li class="scroll">Team</li>
<li class="scroll">Blog</li>
<li class="scroll">Contact</li>
</ul>
</div>
</div>
</div>
Any help will be highly appreciated
I would have a look at it, but I'd need to see the CSS. I found the free template, but the it doesn't have a dropdown menu. So if I could see your CSS, I could get back to you and see what I can do! :)
~ Daniel
Ps I couldn't comment, rep is less than 50.
You can find full-width responsive menus here:
https://www.w3schools.com/bootstrap/bootstrap_navbar.asp
scroll down to see more.
You must use some framework, in this case it's bootstrap.
if you want to keep your code, provide us full-codesnippet or a jsfiddle link, otherwise seem that you want us to create all css/js over your html (and some people will offend and downvote your answer).
Hope it helps!

Why won't the color of my navbar links change [duplicate]

This question already has answers here:
Change navbar color in Twitter Bootstrap
(12 answers)
Closed 5 years ago.
So this is the HTML I have right now. I am trying to change specific links in the navbar. The "font-family", "line-height", and "font-size" all work, but the color of the links will not change.
<nav class="navbar navbar-default">
<div class="container-fluid">
<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="resources/assets/yf_logo.svg">
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right">
<li class="active">Home</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Programs</a>
<ul class="dropdown-menu">
<li>Shelter</li>
<li>Drop-ins</li>
<li>Street Outreach</li>
<li>Community Partners</li>
<li>FAQ</li>
</ul>
</li>
<li class="textstyle16">Get Involved</li>
<li class="textstyle16">About</li>
<li class="textstyle16">Contact</li>
<li class="textstyle18">Donate</li>
</ul>
</div>
</div>
</nav>
Here is my first css
.textstyle16 {
font-family:"montserrat-regular";
font-size:18px;
line-height:21px;
color:#474747;
here is my second css
.textstyle18 {
font-family:"montserrat-regular";
font-size:18px;
line-height:21px;
color:#ffffff;
}
You need to use color: (not font:).
You need to use .textstyle16 a or .textstyle16 a:link as a selector. The links are child elements of the .textstyle16 elements, they don't have that class themselves, and there is a color declaration for a tags in the browsers default styles which applies if you don't use these selectors.
It is probably being overwritten elsewhere in your code. Add !important to the color definition. If this correct the color, then yes, it's being overwritten somewhere in your styles.
Right-click the link and "inspect" the link in Google Chrome or Firefox. You'll be able to see which styles are being applied to the link specifically.
Example:

bootstrap navbar dropdown menu background not working

To simplify this as much as possible, i am basically adding a bootstrap navbar to a page, one of the tabs has a dropdown menu which has a choice of 5 sub options. I have found that the background is only showing to the bottom of the first sub option. The CSS sets the height to 100% which is what i would like, if i change the CSS to say 500px; it will expand the area.
<nav class="navbar navbar-default">
<div class="container-fluid">
<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>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li><a class="active" href="index.html">Home</a></li>
<li><a class="li" href="whatido.html">What I Do</a></li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Travels<span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Asia</li>
<li>Europe</li>
<li>Scotland</li>
<li>Other</li>
<li>And Another</li>
</ul>
</li>
<li><a class="li" href="upcomingtrips.html">Upcoming Trips</a></li>
<li><a class="li"href="aboutme.html">About Me</a></li>
<li><a class="li" href="gallery.html">Gallery</a></li>
<li><a class="li" href="contactpage.html">Contact</a></li>
</ul>
</div>
</div></nav>
</nav>
the css for the dropdown is simple
.dropdown-menu {
height:100%;
}
the result :
adjustable size
however if i change the css to
.dropdown-menu {
height:300px;
}
i get this result
fixed size
Im struggling to understand why the 100% option doesn't cover the entire area when each sub option is included in the 'dropdown-menu' ul class?
In bootstrap for .dropdown-menu class position: absolute; is there. So height in percentage wont work. If remove the position: absolute; from dropdown class the percentage of height is working.

Uneven Bootstrap Pills when Collapsed

The following code produces "pills" of unequal width when displayed on small or extra small screens (as defined by twitter bootstrap by default).
<header>
<div id="brand" class="container">
<div class="row">
<div class="col-sm-12">
<h1>Website</h1>
<h2>header</h2>
</div>
</div>
</div>
<div id="navbar" class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navs">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div id="navs" class="collapse navbar-collapse">
<ul class="nav nav-pills nav-justified">
<li class="active">
Home
</li>
<li>
About
</li>
<li>
Portfolio
</li>
<li>
Blog
</li>
<li>
Contact
</li>
</ul>
</div>
</div>
</header>
The first pill seems to be exactly 2 pixels wider than the rest. I would prefer that the pills fill the entire width of the display.
Is this a bug in Bootstrap, or something I can remedy via some simple CSS?
JSFiddle: https://jsfiddle.net/elikmiller/z2og3vq7/
why don't you override bootstrap css with your custom css just add your custom class for example nav-custom and put this css into your custom css file
.nav-custom>li>a {
padding: 10px 10px;
}
fiddle
You should use another class in your html called nav-stacked. I updated your Fiddle you can see here the full example and can see here the relevant HTML part.
<ul class="nav nav-pills nav-stacked nav-justified">
<li class="active">
This one is 2px wider
</li>
<li>
About
</li>
<li>
Portfolio
</li>
<li>
Blog
</li>
<li>
Contact
</li>
</ul>