I think it's a silly question but I'm struggling to adjust the header. Whenever I use the position as fixed or sticky, the margin doesn't work properly.
I want the same margin as the body section. But it's not working properly.
The current situation:
What I'm looking for:
codes I have used:
CSS:
.hh{
background-color:#BADA55;
height:150px;
border-radius:0px 0px 5px 5px;
box-shadow: 0 1px 1px rgba(0,0,0,0.08),
0 2px 2px rgba(0,0,0,0.12),
0 4px 4px rgba(0,0,0,0.16),
0 8px 8px rgba(0,0,0,0.20);
z-index:999;
position: sticky;
/*margin-right: 250px;*/
/*margin-left: 250px;*/
/*margin: 0 auto; */
width: auto;
top: 0;
overflow-x:hidden;
}
.logo{
width:58px;
height:58px;
}
.logoh{
font-size:32px;
float:right;
margin-left:12px; margin-top:3px;
font-family: Arial, Helvetica, sans-serif;
}
.bd{
border-top:3px solid #5D6E1D;
border-bottom:3px solid #5D6E1D;
line-height:0px;
}
HTML:
<div class="hh" >
<div style="width:100%">
<div class="container ">
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-6 col-sm-12" style="text-align:center; padding:10px">
<div style="display:inline-block">
<div class="navbar-brand">
<img class="logo" src="images/logo.png" style="float:left">
<p class="logoh" style="font-weight:500"> Linda Hammond Research</p>
</div>
</div>
</div>
<div class="col-md-3"></div>
</div>
</div>
<div style="margin-left:15px; margin-right:15px">
<nav class="navbar navbar-expand-lg navbar-light bd ">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation" style="float:right">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent" >
<ul class="navbar-nav nav-fill w-100">
<li class="nav-item active">
<a class="nav-link" href="index.php">Home </a>
</li>
<li class="nav-item active">
<a class="nav-link" href="about-me.php">About</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="research.php">Research </a>
</li>
<li class="nav-item active">
<a class="nav-link" href="reports.php">Reports </a>
</li>
<li class="nav-item active">
<a class="nav-link" href="professional-services.php">Professional Services </a>
</li>
<li class="nav-item active">
<a class="nav-link" href="speaker.php">Speaker </a>
</li>
<li class="nav-item active">
<a class="nav-link" href="prices.php">Prices </a>
</li>
<li class="nav-item active">
<a class="nav-link" href="testimonials.php">Testimonials </a>
</li>
<li class="nav-item active">
<a class="nav-link" href="terms-conditions.php">T&C </a>
</li>
<li class="nav-item active">
<a class="nav-link" href="contact.php">Contact </a>
</li>
</ul>
</div>
</nav>
</div>
</div>
</div>
A solution could be to create a new class that you will add to your header and content like so:
.bodyWidth {
width: 80%;
margin-left: auto;
margin-right: auto;
}
Add max-with:{{size second box}} to hh class
or
put both box into a container class.
<div class="container">
//first box
//second box
</div>
Related
I am trying to blur a dropdown menu for my website. It doesn't seem to work on my Apple devices though. I have tried Mac and iPhone. I am using ASP.NET Core to build the website.
How it's suppose to look
How it looks on Apple/Safari
Navbar style:
##media (max-width: 992px) {
#mainNavbarToggler {
position: absolute;
margin-top: 85px;
padding-left: 5px;
padding-right: 5px;
right: 0;
top:0;
background-color: rgba(0, 0, 0, .25);
border-radius: 10px;
width: 100%;
box-shadow: 0 2px 8px 0 rgba(0, 0, 0, .25), 0 3px 5px 0px rgba(0, 0, 0, 0.50) !important;
backdrop-filter:blur(10px);
-webkit-backdrop-filter:blur(10px);
}
}
Here's my Navbar code:
<!--Navigation Bar-->
<nav class="navbar navbar-expand-lg navbar-light d-lg-block shadow-custom" id="navbarMain" style="background-color: rgba(0, 0, 0, .25); z-index:2000">
<div class="container-fluid">
<a class="navbar-brand d-lg-none" asp-area="" asp-page="/Index">
<img src="/assets/logo/PortaBluTitleLogo.svg" alt="Porta Blu Title Logo" width="150" class="d-inline-block align-text-top filter-white">
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#mainNavbarToggler" aria-controls="mainNavbarToggler" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="mainNavbarToggler" style="-webkit-backdrop-filter: blur(10px)">
<!--Standard Navbar-->
<!--Brand-->
<a class="navbar-brand d-none d-lg-block" style="margin-left: 50px; margin-top: 0px" asp-area="" asp-page="/Index">
<img src="/assets/logo/PortaBluTitleLogo.svg" alt="Porta Blu Title Logo" width="200" class="d-inline-block align-text-top filter-white"></a>
<!--Links-->
<ul class="navbar-nav ms-auto" style="font-size: 25px">
<li class="nav-item">
<a class="nav-link" asp-area="" asp-page="/Venue">Venue</a>
</li>
<li class="nav-item">
<a class="nav-link" asp-area="" asp-page="/Office">Offices</a>
</li>
<li class="nav-item">
<a class="nav-link" asp-area="" asp-page="/Services">Services</a>
</li>
<li class="nav-item">
<a class="nav-link" asp-area="" asp-page="/Gallery">Gallery</a>
</li>
<li class="nav-item">
<a class="nav-link" asp-area="" asp-page="/Contact">Contact Us</a>
</li>
</ul>
<!--Standard Navbar End-->
<!--Icons-->
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link nav-icon instagram-gradient-text" href="https://www.instagram.com/portabluoffical/?hl=en" target="_blank" rel="nofollow">
<i class="bi bi-instagram" id="insta" style="color: black; font-size: 2rem"></i>
</a>
</li>
<li class="nav-item">
<a class="nav-link nav-icon" href="https://www.facebook.com/profile.php?id=100068916759970" target="_blank" rel="nofollow"><i class="bi bi-facebook" style="font-size: 2rem; color: cornflowerblue" ></i></a>
</li>
<li class="nav-item">
<a class="nav-link nav-icon" href="https://www.tiktok.com/##portabluvenue" target="_blank" rel="nofollow"><i class="bi bi-tiktok" id="tiktok" style="font-size: 2rem" ></i></a>
</li>
</ul>
<!--Icons End-->
</div>
</div>
</nav>
<!--Navigation Bar End-->
I have looked at almost all the resources on Stack, even inspected elements on safari and copied the code but still no dice. Is there a stylesheet i need to reference?
Also get this, in Visual Studio for Mac, it works with dotnet watch, but when I publish, it stops working. Is it something to do with the server and browser, meaning I have to specify conditions per browser?
I am using bootstrap 4 for my navbar, I can toogle down the hamburger button just fine but I can't toogle it back on the menu, it remains to be in a collapsed form. So how can I toogle it back to its menu?
I've tried data="collapse" on each nav-item just maybe it would work but it remained in a collapsed form.
.nav-fill .nav-item {
-webkit-box-flex: initial;
flex: initial;
text-align: initial;
}
ul li a.nav-link {
text-transform: uppercase;
font-weight: bold;
letter-spacing: 0.02em;
}
.navigation .bg-light{
background-color: transparent !important;
}
<nav class="navbar navbar-expand-lg navbar-dark bg-dark ">
<div class="container">
<button class="navbar-toggler ml-auto" type="button" data-toggle="collapse" data-target="#navbar10">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbar10">
<ul class="navbar-nav nav-fill w-100">
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="">Codeply</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>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
</div>
</div>
</nav>
fyi: I placed my navbar under my header (because I needed to), could that be the case?
header{
display: flex !important;
flex-direction: column;
}
/*** HEADER *****/
.logo-wrapper img {
width: 100%;
display: block;
}
.logo-wrapper {
width: 100%;
display: block;
position: relative;
}
/* Navbar */
.nav-fill .nav-item {
-webkit-box-flex: initial;
flex: initial;
text-align: initial;
}
header {
background: url(../images/header_img.png) no-repeat top center transparent;
padding: 0 0;
background-attachment: inherit;
background-size: cover;
}
.header-bottom {
padding: 20px 0;
}
ul li a.nav-link {
text-transform: uppercase;
font-weight: bold;
letter-spacing: 0.02em;
}
.navigation .bg-light{
background-color: transparent !important;
}
<header>
<div class="header-bottom">
<div class="container">
<div class="row">
<div class="icon-call col-md-4 col-xs-12 d-none d-md-block ">
<img src = "images/icon-call.png">xoxoxox
</div>
<div class="col-md-4 col-xs-12 col-sm-12">
<div class="logo-wrapper">
<img src = "images/logo.png" >
</div>
</div>
<div class="icon-social col-md-4 col-xs-12 d-none d-md-block">
<div class="social-media text-right">
<img src = "images/icon-fb.png" >
<img src = "images/icon-mail.png">
<img src = "images/icon-insta.png">
</div>
</div>
</div>
</div>
</div>
<div class="navigation">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<button class="navbar-toggler ml-auto" type="button" data-toggle="collapse" data-target="#navbar10">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse text-center" id="navbar10">
<ul class="navbar-nav nav-fill w-100">
<li class="nav-item active">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Services</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Results</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">References</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</div>
</div>
</nav>
</div>
</header>
your code is working fine, but try to use all the links properly like below
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
header{
display: flex !important;
flex-direction: column;
}
/*** HEADER *****/
.logo-wrapper img {
width: 100%;
display: block;
}
.logo-wrapper {
width: 100%;
display: block;
position: relative;
}
/* Navbar */
.nav-fill .nav-item {
-webkit-box-flex: initial;
flex: initial;
text-align: initial;
}
header {
background: url(../images/header_img.png) no-repeat top center transparent;
padding: 0 0;
background-attachment: inherit;
background-size: cover;
}
.header-bottom {
padding: 20px 0;
}
ul li a.nav-link {
text-transform: uppercase;
font-weight: bold;
letter-spacing: 0.02em;
}
.navigation .bg-light{
background-color: transparent !important;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<header>
<div class="header-bottom">
<div class="container">
<div class="row">
<div class="icon-call col-md-4 col-xs-12 d-none d-md-block ">
<img src = "images/icon-call.png">xoxoxox
</div>
<div class="col-md-4 col-xs-12 col-sm-12">
<div class="logo-wrapper">
<img src = "images/logo.png" >
</div>
</div>
<div class="icon-social col-md-4 col-xs-12 d-none d-md-block">
<div class="social-media text-right">
<img src = "images/icon-fb.png" >
<img src = "images/icon-mail.png">
<img src = "images/icon-insta.png">
</div>
</div>
</div>
</div>
</div>
<div class="navigation">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<button class="navbar-toggler ml-auto" type="button" data-toggle="collapse" data-target="#navbar10">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse text-center" id="navbar10">
<ul class="navbar-nav nav-fill w-100">
<li class="nav-item active">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Services</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Results</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">References</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</div>
</div>
</nav>
</div>
</header>
I have used a bootstrap slider with text overlay and it is disabling the nav bar when I scroll down the page. When the text is level with the nav bar which is fixed, the links are disabled
Not sure if it is a bootstrap bug as I have used other sliders in the past which seem fine. The only think it that is is a one page website with many sections so the navbar needs to be fixed
<!------------NavigationBar------------>
<section id="nav-bar">
<nav class="navbar navbar-expand-lg navbar-light">
<a class="navbar-brand" href="#"><img src="img/logo1.png" 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 ml-auto">
<li class="nav-item active">
<a class="nav-link" href="#top">HOME</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#about">ABOUT US</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#services">SERVICES</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#team">OUR TEAM</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#price">PRICE PLANS</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#testimonials">TESTIMONIALS</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#contact">CONTACT</a>
</li>
</ul>
</div>
</nav>
</section>
<!------------Slider------------>
<div id="slider">
<div id="headerSlider" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#headerSlider" data-slide-to="0" class="active"></li>
<li data-target="#headerSlider" data-slide-to="1"></li>
<li data-target="#headerSlider" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<img src="img/img1.jpg" class="d-block w-100" alt="...">
<div class="carousel-caption">
<h5>Business Consultants Is Who We Are</h5>
</div>
</div>
<div class="carousel-item">
<img src="img/img2.jpg" class="d-block w-100" alt="...">
<div class="carousel-caption">
<h5>Create A Business Niche</h5>
</div>
</div>
<div class="carousel-item">
<img src="img/img3.jpg" class="d-block w-100" alt="...">
<div class="carousel-caption">
<h5>Business Plan Support</h5>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#headerSlider" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#headerSlider" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
/*-----------Navigation----------*/
#nav-bar{
position: fixed;
width: 100%;
top: 0;
z-index: 10;
}
.navbar-brand img{
height: 80px;
padding-left: 30px;
}
.navbar-nav li{
padding: 0 10px;
}
.navbar-nav li a{
float: right;
text-align: left;
}
#nav-bar ul li a:hover{
color: #586949!important;
}
.navbar{
background: #fff;
}
.navbar-toggle{
border: none!important;
}
.nav-link{
color:green!important;
font-weight: 600;
font-size: 16px;
}
/*-----------Slider----------*/
#slider{
width: 100%;
background-color:rgba(255,0,0,0.1);
}
/*.carousel-item img{
height: 800px;
}*/
.carousel-caption{
top: 50%;
transform: translateY(-50%);
bottom: initial!important;
}
.carousel-caption h5{
color: #fff;
font-size: 40px;
font-weight: bold;
}
I have a navbar, and it works fine when there are only single-line items:
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="#">FAQ</a>
</li>
<li class="nav-item">
<a class="nav-link profile" href="#">
<div class="profile-info">
<span class="name">Артём</span>
</div>
</a>
</li>
</ul>
</div>
But when item is multiline, the other items lose center vertical alignment and align top instead:
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="#">FAQ</a>
</li>
<li class="nav-item">
<a class="nav-link profile" href="#">
<div class="profile-info">
<span class="name">Артём</span>
<span class="balance">31337 ₽</span>
</div>
</a>
</li>
</ul>
</div>
My SASS code:
#site-header {
background: #2d3840;
border-bottom: solid 1px #20272d;
height: 83px;
.navbar-brand {
color: white;
}
.nav-item {
&:not(:first-child) {
margin-left: 25px;
}
&:not(:last-child) {
margin-right: 25px;
}
// General link
a.nav-link {
color: white;
font-size: 16px;
text-align: center;
#include transition(0.5s);
&:hover {
#include transition(0.3s);
color: $color-accent;
}
&.active {
padding: 6px 21px 6px 21px;
background: $color-accent;
border-radius: 17.5px;
box-shadow: 0 2px 10px 0 rgba(90, 175, 238, 0.6);
&:hover {
color: white;
box-shadow: none;
}
}
// Profile
&.profile {
.profile-info {
display: inline-block;
.name {
display: block;
font-weight: bold;
}
.balance {
display: block;
font-size: 16px;
font-weight: bold;
color: $color-accent;
}
}
}
}
}
}
Desired:
So, how to center items when there are multi-line items?
Remove the profile-info and use these classes for the a tag.
d-flex - to make it flex
flex-column - to change its flex-direction property to column
text-right - to align its inline children on the right side of it
<li class="nav-item">
<a class="nav-link d-flex flex-column text-right" href="#">
<span class="name">Артём</span>
<span class="balance">31337 ₽</span>
</a>
</li>
To align the other items vertically in the center of the list, use align-self-center for each one of the li elements.
<li class="nav-item align-self-center">
<a class="nav-link" href="#">FAQ</a>
</li>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/js/bootstrap.js"></script>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</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 ml-auto">
<li class="nav-item active align-self-center">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item align-self-center">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item align-self-center">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
<li class="nav-item align-self-center">
<a class="nav-link" href="#">FAQ</a>
</li>
<li class="nav-item ">
<a class="nav-link d-flex flex-column text-right" href="#">
<span class="name">Артём</span>
<span class="balance">31337 ₽</span>
</a>
</li>
</ul>
</div>
</nav>
What I am trying to achieve is this:
Without using javascript/jquery.
I have a topbar and a sidebar. On smaller screens, I want the sidebar to collapse and have a button on top, and when the button is clicked the sidebar toggles horizontally, adding opacity to the background, putting the button on the topbar, and putting all content from within the topbar inside the sidebar.
Similar to when the screen is small for Youtube page, and the sign in option appears on the sidebar.
This is the code I have so far :JSFIDDLE
<header>
<nav class="navbar navbar-expand-sm fixed-top navbar-light bg-faded">
<button class="navbar-toggler " type="button" data-toggle="collapse" data-target="#sidebar" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<img class="navbar-brand navbar-logo" src="" />
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav ml-auto user-info">
<li class="avatar">
<img src="">
</li>
<li class="nav-item dropdown">
<a class="nav-link ">Hello</a>
</li>
</ul>
</div>
</nav>
</header>
<div class="container-fluid">
<div id="mySidenav">
<nav class="col-sm-3 col-md-3 col-6 col-lg-2 d-sm-block sidebar collapse
width " id="sidebar">
<ul class="nav nav-pills flex-column">
<li class="nav-item collapsed side" data-toggle="collapse" data-target="#home">
<a class="nav-link">
<img src="" />Home </a>
</li>
<ul class="sub-menu collapse" id="home">
<li class="nav-item list-unstyled">
<a class="nav-link">Submenu1</a>
</li>
<li class="nav-item list-unstyled">
<a class="nav-link">Submenu2</a>
</li>
<li class="nav-item list-unstyled">
<a class="nav-link">Submenu3</a>
</li>
<li class="nav-item list-unstyled">
<a class="nav-link">Submenu4</a>
</li>
</ul>
<li class="nav-item side">
<a class="nav-link">
<img src="a" />Menu Item</a>
</li>
<li class="nav-item side">
<a class="nav-link">
<img src="" />Menu Item</a>
</li>
<li class="nav-item side">
<a class="nav-link">
<img src="" />Menu Item</a>
</li>
<li class="nav-item side">
<a class="nav-link">
<img src="" />Menu Item</a>
</li>
</ul>
</nav>
</div>
<main role="main" class="col-sm-9 ml-sm-auto col-md-9 col-lg-10 pt-3 content">
<h1>
Main Content here
</h1>
</main>
</div>
in your JSFiddle change css (top has to be 0px) : JsFiddle
.sidebar {
position: fixed;
top: 0px;
left: 0;
z-index: 1;
padding: 0;
overflow-x: hidden;
/* Scrollable contents if viewport is shorter than content. */
border-right: 1px solid #eee;
background-color: black;
height: 100%;
}