I am trying to create a website using this codepen(enter link description here).
The problem I'm having is when I make the window size smaller, the profile section and main content section start to overlap. I think the codepen is using bootstrap grid system here so I don't really understand why this is happening.
content overlapping image
Here are the codes.
HTML
<!--navbar-->
<nav class="navbar navbar-expand-lg navbar-dark fixed-top" id="mainNav">
<div class="container">
<a class="navbar-brand js-scroll-trigger" href="#page-top">Bootstrap</a>
<div>
<ul class="navbar-nav text-uppercase ml-auto">
<li class="nav-item">
<a class="btn btn-primary my-2 my-sm-0" type="submit"><i class="fa fa-sign-out"></i> Log out</a>
</li>
</ul>
</div>
</div>
</nav>
<!--our content goes here-->
<div class="container content">
<div class="row profile">
<div class="col-md-3">
<div class="profile-sidebar position-fixed">
<!-- SIDEBAR USERPIC -->
<div class="profile-userpic">
<img src="https://media.rockstargames.com/chinatownwars/global/downloads/avatars/zhou_256x256.jpg" class="img-responsive" alt="">
</div>
<!-- END SIDEBAR USERPIC -->
<!-- SIDEBAR USER TITLE -->
<div class="profile-usertitle">
<div class="profile-usertitle-name">
Jason Davis
</div>
<div class="profile-usertitle-job">
Developer
</div>
</div>
<!-- END SIDEBAR USER TITLE -->
<!-- SIDEBAR BUTTONS -->
<div class="profile-userbuttons">
<button type="button" class="btn btn-success btn-sm">Follow</button>
<button type="button" class="btn btn-danger btn-sm">Message</button>
</div>
<!-- END SIDEBAR BUTTONS -->
<!-- SIDEBAR MENU -->
<div class="profile-usermenu sidebar-sticky">
<ul class="nav flex-column">
<li class="active nav-item">
<a href="#" class="nav-link active">
<i class="fa fa-home"></i>
Overview </a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://codepen.io/jasondavis/pen/jVRwaG?editors=1000">
<i class="fa fa-user"></i>
Account Settings </a>
</li>
<li class="nav-item">
<a class="nav-link" href="#" target="_blank">
<i class="fa fa-check"></i>
Tasks </a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<i class="fa fa-flag"></i>
Help </a>
</li>
</ul>
</div>
<!-- END MENU -->
</div>
</div>
<div class="col-md-9">
<div class="profile-content">
Some user related content goes here...
<h1>test</h1>
<h1>test</h1>
<h1>test</h1>
<h1>test</h1>
<h1>test</h1>
<h1>test</h1>
<h1>test</h1>
<h1>test</h1>
<h1>test</h1>
<h1>test</h1>
<h1>test</h1>
<h1>test</h1>
<h1>test</h1>
<h1>test</h1>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-3">
</div>
<div class="col-md-9 ft">
<footer class="footer">
<div class="row">
<div class="col-md-4">
<span class="copyright">Copyright © Your Website 2018</span>
</div>
<div class="col-md-4">
<ul class="list-inline social-buttons">
<li class="list-inline-item">
<a href="https://github.com/ELMORABITYounes">
<i class="fa fa-github"></i>
</a>
</li>
<li class="list-inline-item">
<a href="https://www.facebook.com/younes.elmorabit.92">
<i class="fa fa-facebook"></i>
</a>
</li>
<li class="list-inline-item">
<a href="https://www.linkedin.com/in/younes-elmorabit-2a162310b/">
<i class="fa fa-linkedin"></i>
</a>
</li>
</ul>
</div>
<div class="col-md-4">
<ul class="list-inline quicklinks">
<li class="list-inline-item">
Privacy Policy
</li>
<li class="list-inline-item">
Terms of Use
</li>
</ul>
</div>
</div>
</footer>
</div>
</div>
</div>
CSS
html, body {
height: 100%;
}
body {
display: flex;
flex-direction: column;
background: #F1F3FA;
}
body {
overflow-x:hidden;
}
#mainNav {
background-color: darkslategrey;
color:white;
}
#mainNav .navbar-brand {
color: #fed136;
font-family: 'Kaushan Script', 'Helvetica Neue', Helvetica, Arial, cursive;
}
.content {
flex: 1 0 auto;
}
.footer {
flex-shrink: 0;
}
footer {
text-align: center;
background-color: white;
}
.ft{
padding-left:22px;
padding-right:31px;
}
footer span.copyright {
font-size: 90%;
line-height: 40px;
text-transform: none;
font-family: 'Montserrat', 'Helvetica Neue', Helvetica, Arial, sans-serif;
color:blak;
}
footer ul.quicklinks {
font-size: 90%;
line-height: 40px;
margin-bottom: 0;
text-transform: none;
font-family: 'Montserrat', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
ul.social-buttons {
margin-bottom: 0;
}
ul.social-buttons li a {
font-size: 20px;
line-height: 40px;
display: block;
width: 40px;
height: 40px;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;
color: white;
border-radius: 100%;
outline: none;
background-color: #212529;
}
ul.social-buttons li a:active, ul.social-buttons li a:focus, ul.social-buttons li a:hover {
background-color: #fed136;
}
.content{
margin-top:60px;
}
/* Profile container */
.profile {
margin: 20px 0;
}
/* Profile sidebar */
.profile-sidebar {
padding: 20px 0 10px 0;
background: #fff;
}
.profile-userpic img {
float: none;
display:block;
margin:auto;
width: 50%;
height: 50%;
-webkit-border-radius: 50% !important;
-moz-border-radius: 50% !important;
border-radius: 50% !important;
}
.profile-usertitle {
text-align: center;
margin-top: 20px;
}
.profile-usertitle-name {
color: #5a7391;
font-size: 16px;
font-weight: 600;
margin-bottom: 7px;
}
.profile-usertitle-job {
text-transform: uppercase;
color: #5b9bd1;
font-size: 12px;
font-weight: 600;
margin-bottom: 15px;
}
.profile-userbuttons {
text-align: center;
margin-top: 10px;
}
.profile-userbuttons .btn {
text-transform: uppercase;
font-size: 11px;
font-weight: 600;
padding: 6px 15px;
margin-right: 5px;
}
.profile-userbuttons .btn:last-child {
margin-right: 0px;
}
.profile-usermenu {
margin-top: 30px;
}
.profile-usermenu ul li {
border-bottom: 1px solid #f0f4f7;
}
.profile-usermenu ul li:last-child {
border-bottom: none;
}
.profile-usermenu ul li a {
color: #93a3b5;
font-size: 14px;
font-weight: 400;
}
.profile-usermenu ul li a i {
margin-right: 8px;
font-size: 14px;
}
.profile-usermenu ul li a:hover {
background-color: #fafcfd;
color: #5b9bd1;
}
.profile-usermenu ul li.active {
border-bottom: none;
}
.profile-usermenu ul li.active a {
color: #5b9bd1;
background-color: #f6f9fb;
border-left: 2px solid #5b9bd1;
margin-left: -2px;
}
/* Profile Content */
.profile-content {
padding: 20px;
background: #fff;
min-height: 460px;
}
.nav>li {
position: relative;
display: block;
}
Any help would be appreciated as I have tried multiple methods with no success.
Thank you in advance.
I see you have added a class position-fixed to the element with class profile-sidebar, so this element will remain fixed no matter what.
You could remove the class position-fixed and handle everything in the CSS, using media queries to set its position for smaller and larger screens.
<div class="profile-sidebar position-fixed">
The position-fixed does not allow your profile-sidebar to move away.
It works otherwise https://jsfiddle.net/f9hot4yk/
Instead of adding the position fixed class you can add profile-sidebar into a min-width location in your CSS where you add the fixed property to the sidebar.
Like this:
#media only screen and (min-width: 1200px) {
.profile-sidebar {
position: fixed;
}
}
Related
so I've tried a few different things out. But ultimately no success. I'm trying to change the colour of the "Home" link to stay a different colour than the rest when we are specifically on the homepage. So for example, say I'm on the homepage, I specifically want that colour to be orange for the home link, and then when I click on About link, about link changes to orange and the home goes to default white
Html:
<!--Header-->
<header class="header-main">
<!--Navigation menu-->
<nav class="navigation">
<!--Bakingwithwill Logo-->
<img class="logo" src="imgs/bww.png" alt="Bakingwithwill" />
<!--Navigation links-->
<div class="nav-links">
<!--Unordered list of navigation items-->
<ul class="nav-menu">
<li id="active-home" class="nav-items">Home</li>
<li class="nav-items">About</li>
<li class="nav-items">Order</li>
<li class="nav-items">Contact</li>
<li class="nav-items">Cart</li>
</ul>
</div>
<div class="footer-nav">
<!--Footer portion of the side navbar-->
<div class="nav-social">
<!--Navigation of Bakingwithwill social media accounts-->
<ul class="nav-social-list">
<li class="social-icons">
<i class="fab fa-facebook"></i>
</li>
<li class="social-icons">
<i class="fab fa-instagram"></i>
</li>
</ul>
</div>
<p class="copyright">Copyright Bakingwithwill</p>
<!--Copyright-->
</div>
</nav>
<img class="header-banner" src="imgs/bww-home-banner.jpg" alt="Bakingwithwill bread banner"/>
<!--Main image-->
<div class="main">
<!--Contents outside the side navbar representing header page-->
<h2 class="baking-heading">Bakingwithwill</h2>
<h1 class="welcome-heading">Welcome!</h1>
<h2 class="intro-heading">Get a slice of the best bread in<br>
Chatham-Kent!</h2>
</div>
</header>
CSS:
/*Base styles*/
body {
font-family: 'Oswald', sans-serif;
}
h1 {
font-family: 'Satisfy', cursive;
}
/*Home styles*/
header {
width: 100%;
height: 585px;
}
/*Side bar navigation menu*/
.navigation {
height: 100%;
width:160px;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #3D3732;
overflow-x: hidden;
padding-top: 20px;
opacity: 90%;
}
.navigation a {
text-decoration: none;
}
.logo {
border-radius: 50%;
height: 70px;
width: 70px;
margin-top: 10px;
margin-left: 45px;
}
#active-home:link, #active-home:visited {
color:#E88F2A !important;
}
.navigation li, p {
text-decoration: none;
color: #FFFFFF;
display: block;
text-align: center;
}
.navigation .nav-items {
padding-right: 30px;
padding-top: 10px;
text-align: center;
}
.navigation .social-icons {
list-style-type: none;
text-align: center;
display: inline;
font-size: 15px;
padding: 5px;
margin-top: 50px;
color: #FFFFFF;
margin-left: 15px;
text-decoration: none;
}
.navigation li:hover {
color: #E88F2A;
}
.navigation p {
font-size: 10px;
text-align: center;
padding: 6px 8px 6px 16px;
}
.main {
margin-left: 160px;
padding: 0px 10px;
}
.footer-nav {
margin-top: 200px;
}
/*Social media icons*/
.navigation i {
text-decoration: none;
color: #FFFFFF;
}
.navigation i:hover {
color: #E88F2A;
}
/*Text overlaying the image*/
.baking-heading {
color: #E88F2A;
font-family: 'Satisfy', cursive;
position: relative;
margin-top: 40px;
padding-left: 50px;
font-size: 50px;
}
.welcome-heading, .intro-heading {
font-family: 'Oswald', sans-serif;
position: relative;
}
.welcome-heading, .baking-heading {
transform: rotate(-13deg);
}
.welcome-heading {
padding-left: 130px;
font-size: 50px;
color: #FFFFFF;
}
.intro-heading {
padding-top: 200px;
font-size: 50px;
text-align: center;
color: #FFFFFF;
}
.header-banner {
/*Image styles*/
margin-top: -40px;
position: absolute;
width: 100%;
height: 585px;
}
So for example, say I'm on the homepage, I specifically want that
colour to be orange for the home link, and then when I click on About
link, about link changes to orange and the home goes to default white
One CSS-only approach is to:
add a class to the <body> element of each page
add classes to each of your links (or to the list-items containing the links)
Home Page:
<body class="home-page">
<ul class="nav-menu">
<li class="nav-items home">Home</li>
<li class="nav-items about">About</li>
<li class="nav-items order">Order</li>
<li class="nav-items contact">Contact</li>
<li class="nav-items cart">Cart</li>
</ul>
About Page:
<body class="about-page">
<ul class="nav-menu">
<li class="nav-items home">Home</li>
<li class="nav-items about">About</li>
<li class="nav-items order">Order</li>
<li class="nav-items contact">Contact</li>
<li class="nav-items cart">Cart</li>
</ul>
Then you can change the color of the relevant link on each page:
.nav-items a {
color: white;
}
.home-page .nav-items.home a,
.about-page .nav-items.about a {
color: orange;
}
You need to add a class to the active link and #id is not recommended for styling. Also, the pseudo classes that you're using is blocking your desired outcome. Try changing :
#active-home:link,
#active-home:visited {
color: #e88f2a !important;
}
to:
.active {
color: #e88f2a !important;
}
Afterwards, place the .active class into your link code for each page. So for home it would be:
<li class="nav-items active">Home</li>
and for your about page:
<a href="#">
<li class="nav-items">Home</li>
</a>
<a href="about.html">
<li class="nav-items active">About</li>
</a>
and so on...
Hi I have arrange my top navigation in such a way that on the left contains 3 different button, in the middle contains a long button and on the right contains a 3 dots button.
the 3 dots is a drop down menu. However, my drop down menu seems to appear behind the div panel container. I read many online solution saying is caused by overflow: hidden however in my case, i need the overflow:hidden in order for left, center and right alignment to work. However, this cause my drop down menu to appear behind. Any idea how this can be solved? below is my code:
css:
body {
height: 100%;
font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
padding: 0;
margin: 0;
}
.page-container {
height: 80vh;
margin-top: 10px
}
.panel-container {
display: flex;
height: 100%;
flex-direction: row;
border: 2px solid #000;
overflow: auto;
xtouch-action: none;
}
.....
....
/**********Alignment for top navigation*************/
.topheader {
margin-bottom:7px;
width:100%;
}
.topright{
width: auto;
overflow:hidden;
background-color:#1E90FF;
color:#fff;
font-weight:bold;
font-size:19px;
margin:3px;
border-radius:7px;
padding:5px;
text-align:center;
}
.topleft{
float:left;
width:350px;
padding:3px;
}
.nav-tab .nav-items {
border-style: none;
background-color:#1E90FF;
font-weight:bold;
font-size:12px;
margin:1px;
border-radius:5px;
padding:5px;
}
.nav-tab .nav-link {
color: #fff;
}
.threedots:after {
content: '\2807';
color: #fff;
font-size:17px;
}
HTML:
<div class="page-container">
<div class="topheader">
<div class="topleft">
<ul class="nav nav-tab" id="myTab" role="tablist">
<li class="nav-items">
<a class="nav-link" id="one-tab" data-toggle="tab" href="#one" role="tab" aria-controls="one"
aria-selected="true">2019-01-01</a>
</li>
<li class="nav-items">
<a class="nav-link" id="two-tab" data-toggle="tab" href="#two" role="tab" aria-controls="two"
aria-selected="false">2019-01-02</a>
</li>
<li class="nav-items">
<a class="nav-link" id="three-tab" data-toggle="tab" href="#three" role="tab" aria-controls="three"
aria-selected="false">2019-01-03</a>
</li>
</ul>
</div>
<div class="topright">
<div class="row">
<div class="col-md-11">
Kelvin
</div>
<div class="col-md-1">
<div class="dropdown">
<button class="btn" type="button" data-toggle="dropdown"><div class="threedots"></div>
<span class="caret"></span></button>
<ul class="dropdown-menu dropdown-menu-right">
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="panel-container">
....
....
....
Below is where the drop down menu is being hidden
Try display: flex on topheader and add flex-grow: 1 on topright div. You should be able to achieve the header alignment without overflow: hidden. Also remove float: left from topleft
body {
height: 100%;
font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
padding: 0;
margin: 0;
}
.page-container {
height: 80vh;
margin-top: 10px
}
.panel-container {
display: flex;
height: 100%;
flex-direction: row;
border: 2px solid #000;
overflow: auto;
xtouch-action: none;
}
.topheader {
margin-bottom: 7px;
display: flex;
}
.topright {
background-color: #1E90FF;
color: #fff;
font-weight: bold;
font-size: 19px;
margin: 3px;
border-radius: 7px;
padding: 5px;
text-align: center;
flex-grow: 1;
}
.topleft {
width: 350px;
padding: 3px;
}
.nav-tab .nav-items {
border-style: none;
background-color: #1E90FF;
font-weight: bold;
font-size: 12px;
margin: 1px;
border-radius: 5px;
padding: 5px;
}
.nav-tab .nav-link {
color: #fff;
}
.threedots:after {
content: '\2807';
color: #fff;
font-size: 17px;
}
.dropdown-menu {
color: #000;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<div class="page-container">
<div class="topheader">
<div class="topleft">
<ul class="nav nav-tab" id="myTab" role="tablist">
<li class="nav-items">
<a class="nav-link" id="one-tab" data-toggle="tab" href="#one" role="tab" aria-controls="one" aria-selected="true">2019-01-01</a>
</li>
<li class="nav-items">
<a class="nav-link" id="two-tab" data-toggle="tab" href="#two" role="tab" aria-controls="two" aria-selected="false">2019-01-02</a>
</li>
<li class="nav-items">
<a class="nav-link" id="three-tab" data-toggle="tab" href="#three" role="tab" aria-controls="three" aria-selected="false">2019-01-03</a>
</li>
</ul>
</div>
<div class="topright">
<div class="row">
<div class="col-md-11">
Kelvin
</div>
<div class="col-md-1">
<div class="dropdown">
<button class="btn" type="button" data-toggle="dropdown"><div class="threedots"></div>
<span class="caret"></span></button>
<ul class="dropdown-menu dropdown-menu-right">
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
The problem seems to be, that your container class of the menu topright has set the property overflow to hidden. That causes, that the part of the dropdown which is higher than the container is hidden. If you remove the overflow:hidden part, the dropdown should be shown correct.
I have a bootstrap 4 nav that that works fine except that I cannot figure out how to get the dropdown items into a horizontal subnav whose items centered on the page instead of flush left.
Here's my existing code:
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<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>
</head>
<body>
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<!-- Brand -->
<a class="navbar-brand" href="#">Logo</a>
<!-- Links -->
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Link 1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link 2</a>
</li>
<!-- Dropdown -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbardrop" data-toggle="dropdown">
Dropdown link
</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Link 1</a>
<a class="dropdown-item" href="#">Link 2</a>
<a class="dropdown-item" href="#">Link 3</a>
</div>
</li>
</ul>
</nav>
<br>
<div class="container">
<h3>Navbar With Dropdown</h3>
<p>This example adds a dropdown menu in the navbar.</p>
</div>
Here's what I would like the menu to look like when a top-level nav link is pressed.
I have been able to get close to this but am having particular difficulty in centering the items in the red subnav.
This what I have that is closer:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
body {
font-family: Arial, Helvetica, sans-serif;
margin: 0;
}
.navbar {
overflow: hidden;
background-color: #333;
}
.navbar a {
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.subnav {
float: left;
overflow: hidden;
}
.subnav .subnavbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.navbar a:hover, .subnav:hover .subnavbtn {
background-color: red;
}
.subnav-content {
display: none;
position: absolute;
left: 0;
background-color: red;
width: 100%;
z-index: 1;
}
.subnav-content a {
float: left;
color: white;
text-decoration: none;
}
.subnav-content a:hover {
background-color: #eee;
color: black;
}
.subnav:hover .subnav-content {
display: block;
}
</style>
</head>
<body>
<div class="navbar">
Home
<div class="subnav">
<button class="subnavbtn">About <i class="fa fa-caret-down"></i></button>
<div class="subnav-content">
Company
Team
Careers
</div>
</div>
<div class="subnav">
<button class="subnavbtn">Services <i class="fa fa-caret-down"></i></button>
<div class="subnav-content">
Bring
Deliver
Package
Express
</div>
</div>
<div class="subnav">
<button class="subnavbtn">Partners <i class="fa fa-caret-down"></i></button>
<div class="subnav-content">
Link 1
Link 2
Link 3
Link 4
</div>
</div>
Contact
</div>
<div style="padding:0 16px">
<h3>Subnav/dropdown menu inside a Navigation Bar</h3>
<p>Hover over the "about", "services" or "partners" link to see the sub navigation menu.</p>
</div>
</body>
</html>
Still can't figure out how to center text in subnav - again
Any help greatly appreciated.
This solution works but it can be a little tedious. I've wrapped the drop-down items in a div and gave them each their own unique class and a "center" class. Their unique classes set their width, and the center class centers them using auto margins. Here is the edited code:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
body {
font-family: Arial, Helvetica, sans-serif;
margin: 0;
}
.navbar {
overflow: hidden;
background-color: #333;
}
.navbar a {
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.subnav {
float: left;
overflow: hidden;
}
.subnav .subnavbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.navbar a:hover,
.subnav:hover .subnavbtn {
background-color: red;
}
.subnav-content {
display: none;
position: absolute;
left: 0;
background-color: red;
width: 100%;
z-index: 1;
}
.subnav-content a {
float: left;
color: white;
text-decoration: none;
}
.subnav-content a:hover {
background-color: #eee;
color: black;
}
.subnav:hover .subnav-content {
display: block;
}
/* NEW CSS STARTS HERE */
.center {
margin: 0 auto;
}
.about {
width: 261px;
}
.services {
width: 336px;
}
.partners {
width: 299px;
}
</style>
</head>
<body>
<div class="navbar">
Home
<div class="subnav">
<button class="subnavbtn">About <i class="fa fa-caret-down"></i></button>
<div class="subnav-content">
<div class="center about">
Company
Team
Careers
</div>
</div>
</div>
<div class="subnav">
<button class="subnavbtn">Services <i class="fa fa-caret-down"></i></button>
<div class="subnav-content">
<div class="center services">
Bring
Deliver
Package
Express
</div>
</div>
</div>
<div class="subnav">
<button class="subnavbtn">Partners <i class="fa fa-caret-down"></i></button>
<div class="subnav-content">
<div class="center partners">
Link 1
Link 2
Link 3
Link 4
</div>
</div>
</div>
Contact
</div>
<div style="padding:0 16px">
<h3>Subnav/dropdown menu inside a Navigation Bar</h3>
<p>Hover over the "about", "services" or "partners" link to see the sub navigation menu.</p>
</div>
</body>
</html>
Not sure if you want it to span the entire width of the screen but if you want to just have them be organized in a row instead of a column you can add a bootstrap d-flex to not have it be in the default display:block
<div class="dropdown-menu d-flex">
<a class="dropdown-item" href="#">Link 1</a>
<a class="dropdown-item" href="#">Link 2</a>
<a class="dropdown-item" href="#">Link 3</a>
</div>
I am trying to understand how to get this work. I have a navbar with logo on left and menu links on the right. When the screen reaches 768px, menu links should disappear and menu icon should show up instead. And when menu icon is pressed, menu overlay should appear with those links and some button and links.
My example below:
<nav class="navbar navbar-expand-md fixed-top navbar-dark" id="section1">
<div class="container">
<a class="navbar-brand" href="#"><img class="company-logo" src="img/company-logo.svg"></a>
<button class="navbar-toggler" type="button" data-target="#collapsingNavbarMd">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse" id="collapsingNavbarMd">
<ul class="nav navbar-right">
<li class="nav-item">
<a class="nav-link" href="#works">Works</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#services">Services</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#about">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#contact-us">Contact Us</a>
</li>
<section class="contact-buttons">
<div class="ask-button">
<button class="btn-outlined">Ask me</button>
</div>
<div class="social-icons">
<div class="whatsapp-icon social-icon">
<img src="img/whatsapp-icon.svg" alt="WhatsApp">
</div>
<div class="linkedin-icon social-icon">
<img src="img/linkedin-icon.svg" alt="LinkedIn">
</div>
<div class="facebook-icon social-icon">
<img src="img/facebook-icon.svg" alt="Facebook">
</div>
<div class="twitter-icon social-icon">
<img src="img/twitter-icon.svg" alt="Twitter">
</div>
</div>
</section>
</ul>
</div>
</div>
</nav>
CSS:
.navbar {
padding: 0;
.company-logo {
width: 140px;
height: auto;
}
.company-logo:hover {
opacity: 0.7;
}
}
.navbar .container {
margin-top: 30px;
}
.navbar .contact-buttons {
display: none;
}
.navbar button {
display: block;
}
.navbar-right .nav-item .nav-link {
padding: 0;
padding-left: 2.5rem;
color: #fff;
font-size: 1rem;
font-weight: 400;
}
.navbar-dark .navbar-toggler {
border-color: transparent;
z-index: 2;
}
.navbar-toggler {
padding: 0;
}
.navbar {
button:focus {
outline: none;
}
}
.navbar-expand-md .container {
padding-right: 30px;
padding-left: 30px;
}
.navbar-expand-md .navbar-collapse {
justify-content: flex-end;
}
Overlay style should be like this:
.navbar-overlay {
display: block;
background-color: #585858;
position: relative;
width: 100%;
text-align: center;
display: flex;
.container {
flex-direction: column;
padding: 12vh;
ul {
flex-direction: column;
}
}
.navbar-right .nav-item .nav-link {
padding: 0;
padding-left: 0;
color: #fff;
font-size: 3rem;
margin-bottom: 30px;
font-weight: 500;
}
.company-logo {
display: none;
}
.contact-buttons {
display: block;
}
}
I need to align some elements in the center when the navbar is collapsed in responsive view, via the collapse button
At the moment I dont like the way my searchbox is padded, is there a way I could center it better?
My 'bell notification icon' and 'user dropdown' currently are position to the left, I want these to be positioned in the middle.
this is currently what it looks like:
I would like this to work in other browsers as well.
thank you, here is my code:
body {
padding-top: 102px;
background-color: #4d4d4d;
font-family: 'Lato', verdana, sans-serif;
}
.container {
width: 1530px;
margin-top: 0;
}
.navbar-fixed-top {
background-color: #fff;
}
.navbar-header {
min-height: 80px;
}
.hamburger-icon {
margin-top: 20px;
}
.navbar-default .navbar-brand {
line-height: 45px;
font-size: 45px;
color: #010101;
text-transform: uppercase;
}
.navbar-default .navbar-brand span {
font-style: normal;
color: #ff5500;
}
.dropdown-toggle.inbox {
margin-bottom: 5px;
}
.dropdown-menu.bell {
background-color: #f8f8f8;
border-radius: 0;
box-shadow: 0;
}
.dropdown-menu.bell h4 {
padding: 10px 0;
color: #010101;
text-align: center;
display: block;
}
.dropdown-menu.bell li a {
padding-top: 5px;
padding-bottom: 5px;
}
.nav>li.dropdown.bell>a:hover,
.nav>li.dropdown.bell>a:focus {
background-color: transparent;
}
.dropdown-menu.bell li.divider {
padding: 0;
margin: 0 20px;
}
.dropdown-menu.bell .label {
background-color: transparent;
color: #ff5500;
font-weight: 100;
}
.badge-notify {
background: #ff5500;
margin-top: -24px;
margin-left: -20px;
height: 1.7em;
}
/* caret for notification dropdown */
.dropdown-menu.bell:before {
position: absolute;
top: -10px;
right: 10%;
display: inline-block;
border-right: 10px solid transparent;
border-bottom: 10px solid #ccc;
border-left: 10px solid transparent;
border-bottom-color: rgba(0, 0, 0, 0.2);
content: '';
}
.dropdown-menu.bell:after {
position: absolute;
top: -9px;
right: 10%;
display: inline-block;
border-right: 9px solid transparent;
border-bottom: 9px solid #f8f8f8;
border-left: 9px solid transparent;
content: '';
}
.user span.fullname {
font-size: 14px;
color: #010101;
font-weight: 400;
}
.user span:last-child {
padding-right: 10px;
}
.user span:first-child {
padding-right: 30px;
padding-left: 10px;
}
.user .dropdown-menu.user-list {
width: 100%;
border-radius: 0;
border: 0;
background-color: #f8f8f8
}
.user .dropdown-menu.user-list li a {
margin: 5px 0px;
color: #010101;
}
.user .dropdown-menu.user-list li a:hover {
background-color: transparent;
color: #ff5500;
}
.user .dropdown-menu.user-list li.divider {
padding: 0;
margin: 0 20px;
}
/* Large desktop */
#media (max-width: 1590px) {
.container {
width: auto;
}
}
/* Portrait tablet to landscape and desktop */
#media (max-width: 979px) {}
/* Landscape phone to portrait tablet */
#media (max-width: 768px) {
.container {
width: auto;
}
.dropdown.bell .inbox {
width: 100% !important;
}
.dropdown-menu.bell h4 {
margin: 0 0;
}
.dropdown-menu.bell:before,
.dropdown-menu.bell:after {
display: none;
}
}
/* Landscape phones and down */
#media (max-width: 480px) {} .search .input-group {
padding-top:15px;
font-family:'Lato',
sans-serif;
}
.search .input-group input.search-field {
padding: 0;
border-radius: 0;
border: 0;
box-shadow: none;
background-color: #fff;
font-size: 18px;
font-weight: 100;
}
.search .input-group input.search-field:hover {
background-color: transparent;
}
.search .input-group-btn button {
padding: 2px;
border: 0;
box-shadow: none;
background-color: transparent;
border-radius: 0;
}
.search .input-group-btn button:hover {
background-color: #f8f8f8;
color: #ff5500;
}
.search .input-group-btn .glyphicon-search {
font-size: 22px;
}
<link href='https://fonts.googleapis.com/css?family=Lato' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/js/bootstrap.min.js"></script>
<div class="container">
<div class="navbar navbar-default navbar-fixed-top navbar-md" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle hamburger-icon" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
logo<span>here</span>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<!-- search bar -->
<li class="dropdown search">
<form class="navbar-form" role="search">
<div class="input-group">
<input type="text" class="form-control search-field" placeholder="Search name or keyword" name="q">
<div class="input-group-btn">
<button class="btn btn-default" type="submit">
<img src="https://cdn2.iconfinder.com/data/icons/ios-7-icons/50/search-128.png" height="30" width="30" class=" avatar-img img-square">
</button>
</div>
</div>
</form>
</li>
<!-- notification bell -->
<li class="dropdown bell">
<a href="#" class="dropdown-toggle inbox" data-toggle="dropdown">
<img src="https://cdn4.iconfinder.com/data/icons/ionicons/512/icon-ios7-bell-outline-128.png" height="45" width="45" class=" avatar-img img-square">
<span class="badge badge-notify">1</span>
</a>
<ul class="dropdown-menu bell" role="menu">
<li>
<h4 class="menu-title">Notifications</h4>
</li>
<li><span class="label label-default">4:00 AM</span>Favourites Snippet
</li>
<li class="divider"></li>
<li><span class="label label-warning">4:30 AM</span>Email marketing
</li>
<li class="divider"></li>
<li><a href="#"><span class="label label-warning">5:00 AM</span>Subscriber focused email
design</a>
</li>
<li class="divider"></li>
<li>View All
</li>
</ul>
</li>
<!-- user login information -->
<li class="dropdown user">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<span><img src="https://cdn2.iconfinder.com/data/icons/ios-7-icons/50/user_male2-128.png" height="50" width="50" ></span>
<span class="fullname">Jacky Smith</span>
<span><img src="https://cdn0.iconfinder.com/data/icons/slim-square-icons-basics/100/basics-08-128.png" height="20" width="20" ></span>
</a>
<ul class="dropdown-menu user-list" role="menu">
<li>Action
</li>
<li class="divider"></li>
<li>Another action
</li>
<li class="divider"></li>
<li>Something else here
</li>
<li class="divider"></li>
<li>Separated link
</li>
<li class="divider"></li>
<li>One more separated link
</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-12">
<p>dfsjfhskfs</p>
<!-- <div class="chevron right">
</div>
<div style="height: 1em;">
</div> -->
</div>
</div>
</div>
</div>
I hope to help you, if you want to focus the search input of the same, although I would make a width and shrink a bit
EXAMPLE BOOTPLY
The problem now is that the font size is very large for a navbar
reduces the font size "font-size: 26px; for example" of the title LOGOHERE, or put an image tag img-responsive