I'm making a website with Bootstrap 5 and my navbar doesn't work.
When I'm on mobile it does not expand.
#import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght#0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap');
/*
#FF3633 - Vermelho
*/
*{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
/* estilo - header */
.navbar {
background-color: #131313;
padding: 1rem 8rem;
z-index: 1000;
}
.navbar .navbar-brand {
font-size: 1.4rem;
font-weight: 800;
}
#navbarSupportedContent > ul > li:nth-child(n) > a {
color: #fff;
font-size: 1.1rem;
padding: 0 0.8rem;
}
#navbarSupportedContent > ul > li:nth-child(n) > a:hover {
color: #FF3633;
}
#navbarSupportedContent button {
background-color: #FF3633;
font-weight: 600;
padding: 0.4rem 1.4rem;
border-radius: 30px;
outline: none;
}
#navbarSupportedContent button:hover {
background-color: #CC3036;
}
<header>
<nav class="navbar navbar-expand-lg navbar-dark fixed-top">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<img src="img/logo-wt.png" width="100" height="30" alt="">
</a>
<button class="navbar-toggler" type="button" data-bs-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 mx-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="#">Quem Somos</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Serviços</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Serviços</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contato</a>
</li>
</ul>
<button class="btn text-light" type="submit">Contato</button>
</div>
</div>
</nav>
<div class="mid">
<video autoplay muted loop>
<source class="embed-responsive" src="darkvd.mp4" type="video/mp4">
</video>
<div class="hero text-center">
<h2 class="text-light display-3 fw-bold m-lg-3 mx-3">Suporte Linux e Cloud</h2>
<p class="text-light mx-auto">Criando um paralelo entre baixo custo, disponibilidade, praticidade e satisfação</p>
<a class="text-light fw-bold m-lg-3 mx-3 " href="#"> SAIBA MAIS </a>
</div>
</div>
<header>
<nav class="navbar navbar-expand-lg navbar-dark fixed-top">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<img src="img/logo-wt.png" width="100" height="30" alt="">
</a>
<button class="navbar-toggler" type="button" data-bs-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 mx-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="#">Quem Somos</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Serviços</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Serviços</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contato</a>
</li>
</ul>
<button class="btn text-light" type="submit">Contato</button>
</div>
</div>
</nav>
<div class="mid">
<video autoplay muted loop>
<source class="embed-responsive" src="darkvd.mp4" type="video/mp4">
</video>
<div class="hero text-center">
<h2 class="text-light display-3 fw-bold m-lg-3 mx-3">Suporte Linux e Cloud</h2>
<p class="text-light mx-auto">Criando um paralelo entre baixo custo, disponibilidade, praticidade e satisfação</p>
<a class="text-light fw-bold m-lg-3 mx-3 " href="#"> SAIBA MAIS </a>
</div>
</div>
button pic
Bootstrap 5 has namespaced all of the data attribute names with data-bs-*.
Change the following:
data-target="#navbarSupportedContent"
to this:
data-bs-target="#navbarSupportedContent"
In your button in which you are collapsing the navbar then main attribute tags are not there. Main attributes used are data-toggle="collapse" data-target=".nav-collapse". Second change is that see if you added these links or add bundle from https://getbootstrap.com/docs/5.0/getting-started/introduction/
<script src="https://cdn.jsdelivr.net/npm/#popperjs/core#2.6.0/dist/umd/popper.min.js" integrity="sha384-KsvD1yqQ1/1+IA7gi3P0tyJcT3vR+NdBTt13hSJ2lnve8agRGXTTyNaBYmCR/Nwi" crossorigin="anonymous"></script>
Hope my answer helps you
I have managed to solve it with js codes from my external js file which I had already included on the page before closing of body tag.
Below here are my js codes which I used to and managed to solve the issue:
$(document).ready(function(){
//--Navbar_Toggle_icon--//
NavItemsStatus = '';
$('.navbar-toggler-icon').mousedown(function(){
//---Check if the NavItems are opened, if so then close them, otherwise open them--//
if((NavItemsStatus == "")|| (NavItemsStatus == undefined)){
NavItemsStatus = 'on';
//--Do nothing here as the nav items are sliding down after clicked for the first time--//
}else if((NavItemsStatus == "off")){
NavItemsStatus = 'on';
$("#navbarNavAltMarkup").show(600); //the id which was called on data-bs-target
}else{
NavItemsStatus = 'off';
$("#navbarNavAltMarkup").hide();
$("#navbarNavAltMarkup").css('height','0px');
}
})
});
So for your case the id to use is #navbarSupportedContent.
There is my universal working solution:
$(document).ready(function(){
$('a[data-bs-toggle="collapse"]').mouseup(function(){
var expanded = $(this).attr('aria-expanded');
if(expanded=="true"){
setTimeout(() => {
hide_collapse(this);
}, 100);
}
})
function hide_collapse(element){
var aria_control = $(element).attr('aria-controls');
$("#"+aria_control).removeClass("show");
$(element).attr('aria-expanded',"false");
}
});
for the navbar to work you need to include some javascript (even if you will not use it). The provided links in bootstrap -> get started-> JS do not really work.
So to make it fast and easy for you, here is the header where you need to add your title.
<head>
<meta charset="utf-8">
<title>TinDog</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
<link rel="stylesheet" href="css/styles.css">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</head>
Related
I have been coding a website and found that a link I need to be responsively stuck to the bottom of my div (In that spot both on large screen & mobile view)
Below is the code I currently have & 2 pictures attached for both big screen and mobile.
nav#navbar {
background-color: rgba(0, 0, 0, 0.8) !important;
}
nav#navbar ul.navbar-nav {
display: flex;
margin: 0 auto;
}
div#image-container {
height: 1920px;
background-repeat: no-repeat;
}
#booksy-container {
/* CSS properties and values go here */
height: 10.5%;
position: absolute;
top: 60%;
width: 100%;
text-align: center;
}
#booksy-link {
display: fixed;
position: relative;
align-content: end;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Bootstrap test</title>
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css"
/>
<link rel="stylesheet" href="index.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
</head>
<body>
<!--Navigation bar-->
<nav
class="navbar navbar-expand-md bg-dark navbar-dark navbar-fixed-top transparent"
id="navbar"
>
<a class="navbar-brand" href="index.html">
<img src="images/BlankBack.png" width="80" height="60" alt="" />
</a>
<button
class="navbar-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">
<a class="nav-link" href="index.html">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="aboutus.html">About us</a>
</li>
<li class="nav-item">
<a class="nav-link" href="products.html">Products</a>
</li>
<li class="nav-item">
<a class="nav-link" href="contactus.html">Contact us</a>
</li>
</ul>
</div>
</nav>
<!--NavBar Ends-->
<div
class="container-fluid"
id="image-container"
style="
background-image: url('images/Charlie-Co.-Barbershop-West-Chester-3.png');
"
>
<div class="d-flex justify-content-center pb-0" id="booksy-container">
<a
href="https://booksy.com/en-ie/3715_charlies-barbers-lucan_barbers_52867_ireland"
id="booksy-link"
>Book your appointment here!</a
>
</div>
</div>
</body>
</html>
Any suggestions welcome! Thank you!
I need the code to reflect what the view on a large screen is to the mobile view
I am trying to change the CSS of a parent image (navbar's border) when the mobile hamburger menu is clicked open, then for it to return back again when clicked again/menu closed.
I have tried to target the navbar with the border using both .parent and .find selector options, but I cannot get either to work. I think I am close, but I'm struggling to work out what's going wrong. Thank you for your help.
$(".navbar-toggler").click(function(){
$(this).find('.navbar').addClass("is-clicked");
$(this).find('.navbar').removeClass("is-clicked");
});
.navbar {
position: relative;
z-index: 98;
border-bottom: 4px solid #000000;
margin-left: 40px;
margin-right: 40px;
color: #000000;
height: 100px;
}
.navbar.is-clicked {
border-bottom: red;
}
.navbar-toggler {
font-size: 32px;
color: black;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://use.fontawesome.com/releases/v5.15.4/css/all.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<nav class="navbar navbar-expand-lg">
<div class="container-fluid nav-container">
<a class="navbar-brand" href="index.html">ABC.</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="toggler-icon"><i class="fas fa-bars"></i>
</span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarSupportedContent">
<ul class="navbar-nav">
<li class="nav-item nav-item-about p-nav">
<a class="nav-link" aria-current="page" href="about.html">About</a>
</li>
<li class="nav-item p-nav">
<a class="nav-contact" href="mailto:michellelclement#gmail.com?subject=Hello from your portfolio!">Contact</a>
</li>
</ul>
</div>
</div>
</nav>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
That is because when you use $(this).find('.navbar'), it only searches for the element with the class navbar inside the element.
If you want to search outwards, then you need to use .closest(), which will select the closest parent element that matches the selector .navbar:
$(".navbar-toggler").click(function(){
$(this).closest('.navbar').toggleClass("is-clicked");
});
See a proof-of-concept example:
$(".navbar-toggler").click(function() {
$(this).closest('.navbar').toggleClass("is-clicked");
});
.navbar {
position: relative;
z-index: 98;
border-bottom: 4px solid #000000;
margin-left: 40px;
margin-right: 40px;
color: #000000;
height: 100px;
}
.navbar.is-clicked {
border-bottom-color: red;
}
.navbar-toggler {
font-size: 32px;
color: black;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://use.fontawesome.com/releases/v5.15.4/css/all.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<nav class="navbar navbar-expand-lg">
<div class="container-fluid nav-container">
<a class="navbar-brand" href="index.html">ABC.</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="toggler-icon"><i class="fas fa-bars"></i>
</span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarSupportedContent">
<ul class="navbar-nav">
<li class="nav-item nav-item-about p-nav">
<a class="nav-link" aria-current="page" href="about.html">About</a>
</li>
<li class="nav-item p-nav">
<a class="nav-contact" href="mailto:michellelclement#gmail.com?subject=Hello from your portfolio!">Contact</a>
</li>
</ul>
</div>
</div>
</nav>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
The Jquery:
$('.navbar-toggler').on('click', function(){
$('.navbar').toggleClass('is-clicked');
});
You also need to change this in your css:
.navbar.is-clicked {
border-bottom-color: red;
}
I have used html,css and bootstrap to design this section but the problem is whichever video I upload has some extra width and height resulting in vertical and horizontal scroll bar. It effects my nav-bar. Any help please? I am mentioning the code and CSS.
* {
margin: 0;
padding: 0;
font-family: 'Exo 2', sans-serif;
}
h1,
h2 {
font-family: 'Lemonada', cursive;
}
h1,
h2 {
color: yellow;
}
.home-data-container {
z-index: 1;
position: relative;
bottom: 850px;
left: 40px;
}
.heading-btn {
margin-top: 15px;
}
.heading-btn:hover {
color: black;
background: whitesmoke;
}
#media screen and (max-width: 992px) {
.home-data-container {
text-align: center;
}
}
<!-- Header -->
<nav class="navbar navbar-expand-lg navbar-dark 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="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Special</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Dishes</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</div>
<a class="navbar-brand" href="#"> DANY</a>
</div>
</nav>
<!-- Hedaer End -->
<!-- Home section -->
<section class="home" id="home">
<div class="video-container">
<video autoplay loop muted>
<source
src="videos/Seasoning Pizza at Italian Restaurant.mp4"
type="video/mp4"
/>
</video>
</div>
<div class="home-data-container">
<h1 class="home-heading">Food that you cant resist</h1>
<h2 class="home-heading">Enjoy the marvelous taste</h2>
<button type="button" class="btn btn-dark btn-lg heading-btn">
Get Started
</button>
</div>
</section>
screen shot
What exactly am I doing wrong here? I checked adding width and height attributes to the video tag but it didn't work
Can you try to add css to video tag and set width:100% ?
I've created a Bootstrap navigation bar and below that, I have made a container in which I will show some description as shown in the image below. I've used the latest version of the bootstrap.
Now, the alignment of the description text should match that of the left-most item of the navigation bar, but what I'm getting from my code is shown in the below image.
Here you can clearly see that the alignment of the left most navbar item i.e. CP-210-1 button doesn't match with the description text starting with This is....
Here is my code.
.model-family-navigation-bar {
background-color: #00853e;
}
.navigation-bar-content {
color: white;
font-size: 120%;
}
.dropdown-menu>div>a:hover {
background: #8dc4d4;
}
.dropdown-menu>div:nth-child(odd) {
background: #d9d9d9;
}
.dropdown-menu>div:nth-child(even) {
background: #f9fffe;
}
.border-section {
border: 2px solid #D0D0D0;
margin-top: 20px;
}
.greenTitle {
color: green;
font-weight: bold;
}
a:link {
font-size: 120%;
background-color: transparent;
text-decoration: underline;
}
a:visited {
color: white;
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>App5</title>
<base href="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
<div class="container model-family-navigation-bar" style="min-height: 32px">
<nav class="navbar navbar-expand-sm navbar-dark model-family-navigation-bar" style="min-height: 32px">
<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">
<!-- <div class="col-sm-auto"> -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle navigation-bar-content text-white" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style="text-decoration:none">
<span id="selected" style="text-decoration:none;font-weight:bold">CP-210-1</span>
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color:#00853e">
<h1 class="dropdown-header text-white">Model Family</h1>
<div>
<!-- <div class="dropdown-divider"></div> -->
<a class="dropdown-item text-black" (click)="showList()">CP210-1</a>
<a class="dropdown-item text-black" (click)="showList()">CP210-2</a>
<a class="dropdown-item text-black" (click)="showList()">CP210-3</a>
<a class="dropdown-item text-black" (click)="showList()">CP210-4</a>
</div>
</div>
</li>
<!-- </div> -->
<!-- <div class="col-sm-auto"> -->
<li class="nav-item">
<span class="navigation-bar-content navbar-text text-white ml-4">Proportional Directional Valve</span>
</li>
<!-- </div> -->
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link text-white" href="https://www.google.com/" style="font-size:13px">Data Sheet</a>
</li>
</ul>
</div>
</nav>
</div>
<div class="container border-section mt-2">
<div class="row" style="min-height:80px;">
<p class="ml-4 mt-1" style="font-size:20px">This is a proportional, 3 position 4 way, directional control valve</p>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.min.js" integrity="sha384-a5N7Y/aK3qNeh15eJKGWxsqtnX/wWdSZSKp+81YjTmS15nvnvxKHuzaWwXHDli+4" crossorigin="anonymous"></script>
</body>
</html>
I'm not finding any way to align the left-most item of the navigation bar to the description text. Although I have an alternative to add the left padding to the left item but that's not what I'm supposed to do. So, can anyone help me out on how to align the text with the button item? Also, I'm not finding any way to decrease the height of the green colored navigation bar container equal to that as given in the first image.
If I decrease the height then the responsive behavior is not there on decreasing the browser width. So, can anyone suggest something for that also?
As a quick fix you could try setting the left padding of the "nav-link" anchor to 0.
Something like this:
.navbar-nav .nav-link.dropdown-toggle {
padding-left: 0px;
}
Or you could add a custom class to that element and use that in your selector.
I have a Bootstrap 4 navbar and I want another section to appear below it when you hover over a specific link. And I've written everything, the thing is, it doesn't work for some reason. I've tried using a:hover div {} and a:hover + div {} to make sure it's not the structure of CSS.
Can someone take a look and let me know what is going on? Please open the snippet in full screen.
.hover {
background: red;
display: none;
}
#projects:hover + .hover {
display: block;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
<nav class="navbar navbar-toggleable-md fixed-top">
<div class="container">
<button class="navbar-toggler navbar-toggler-right" 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>
<a class="navbar-brand" href="/">
<img src="..." alt="Logo">
</a>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link active" href="/">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item" id="projects">
<a class="nav-link" href="#">Projects</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
<div class="hover">
hover
</div>
Consider the section below
#projects:hover + .hover {
display: block;
}
Whenever you hover over #projects it will change the display to block on any sibling elements that immediately follows #projects but there is no elements with .hover that follows #projects. So this will never work. the .hover container is placed outside the nav bar and I believe you would like to show that .hover container when you hover of the link.
To note, with css, you can write rules to style elements from parent to child or surrounding siblings but you cannot go up the chain to the parent and afterwards to the parent sibling.
One option is to place the section inside the navbar but this will look somehwhat ugly to show a whole section in the nav ( I am assuming you do not want sub menu items).
You can achieve this, with some javascript (jquery for a shorter solution).
The solution below demonstrates a hover on a menu link that triggers the display of a section .hover which is outside the nav bar
function show() {
$(".hover").css({
display: "block"
})
}
function hide() {
$(".hover").css({
display: "none"
})
}
$("#projects").hover(show, hide)
.hover {
background: red;
display: none;
}
#navt {
border:solid red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
<nav class="navbar navbar-toggleable-md fixed-top">
<div class="container">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation" id="navt">
<span class="navbar-toggler-icon"></span>click here
</button>
<a class="navbar-brand" href="/">
<img src="..." alt="Logo">
</a>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link active" href="/">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item" id="projects">
<a class="nav-link" href="#">Projects</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
<div class="hover">
hover
</div>
The method what you have been trying only works for sibling elements.
Example: Two <div> elements (Try this)
<style type="text/css">
.faa {
height:200px;
width:200px;
background: blue;
}
.boo {
height:200px;
width:200px;
background: yellow;
}
.boo:hover ~ .faa{
display: none;
}
</style>
<div class="boo"></div>
<div class="faa"></div>
This can not be done with CSS, So Try below JQuery code block to solve your problem,
$(function() {
$("#projects").hover(function(){
$('.hover').show(400);
}, function(){
$('.hover').hide(400);
});
});
You can know more,
On a CSS hover event, can I change another div's styling?