Challenges with navbars and Bootstrap

Just started using twitter-bootstrap and I'm trying to customize the navbar by removing borders and padding, adding a hover effect for links with a different background color, and setting margins of about 10px on the left and right. However, I'm having trouble getting the margins to work properly.

Here's my code:

<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Case</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://fonts.googleapis.com/css?family=Catamaran:100|Luckiest+Guy|Quicksand:300|Asap:700|Montserrat:700|Open+Sans|Roboto|Signika:700" rel="stylesheet"/>

</head>
<body>

<style>

.navbar-default {   
 border: 0;
 -webkit-border-radius: 0;
 -moz-border-radius: 0;
 border-radius: 0;
 background-color: #00a3fe;
 font-family: 'Quicksand', sans-serif;font-size: 14pt;font-weight: 800;width: 100%; valign: middle;color : #ffffff;

 }

.nav.navbar-nav.navbar-right li a {
color: #ffffff;
 }

.nav.navbar-nav.navbar-nav li a {
color: #ffffff;
}
</style>


<nav class = "navbar navbar-default" role = "navigation">

   <div class = "navbar-header">
  <button type = "button" class = "navbar-toggle" 
     data-toggle = "collapse" data-target = "#example-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 = "#">Company</a>
</div>

<div class = "collapse navbar-collapse" id = "example-navbar-collapse">

     <ul class="nav navbar-nav navbar-nav">
    <li class="active"><a href="#">Home</a></li>
  </ul>

     <ul class="nav navbar-nav navbar-nav">
    <li class="non-active"><a href="#">Sign up</a></li>
  </ul>

     <ul class="nav navbar-nav navbar-nav">
    <li class="non-active"><a href="#">Register</a></li>
  </ul>

     <ul class="nav navbar-nav navbar-nav">
    <li class="non-active"><a href="#">About</a></li>
  </ul>

  <ul class="nav navbar-nav navbar-right">
    <li><a href="#"><span class="glyphicon glyphicon-user"></span> Login</a>    </li>
    </ul>
  </div>

</nav>
</body>
</html>

Answer №1

Your CSS styles are being overridden by Bootstrap. To fix this, use .navbar.navbar-default instead of just .navbar-default to prioritize your CSS.

If you want to add margin around your nav, wrap a div around it and give that div some padding like padding: 0 20px;. This will give your nav 20px space on the left and right. (I named that div class="navbarcon", you can find the CSS for it)

To change the background color of links when hovered over, use the :hover pseudo-class. I have set the background to green initially and red when hovering over them.

body,html{
  width:100%;
  margin:0;
  padding:0;
}
.navbarcon{
  width:100%;
  margin:0;
  padding:0 20px;
  background-color: #00a3fe;
}

.navbar.navbar-default {   
 border: 0;
 -webkit-border-radius: 0;
 -moz-border-radius: 0;
 border-radius: 0;
 background-color: #00a3fe;
 font-family: 'Quicksand', sans-serif;
 font-size: 14pt;
 font-weight: 800;
 width: 100%;
 valign: middle;
 color : #ffffff;
 }

.nav.navbar-nav.navbar-right li a {
color: #ffffff;
background-color:green;
}

.nav.navbar-nav.navbar-nav li a {
color: #ffffff;
background-color:green;
}

.nav.navbar-nav.navbar-right li a:hover {
background-color:red;
}

.nav.navbar-nav.navbar-nav li a:hover {
background-color:red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

<div class="navbarcon">
<nav class = "navbar navbar-default" role = "navigation">
   <div class = "navbar-header">
  <button type = "button" class = "navbar-toggle" 
     data-toggle = "collapse" data-target = "#example-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 = "#">Company</a>
</div>

<div class = "collapse navbar-collapse" id = "example-navbar-collapse">

  <ul class="nav navbar-nav navbar-nav">
    <li class="active"><a href="#">Home</a></li>
    <li class=""><a href="#">Sign up</a></li>
    <li class=""><a href="#">Register</a></li>
    <li class=""><a href="#">About</a></li>
  </ul>

  <ul class="nav navbar-nav navbar-right">
    <li><a href="#"><span class="glyphicon glyphicon-user"></span> Login</a></li>
    </ul>
  </div>
 </nav>
</div>

Answer №2

Discover the magic of CSS hover effects by checking out this helpful resource CSS Hover Effects. Feel free to explore and unleash your creativity!

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

How to use image source and mouse hover effects in CSS3

Can we create a CSS3 class for the src, onmouseout, and onmousehover properties? <img src="http://www.example.com//images/pic.png" onmouseout="this.src = 'http://www.example.com/images/pic.png'" onmouseover="this.src = 'http://www.examp ...

Fullcalendar Bootstrap popover mysteriously disappears

I'm having issues with my Bootstrap popovers being hidden under the rows in FullCalendar. I've tried using container: 'body' and trigger: 'focus', but they don't seem to work. The function that's causing this proble ...

Having trouble with the Jquery animate() function?

I recently developed a jQuery animation where clicking on specific buttons triggers a hidden div to slide from left: -650px; to left: 0px;. You can see an example by clicking here. However, I've noticed that when another button is clicked to reveal a ...

Ways to position a single item in the middle of a multi-column layout

I need help with aligning dynamic images in a 2-column layout. What's the best way to center a single image or collapse the columns when there's only one image? Currently, the single image is always placed in the left column. Is there a CSS-only ...

Adjusting the appearance of a JavaScript element based on its hierarchy level

Currently, I am utilizing Jqtree to create a drag and drop tree structure. My main goal is to customize the appearance of the tree based on different node levels. Javascript Tree Structure var data = [ { name: 'node1', id: 1, chi ...

Implementing a stylish gradient background with HTML 5 progress bar tag

I am trying to customize an HTML5 progress bar tag in a unique way: The background of the bar should have a gradient with a fixed width of 100%, but I want the gradient to only be visible where the value of the bar is... progress[value]::-webkit-progres ...

What is the proper way to add comments within CSS code inline?

Can anyone provide instructions on how to comment an inline css property, such as height, in the following code snippet? <div style="width:100%; height:30%;"> Any help is appreciated. Thank you! ...

What are some techniques I can use to ensure my image grid is responsive in html/css?

If you want to check out the website, you can visit . The main goal is to create an image grid for a portfolio. It appears really nice on a 1080p screen, but anything below that seems messy and unorganized. Any assistance or suggestions on how to improve ...

I'm noticing that my Tailwind styles don't take effect until I redefine them. What could be causing

My Tailwind classes are giving me trouble. I faced an issue when I created a new component in the directory and placed my Button component there. Whenever I restart the project in terminal, the styles do not apply to my button unless I manually define th ...

Align the body of the table with the header after populating the table with values

Issue : The data in the table body is misaligned with the headers of each column. Solution : var test_insert1 = '<tr>' + '<td class="td-trad-9">762261</td>' + '<td class="td-trad-7">1.16176&l ...

A guide to loading CSS and JavaScript files asynchronously

Is it possible to use loadCSS (https://github.com/filamentgroup/loadCSS/blob/master/README.md) to allow the browser to asynchronously load CSS and JavaScript? This is what I currently have in my head tag: <link rel="preload" href="http://zoidstudios. ...

In the world of MUI, how should one interpret the symbols '&', '>', and '*' when used together?

Currently, I am in the process of building a website using React. To help with this project, I purchased a Material-UI React template. As I was going through the code, I came across the line 4 where it mentions '& > *', and I'm not qu ...

Aligning content vertically in Bootstrap 4 so it is centered

I've been struggling to center my Container in the middle of the page using Bootstrap 4. I haven't had much luck so far. Any suggestions would be greatly appreciated. You can check out what I have so far on Codepen.io and experiment with it to s ...

Exploring how to replicate background-size: cover with a center position using HTML5's <video> tag

Looking to replicate the effect of background-size: cover on a <video> element. I was able to achieve this with the code below: <video id="videobackground" autoplay="true" loop="true"> <source src="BackgroundFinal2.mp4" type="video/mp4" ...

Displaying a variable in a live HTML user interface

I have successfully created a Python program that captures data from an Arduino Potentiometer and shows it on the Python console. Now, I am working on enhancing the output by displaying it in a local HTML file. I am seeking guidance on how to incorporate t ...

Strategies for smoothly navigating the page to a specific div every time

Currently, I am working on a form that requires submitting multiple child forms. To enhance user experience, I have incorporated jQuery functionality to display a message at the top of the page upon each submission. Now, my goal is to implement a feature w ...

Enabling hover effects to scroll divs only when interacted with

I am aiming to achieve two separate scrolling divs and I'm uncertain about the exact approach. Experimenting with various overflow properties has only resulted in one scrolling independently. .profile { width: 100%; display: flex; ...

Tips for adding an offset to a #link located on a different webpage

I have a website that consists mainly of an index.html file with a few additional subpages. The index.html file is divided into sections, but the navigation has a fixed position and a height of 100px, which requires a 100px offset for links like <a hre ...

Customize the appearance of the "Collapse" component in the antd react library by overriding the default styles

Incorporating JSX syntax with *.css for my react component. Displayed below is the jsx code for the antd collapse section. <Collapse defaultActiveKey={["1"]} expandIconPosition="right" > <Panel header="This is p ...

Converting HTML divs into a single page PDF document using DinkToPdf

Having trouble generating PDF from HTML using DinkToPdf due to div elements splitting across pages? Is there a way to ensure the entire div stays on one page, perhaps through html/css? Ideally, if there is sufficient space, the div should remain on the c ...