I am duplicating the Youtube navigation bar by using flexbox but when I came across the search bar It kept on moving the icons while I was trying to increase the width of the search bar.
I've tried position absolute and align self but it did not work.
* {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}
body {
background-color: #f1f1f1;
}
.navigation {
height: 60px;
width: 100%;
box-shadow: 0px 10px 9px #eeeeee;
background-color: #ffffff;
display: flex;
justify-content: space-around;
align-items: center;
}
.stack,
.icon {
width: 100px;
}
/* right corner of nav bar */
.menu {
position: relative;
right: 30px;
width: 23px;
opacity: .6;
}
.youtube-logo {
position: relative;
right: 130px;
width: 90px;
}
.search-bar {
position: relative;
left: 100px;
height: 30px;
}
<nav class="navigation">
<a href="#menu">
<img src="images/menu.svg" alt="menu for the top left, shaped like a hamburger" class="menu">
</a>
<a href="#logo">
<img src="images/youtube.logo.png" alt="youtube logo" class="youtube-logo">
</a>
<input type="text" name="searchbar" placeholder="Search" class="search-bar">
<a href="#video-icon">
<img src="images/video.svg" alt="video icon" class="video">
</a>
</nav>
I wanted the search bar to be the same exact width of YouTube's search bar without moving the other icons.
//you can used a ul li for fixed navbar and this very helpful to don't move other element in navbar
like this :
Navbar
<div class="collapse navbar-collapse">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-
label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
// or use Bootstrap 4 very nice and easy
You're likely looking to use justify-content: space-between and then adjusting the flex property of the input bar. Flexbox items default to a value of flex: 0 1 auto (aka flex-grow: 0, flex-shrink: 1, flex-basis: auto). In this case, you want the input bar by default to grow and take up the rest of the available space in your flex container, so if you set its flex property to flex: 1 (equivalent to flex: 1 1 0) or set flex-grow: 1 you accomplish this.
justify-content: space-around evenly spaces each element, and the empty space before the first item and after the last item in the flex container is set to equal half the space between each adjacent item. Using justify-content: space-between forces the first and last item in the flex container to be flush respectively with the beginning and end of the flex container.
This way, you don't need to use position relative/ absolute (you shouldn't need to use either of these in a flex container anyway) and can use margins to better space between each element.
* {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}
body {
background-color: #f1f1f1;
}
.navigation {
height: 60px;
box-shadow: 0px 10px 9px #eeeeee;
background-color: #ffffff;
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 16px;
}
.stack,
.icon {
width: 100px;
}
/* right corner of nav bar */
.menu {
width: 23px;
opacity: 0.6;
margin: 0 16px 0 0;
}
.youtube-logo {
width: 90px;
height: 40px;
}
.search-bar {
margin: 0 40px;
flex: 1;
}
<nav class="navigation">
<a href="#menu">
<img src="https://via.placeholder.com/23" alt="menu for the top left, shaped like a hamburger" class="menu">
</a>
<a href="#logo">
<img src="https://via.placeholder.com/190" alt="youtube logo" class="youtube-logo">
</a>
<input type="text" name="searchbar" placeholder="Search" class="search-bar">
<a href="#video-icon">
<img src="https://via.placeholder.com/40" alt="video icon" class="video">
</a>
</nav>
More on how justify-content values work: https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content
And more on the flex property: https://developer.mozilla.org/en-US/docs/Web/CSS/flex
Related
I'm having a problem with my checkbox burger menu dropdown is covering content when clicked. It may also look like the menu itself isn't "connected" to the navbar when clicked.
I have tried changing position to absolute but that creates a hidden problem I can't solve.
My first stackoverflow, and one of my first projects. Thanks for patience and help :)
https://jsfiddle.net/ow82jhbm/1/
#media only screen and (max-width:1111px) {
#navtekst {
display: none;
}
}
#sidebarMenu {
height: auto;
/*change here related your menu height*/
position: fixed;
overflow: auto;
width: 100%;
z-index: 100;
transform: translateY(-171px);
/*change here related your menu height*/
}
.main-content-wrapper a {
width: 100%;
height: 40px;
display: block;
text-align: center;
font-size: 20px;
padding-top: 10px;
padding-bottom: 10px;
border: 0.5px solid white;
color: whitesmoke;
text-decoration: none;
}
.sidebarMenuInner {
margin: 0;
padding: 0;
border-top: 1px solid rgba(255, 255, 255, 0.10);
}
input[type="checkbox"]:checked~#sidebarMenu {
transform: translatey(0);
top: 50px/*change here related your top menu height*/
}
input[type=checkbox] {
transition: all 0.3s;
box-sizing: border-box;
display: none;
}
.sidebarIconToggle {
transition: all 0.3s;
box-sizing: border-box;
cursor: pointer;
position: absolute;
z-index: 99;
height: 22px;
width: 22px;
right: 20px;
top: 20px;
display: none
}
/*Whole spinner*/
.spinner {
transition: all 0.3s;
box-sizing: border-box;
position: absolute;
height: 3.5px;
width: 100%;
background-color: white;
}
/*Each line in spinner*/
.horizontal {
transition: all 0.3s;
box-sizing: border-box;
position: relative;
float: left;
margin-top: 3px;
}
.diagonal.part-1 {
position: relative;
transition: all 0.3s;
box-sizing: border-box;
float: left;
}
.diagonal.part-2 {
transition: all 0.3s;
box-sizing: border-box;
position: relative;
float: left;
margin-top: 3px;
}
/*Spinner rotation*/
input[type=checkbox]:checked~.sidebarIconToggle>.horizontal {
transition: all 0.3s;
box-sizing: border-box;
opacity: 0;
}
input[type=checkbox]:checked~.sidebarIconToggle>.diagonal.part-1 {
transition: all 0.3s;
box-sizing: border-box;
transform: rotate(135deg);
margin-top: 8px;
}
input[type=checkbox]:checked~.sidebarIconToggle>.diagonal.part-2 {
transition: all 0.3s;
box-sizing: border-box;
transform: rotate(-135deg);
margin-top: -9px;
}
#media screen and (max-width: 1111px) {
.sidebarIconToggle {
display: block
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<nav class="navbar navbar-expand-sm bg-dark navbar-dark text-white">
<!--Brand/logo-->
<a class="navbar-brand">
<img id="logo" alt="Logo" src="TradeLeague-1 (7).png" />
</a>
<!--Links-->
<ul class="navbar-nav" [class.is-open]="isMenuOpen" style="font-size:18px" id="navtekst">
<!--Homepage-->
<li class="nav-item">
<!--Routering and displaying active page-->
<a class="nav-link" routerLinkActive="active" routerLink="/home"> Home</a>
</li>
<!--Create company-->
<li class="nav-item">
<!--Routering and displaying active page-->
<a class="nav-link" routerLinkActive="active" routerLink="/createcompany"> Create Company</a>
</li>
<!--Company list-->
<li class="nav-item">
<!--Routering and displaying active page-->
<a class="nav-link" routerLinkActive="active" routerLink="/companies"> Companies</a>
</li>
<!--Leaderboard-->
<li class="nav-item">
<!--Routering and displaying active page-->
<a class="nav-link" routerLinkActive="active" routerLink="/leaderboard"> Leaderboard</a>
</li>
</ul>
<!--Creating a new list aligned to the right-->
<ul class="navbar-nav ml-auto" style="font-size:18px" id="navtekst">
<!--Log-in Page-->
<li class="nav-item ">
<!--Routering and displaying active page-->
<a class="nav-link" routerLinkActive="active" routerLink="/login"> Sign-in</a>
</li>
<!--Profilepage-->
<li class="nav-item">
<!--Routering and displaying active page-->
<a class="nav-link" routerLinkActive="active" routerLink="/profile"><i class="fa fa-user-circle"></i> Profile</a>
</li>
</ul>
<input type="checkbox" class="openSidebarMenu ml-auto" id="openSidebarMenu">
<label for="openSidebarMenu" class="sidebarIconToggle">
<div class="spinner diagonal part-1"></div>
<div class="spinner horizontal"></div>
<div class="spinner diagonal part-2"></div>
</label>
<div id="sidebarMenu" class="bg-dark">
<div class="main-content-wrapper">
<a class="nav-link" routerLinkActive="active" routerLink="/home"> Home</a>
<a class="nav-link" routerLinkActive="active" routerLink="/createuser"> Create User</a>
<a class="nav-link" routerLinkActive="active" routerLink="/createcompany"> Create Company</a>
<a class="nav-link" routerLinkActive="active" routerLink="/companies"> Companies</a>
<a class="nav-link" routerLinkActive="active" routerLink="/leaderboard"> Leaderboard</a>
<a class="nav-link" routerLinkActive="active" routerLink="/login"> Sign in</a>
<a class="nav-link" routerLinkActive="active" routerLink="/profile"> Profile</a>
</div>
</div>
</nav>
<br/>
<!--HTML EXAMPLE*/-->
<div class="container bg-dark card text-white" style="text-align: center; width: 65%">
<br />
<!--Header-->
<h1><u>Create User</u></h1>
<br />
<!--Form for creating new user-->
<form [formGroup]="skjema" (ngSubmit)="onSubmit()">
<div class="form-group">
<label>Username</label>
<input class="form-control" formControlName="username" />
<p class="alert alert-warning" [hidden]="skjema.controls.username.valid || (skjema.controls.username.pristine && !submitted)">
Username er obligatorisk.
</p>
</div>
<div class="form-group">
<label>Password</label>
<input class="form-control" formControlName="password" />
<p class="alert alert-warning" [hidden]="skjema.controls.password.valid || (skjema.controls.password.pristine && !submitted)">
Password er obligatorisk.
</p>
</div>
<!--Sends company to script with function createUser() when confirm button is pressed-->
<div class="form-group">
<button type="submit" style="margin-right:15px" [disabled]="!skjema.valid" class="btn btn-primary">Registrer</button>
<button class="btn btn-primary" routerLink="/">Tilbake</button>
</div>
</form>
</div>
Typically, this is done using JS and targets the same menu instead of using two.
With your current structure, you can make this work by first changing #sidebarMenu to position: absolute;. Then target input[type="checkbox"]:checked~#sidebarMenu and use top: 100%; to make sure your menu is appearing directly below the navbar. Make sure you remove the translateY value in those styles.
Next, to get the dropdown menu to push down the other content you will have to use position: relative; on input[type="checkbox"]:checked~#sidebarMenu. This enables the menu to push down and extend the actual navbar height. I used flex to re-configure the alignment of your nav on mobile.
#media only screen and (max-width:1111px) {
#navtekst {
display: none;
}
}
#sidebarMenu {
height: auto;
/*change here related your menu height*/
position: absolute;
display: none;
width: 100%;
z-index: 100;
transform: translateY(-171px);
/*change here related your menu height*/
}
.main-content-wrapper a {
width: 100%;
height: 40px;
display: block;
text-align: center;
font-size: 20px;
padding-top: 10px;
padding-bottom: 10px;
border: 0.5px solid white;
color: whitesmoke;
text-decoration: none;
}
.sidebarMenuInner {
margin: 0;
padding: 0;
border-top: 1px solid rgba(255, 255, 255, 0.10);
}
input[type="checkbox"]:checked~#sidebarMenu {
transform: translatey(0);
position: relative;
top: 100%/*change here related your top menu height*/
;
left: 0;
display: block;
padding-top: 1em;
}
input[type=checkbox] {
transition: all 0.3s;
box-sizing: border-box;
display: none;
}
.sidebarIconToggle {
transition: all 0.3s;
box-sizing: border-box;
cursor: pointer;
position: absolute;
z-index: 99;
height: 22px;
width: 22px;
right: 20px;
top: 20px;
display: none
}
/*Whole spinner*/
.spinner {
transition: all 0.3s;
box-sizing: border-box;
position: absolute;
height: 3.5px;
width: 100%;
background-color: white;
}
/*Each line in spinner*/
.horizontal {
transition: all 0.3s;
box-sizing: border-box;
position: relative;
float: left;
margin-top: 3px;
}
.diagonal.part-1 {
position: relative;
transition: all 0.3s;
box-sizing: border-box;
float: left;
}
.diagonal.part-2 {
transition: all 0.3s;
box-sizing: border-box;
position: relative;
float: left;
margin-top: 3px;
}
/*Spinner rotation*/
input[type=checkbox]:checked~.sidebarIconToggle>.horizontal {
transition: all 0.3s;
box-sizing: border-box;
opacity: 0;
}
input[type=checkbox]:checked~.sidebarIconToggle>.diagonal.part-1 {
transition: all 0.3s;
box-sizing: border-box;
transform: rotate(135deg);
margin-top: 8px;
}
input[type=checkbox]:checked~.sidebarIconToggle>.diagonal.part-2 {
transition: all 0.3s;
box-sizing: border-box;
transform: rotate(-135deg);
margin-top: -9px;
}
#media screen and (max-width: 1111px) {
.sidebarIconToggle {
display: block
}
.navbar {
flex-flow: column !important;
}
.navbar-brand {
width: 99%;
}
}
#media only screen and (min-width: 1111px) {
#sidebarMenu {
display: none !important;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<nav class="navbar navbar-expand-sm bg-dark navbar-dark text-white">
<!--Brand/logo-->
<a class="navbar-brand">
<img id="logo" alt="Logo" src="TradeLeague-1 (7).png" />
</a>
<!--Links-->
<ul class="navbar-nav" [class.is-open]="isMenuOpen" style="font-size:18px" id="navtekst">
<!--Homepage-->
<li class="nav-item">
<!--Routering and displaying active page-->
<a class="nav-link" routerLinkActive="active" routerLink="/home"> Home</a>
</li>
<!--Create company-->
<li class="nav-item">
<!--Routering and displaying active page-->
<a class="nav-link" routerLinkActive="active" routerLink="/createcompany"> Create Company</a>
</li>
<!--Company list-->
<li class="nav-item">
<!--Routering and displaying active page-->
<a class="nav-link" routerLinkActive="active" routerLink="/companies"> Companies</a>
</li>
<!--Leaderboard-->
<li class="nav-item">
<!--Routering and displaying active page-->
<a class="nav-link" routerLinkActive="active" routerLink="/leaderboard"> Leaderboard</a>
</li>
</ul>
<!--Creating a new list aligned to the right-->
<ul class="navbar-nav ml-auto" style="font-size:18px" id="navtekst">
<!--Log-in Page-->
<li class="nav-item ">
<!--Routering and displaying active page-->
<a class="nav-link" routerLinkActive="active" routerLink="/login"> Sign-in</a>
</li>
<!--Profilepage-->
<li class="nav-item">
<!--Routering and displaying active page-->
<a class="nav-link" routerLinkActive="active" routerLink="/profile"><i class="fa fa-user-circle"></i> Profile</a>
</li>
</ul>
<input type="checkbox" class="openSidebarMenu ml-auto" id="openSidebarMenu">
<label for="openSidebarMenu" class="sidebarIconToggle">
<div class="spinner diagonal part-1"></div>
<div class="spinner horizontal"></div>
<div class="spinner diagonal part-2"></div>
</label>
<div id="sidebarMenu" class="bg-dark">
<div class="main-content-wrapper">
<a class="nav-link" routerLinkActive="active" routerLink="/home"> Home</a>
<a class="nav-link" routerLinkActive="active" routerLink="/createuser"> Create User</a>
<a class="nav-link" routerLinkActive="active" routerLink="/createcompany"> Create Company</a>
<a class="nav-link" routerLinkActive="active" routerLink="/companies"> Companies</a>
<a class="nav-link" routerLinkActive="active" routerLink="/leaderboard"> Leaderboard</a>
<a class="nav-link" routerLinkActive="active" routerLink="/login"> Sign in</a>
<a class="nav-link" routerLinkActive="active" routerLink="/profile"> Profile</a>
</div>
</div>
</nav>
<br/>
<!--HTML EXAMPLE*/-->
<div class="container bg-dark card text-white" style="text-align: center; width: 65%">
<br />
<!--Header-->
<h1><u>Create User</u></h1>
<br />
<!--Form for creating new user-->
<form [formGroup]="skjema" (ngSubmit)="onSubmit()">
<div class="form-group">
<label>Username</label>
<input class="form-control" formControlName="username" />
<p class="alert alert-warning" [hidden]="skjema.controls.username.valid || (skjema.controls.username.pristine && !submitted)">
Username er obligatorisk.
</p>
</div>
<div class="form-group">
<label>Password</label>
<input class="form-control" formControlName="password" />
<p class="alert alert-warning" [hidden]="skjema.controls.password.valid || (skjema.controls.password.pristine && !submitted)">
Password er obligatorisk.
</p>
</div>
<!--Sends company to script with function createUser() when confirm button is pressed-->
<div class="form-group">
<button type="submit" style="margin-right:15px" [disabled]="!skjema.valid" class="btn btn-primary">Registrer</button>
<button class="btn btn-primary" routerLink="/">Tilbake</button>
</div>
</form>
</div>
I am using Font Awesome for this code and what I want is to change the ⬇️ icon to ⬆️ when I hover over the drop-down-list . Somehow I figured out to change it when we hover over its parent element. But how do I change it when we need to hover on the element outside its parent element like in this case. A help over it will be appreciated. Thanks :)
This is the result of my code
Here, after hovering over the drop down list, I need the arrow ⬇️ to turn ⬆️
.drop-down-list {
display: none;
}
.drop-down-menu:hover .drop-down-list {
display: flex;
flex-direction: column;
gap: 1rem;
background-color: aliceblue;
border-radius: 9px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
max-width: 20%;
padding: 0.2rem;
margin-top: 0.2rem;
}
.btn:hover span {
display: none;
}
.btn:hover::after {
content: "\f106";
font-family: "FontAwesome" !important;
}
<head>
<script src="https://kit.fontawesome.com/722021f5b4.js" crossorigin="anonymous">
</script>
</head>
<body>
<div class="drop-down-menu">
<a class="btn" href="#">
Products <span><i class="fas fa-angle-down"></i></span>
</a>
<div class="drop-down-list">
<a class="drop-down-links" href="#">Link 1</a>
<a class="drop-down-links" href="#">Link 2</a>
<a class="drop-down-links" href="#">Link 3</a>
</div>
</div>
</body>
You can apply the hover trigger to the parent element and change the btn style like so:
.drop-down-list {
display: none;
}
.drop-down-menu:hover .drop-down-list {
display: flex;
flex-direction: column;
gap: 1rem;
background-color: aliceblue;
border-radius: 9px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
max-width: 20%;
padding: 0.2rem;
margin-top: 0.2rem;
}
.drop-down-menu:hover .btn span {
display: none;
}
.drop-down-menu:hover .btn::after {
content: "\f106";
font-family: "FontAwesome" !important;
}
<head>
<script src="https://kit.fontawesome.com/722021f5b4.js" crossorigin="anonymous">
</script>
</head>
<body>
<div class="drop-down-menu">
<a class="btn" href="#">
Products <span><i class="fas fa-angle-down"></i></span>
</a>
<div class="drop-down-list">
<a class="drop-down-links" href="#">Link 1</a>
<a class="drop-down-links" href="#">Link 2</a>
<a class="drop-down-links" href="#">Link 3</a>
</div>
</div>
</body>
Below image is the mobile view representation of the current scenario -
Here, Orange part represents second div ( DIV 2). Div 3 is a navbar. What I intend to achieve is that in this mobile view, I want that the entire width of div 3 should collapse to the width of a hamburger, sub divs should come in one line and the hamburger icon should come next to it. Something like this -
You can take any random thing in the div to test this scenario ( paragraph, heading etc.)
I am struggling to put the subdivs and the hamburger in one row. Right now I am using bootstrap grid structure to place items. Maybe, I'll need to put the second and third div in a single flexbox. How do I add breakpoints in that?
<div>
<p>DIV1</p>
</div>
<div class="second-div">
<div class="row">
<div class="col-sm-6 justify-content-start">
<p>sub-div1</p>
</div>
<div class="col-sm-6 justify-content-end">
<p>sub-div2</p>
</div>
</div>
<div class="third-div">
<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 mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
Dropdown
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
</div>
</div>
Can anyone please help?
I recommend using CSS-Flexbox to solve your Problem. the following example gives you an overview to get a similar result as you posted in your Question:
body{
width: 100vw;
height: 100vh;
margin: 0;
padding: 0;
}
/*for smartphone / mobile*/
#media only screen and (max-width: 600px) {
.wrapper{
width: 100%;
height: 20%;
/*the following 3 lines make your Element behave as a flexbox element, the way it should behave and how it positions the elements inside of it*/
display: flex;
flex-direction: row;
justify-content: space-between;
}
.div1{
display: none;
}
.container-subdivs{
width: 80%;
height: 100%;
/*the following 3 lines make your Element behave as a flexbox element, the way it should behave and how it positions the elements inside of it*/
display:flex;
/*flex-flow is a combination of flex-direction and flex-wrap*/
flex-flow: row nowrap;
justify-content: space-between;
}
.subdiv1{
width: 10%;
height: 100%;
background-color: orange;
}
.subdiv2{
width: 15%;
height: 100%;
background-color: red;
}
.subdiv3{
width: 15%;
height: 100%;
background-color: yellow;
}
.div3{
height: 100%;
width: 15%;
background-color: pink;
}
}
/* for normal desktop, tablet etc.*/
#media only screen and (min-width: 601px) {
.wrapper{
width: 100%;
height: 100%;
}
.div1{
width: 100%;
height: 2%;
background-color: purple;
}
.container-subdivs{
width: 100%;
height: 20%;
/*See above comments*/
display:flex;
flex-flow: row wrap;
}
.subdiv1{
width: 80%;
height: 60%;
background-color: orange;
}
.subdiv2{
width: 20%;
height: 60%;
background-color: red;
}
.subdiv3{
width: 100%;
height: 40%;
background-color: yellow;
}
.div3{
margin-top: 4vh;
height: 20%;
width: 100%;
background-color: pink;
}
}
<div class="wrapper">
<div class="div1">
div1
</div>
<div class="container-subdivs">
<div class="subdiv1">
subdiv1
</div>
<div class="subdiv2">
subdiv2
</div>
<div class="subdiv3">
subdiv3
</div>
</div>
<div class="div3">
div3
</div>
</div>
The key here is how to set the flex-direction and flex-wrap behaviours, also you need enough elements to wrap several other elements to make them behave in the same way. To find your final solution you need to add a few elements and the css for your hamburger-menu, you will eb able to figure this out yourself.
check THIS to understand what is happening here and how to finalize the approach. Good luck and dont be afraid to ask additional questions in the comments.
well. you have to use css3 grid instead. use CSS3 AND MEDIA QUERYIES to develop the layout like this.
checkout the code here
.item1 { grid-area: header; }
.item2 { grid-area: menu; }
.item4 { grid-area: right; }
.item5 { grid-area: footer; }
/* On screens that are 992px or less, set the background color to blue */
#media screen and (min-width: 600px) {
body {
background-color: blue;
}
.grid-container {
display: grid;
grid-template-columns: repeat(12, 1fr);
grid-auto-rows: minmax(100px, auto);
grid-template-areas:
"right right header header . . . menu menu menu footer footer";
grid-gap: 10px;
background-color: #2196F3;
padding: 10px;
}
}
/* On screens that are 600px or less, set the background color to olive */
#media screen and (max-width: 600px) {
body {
background-color: olive;
}
.grid-container {
display: grid;
grid-template-columns: repeat(12, 1fr);
grid-auto-rows: minmax(100px, auto);
grid-template-areas:
"right right right right right right header header header header header header"
"menu menu menu menu menu menu menu menu menu menu menu menu"
"footer footer footer footer footer footer footer footer footer footer footer footer";
grid-gap: 10px;
background-color: #2196F3;
padding: 10px;
}
}
.grid-container > div {
background-color: rgba(255, 255, 255, 0.8);
text-align: center;
padding: 20px 0;
font-size: 30px;
}
I'm trying to set up a navbar that contains several items aligned to the right.
The problem is that when I click on the "notification" icon, I have my dropdown displayed, but my icons move in the navbar instead of staying fixed, I don't understand why
This is my code :
HTML :
<nav class="navbar navbar-expand-lg navbar-dark bg-secondary justify-content-end">
<ul class="navbar-nav menu-right">
<div class="child child-right">
<!-- Parameters item -->
<li class="nav-item">
<a href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fa fa-cog"></i>
<span class="badge-sonar"></span>
</a>
<div class="dropdown-menu parametres" aria-labelledby="dropdownMenuMessage">
<a class="dropdown-item" href="#">My profile</a>
<a class="dropdown-item" href="#">Help</a>
<a class="dropdown-item" href="#">Setting</a>
</div>
</li>
<!-- Notifications item -->
<li class="nav-item">
<a href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fa fa-bell"></i>
</a>
<div class="dropdown-menu notifications" aria-labelledby="dropdownMenuMessage">
<div class="notifications-header">
<i class="fa fa-bell"></i>
Notifications
</div>
<!-- Notification content -->
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">
<div class="notification-content">
<div class="icon">
<i class="fas fa-check text-success border border-success"></i>
</div>
<div class="content">
<div class="notification-detail">Lorem ipsum dolor sit amet consectetur adipisicing
elit. In totam explicabo</div>
<div class="notification-time">
6 minutes ago
</div>
</div>
</div>
</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item text-center" href="#">View all notifications</a>
</div>
</li>
</div>
</ul>
</nav>
SASS:
.navbar {
overflow: visible;
height: 56px;
z-index: 9999;
}
.notifications {
max-width: 250px;
margin-left: -200px;
margin-top: 5px;
.dropdown-item {
padding: .25rem 1rem;
}
.notifications-header {
padding: 0 1rem;
}
.notification-content {
display: flex;
.icon {
width: 40px;
height: 40px;
i {
width: 35px;
height: 35px;
text-align: center;
line-height: 35px;
}
}
.content {
line-height: 1.6;
padding-left: 5px;
width: calc(100% - 40px);
.notification-time {
font-size: .7rem;
color: #828282;
}
.notification-detail {
font-size: 12px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
}
}
}
.child {
display: flex;
flex-flow: row nowrap;
flex-grow: 0;
justify-content: flex-start;
align-items: stretch;
}
.child.child-right {
flex-grow: 1;
justify-content: flex-end;
}
.child>li{
padding-right: 50px;
}
And the jsfiddle : https://jsfiddle.net/kiuega/beat2zmn/11/
Can someone help me please ?
Styles are overridden by navbar.scss like drop-down is of static pos instead of absolute so here is the solution
Add these styles to you style sheet
.child > li {
padding-right: 50px;
position: relative;
}
.navbar-nav .dropdown-menu {
position: absolute;
float: none;
}
check margins and padding(in the child) check with the inspect element and see witch element change his position
If you open the devtools in your browser then you will see these classes on the dropdown panel:
.navbar-nav .dropdown-menu
(overwritten by navbar.scss)
If you remove the 'position: static', then it will work as expected.
And play with the top and left properties to get the right position.
I have a row of five graphics with text on them. In mobile view, I want to set up a media query so that the five graphics turn into a dropdown with text. For example, image 1 says "Personal Capability", image 2 says "Leading Change", etc. On mobile view, I want the graphics to go away and the dropdown to have options for "Personal Capability", "Leading Change", etc.
My HTML:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="row" style="margin:1%">
<div class="col-xs-1">
</div>
<!--end col-sm-1-->
<div class="col-xs-2">
<a href="#">
<img src="http://placehold.it/150x150" class="img-responsive" title="Personal Capability" style="border:0">
</a>
</div>
<!--end col-sm-2-->
<div class="col-xs-2">
<a href="#">
<img src="http://placehold.it/150x150" class="img-responsive" title="Leading Change" style="border:0">
</a>
</div>
<!--end col-sm-2-->
<div class="col-xs-2">
<a href="#">
<img src="http://placehold.it/150x150" class="img-responsive" title="Character" style="border:0">
</a>
</div>
<!--end col-sm-2-->
<div class="col-xs-2">
<a href="#">
<img src="http://placehold.it/150x150" class="img-responsive" title="Interpersonal Skills" style="border:0">
</a>
</div>
<!--end col-sm-2-->
<div class="col-xs-2">
<a href="#">
<img src="http://placehold.it/150x150" class="img-responsive" title="Focus on Results" style="border:0">
</a>
</div>
<!--end col-sm-2-->
<div class="col-xs-1">
</div>
<!--end col-sm-1-->
</div>
<!--end row-->
You can do this so you don't have to use duplicate content. It's simply using media queries to build a row of images/graphics above a certain breakpoint then hiding those images/graphics when the dropdown should appear.
The dropdown is just a standard button dropdown. In the example a media query # min-width: 768px is used to display the images and # max-width: 767px to display the dropdown. You're simply changing the rules inside the dropdown-menu (which lends itself because it's just a list ultimately) to reflect the output you need, a row of images which you can extend if depending on how many images or reuse in other places with a different number of images.
Basic CSS Change
.btn-group-transform .dropdown-menu {
position: relative;
display: table;
width: 100%;
min-width: 100%;
margin: 0 auto;
padding: 0;
background: transparent;
border: none;
box-shadow: none;
border-radius: 0;
text-align: center;
}
/*Default 6 Images but the % can be changed to accomodate or use/make a helper class*/
.btn-group-transform .dropdown-menu > li {
display: inline-table;
/*Adjust the below value based on the number of list items*/
width: 16.666667%;
float: none;
/*Adjust the below value to add or remove space between list items*/
padding: 2.5px;
}
Example 1; Open at FullPage and reduce the browser window
/*Body rules are for DEMO ONLY*/
body {
padding-top: 2.5px;
}
/*Body rules are for DEMO ONLY*/
#media (min-width: 768px) {
.btn-group-transform {
position: relative;
width: 100%;
}
.btn-group-transform .dropdown-menu {
position: relative;
display: table;
width: 100%;
min-width: 100%;
margin: 0 auto;
padding: 0;
background: transparent;
border: none;
box-shadow: none;
border-radius: 0;
text-align: center;
}
/*Default 6 Images but the % can be changed to accomodate or use.make a helper class*/
.btn-group-transform .dropdown-menu > li {
display: inline-table;
/*Adjust the below value based on the number of list items*/
width: 16.666667%;
float: none;
/*Adjust the below value to add or remove space between list items*/
padding: 2.5px;
}
/*If you want to extend this for a different number of images use these helpers or add new ones*/
/*5 Images*/
.btn-group-transform .dropdown-menu > li.list-5 {
width: 20%;
}
/*4 Images*/
.btn-group-transform .dropdown-menu > li.list-4 {
width: 25%;
}
/*If you want to extend this for a different number of images use the above helpers or add new ones*/
.btn-group-transform .dropdown-menu > li > a {
background: none;
transition: all 300ms linear;
padding: 0;
}
.btn-group-transform .dropdown-menu > li > a > img {
max-width: 100%;
height: auto;
margin: auto;
}
.btn-group-transform .dropdown-menu > li > a:hover {
opacity: 0.5;
}
.btn-group-transform button,
.btn-group-transform span {
display: none;
}
}
#media (max-width: 767px) {
/*Body rules are for DEMO ONLY*/
body {
text-align: center;
}
/*Body rules are for DEMO ONLY*/
.btn-group-transform img {
display: none;
}
}
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<div class="btn-group btn-group-transform">
<button type="button" class="btn btn-default dropdown-toggle dropdown-toggle-transform" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>
<a href="#">
<img src="http://placehold.it/1000x1000/F21115/fff?text=ONE"> <span>Personal Capability</span>
</a>
</li>
<li>
<a href="#">
<img src="http://placehold.it/1000x1000/F21115/fff?text=TWO"> <span>Leading Change</span>
</a>
</li>
<li>
<a href="#">
<img src="http://placehold.it/1000x1000/F21115/fff?text=THREE"> <span>Character</span>
</a>
</li>
<li>
<a href="#">
<img src="http://placehold.it/1000x1000/F21115/fff?text=FOUR"> <span>Interpersonal Skills</span>
</a>
</li>
<li>
<a href="#">
<img src="http://placehold.it/1000x1000/F21115/fff?text=FIVE"> <span>Focus on Results</span>
</a>
</li>
<li>
<a href="#">
<img src="http://placehold.it/1000x1000/F21115/fff?text=SIX"> <span>Something Else</span>
</a>
</li>
</ul>
</div>
<div class="btn-group btn-group-transform">
<button type="button" class="btn btn-default dropdown-toggle dropdown-toggle-transform" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li class="list-5">
<a href="#">
<img src="http://placehold.it/600x600/000/fff?text=ONE"> <span>Personal Capability</span>
</a>
</li>
<li class="list-5">
<a href="#">
<img src="http://placehold.it/600x600/000/fff?text=TWO"> <span>Leading Change</span>
</a>
</li>
<li class="list-5">
<a href="#">
<img src="http://placehold.it/600x600/000/fff?text=THREE"> <span>Character</span>
</a>
</li>
<li class="list-5">
<a href="#">
<img src="http://placehold.it/600x600/000/fff?text=FOUR"> <span>Interpersonal Skills</span>
</a>
</li>
<li class="list-5">
<a href="#">
<img src="http://placehold.it/600x600/000/fff?text=FIVE"> <span>Focus on Results</span>
</a>
</li>
</ul>
</div>
<div class="btn-group btn-group-transform">
<button type="button" class="btn btn-default dropdown-toggle dropdown-toggle-transform" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown <span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right">
<li class="list-4">
<a href="#">
<img src="http://placehold.it/600x600/176B99/fff?text=ONE"> <span>Personal Capability</span>
</a>
</li>
<li class="list-4">
<a href="#">
<img src="http://placehold.it/600x600/176B99/fff?text=TWO"> <span>Leading Change</span>
</a>
</li>
<li class="list-4">
<a href="#">
<img src="http://placehold.it/600x600/176B99/fff?text=THREE"> <span>Character</span>
</a>
</li>
<li class="list-4">
<a href="#">
<img src="http://placehold.it/600x600/176B99/fff?text=FOUR"> <span>Interpersonal Skills</span>
</a>
</li>
</ul>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
If you want to actually use the text that will be displayed in the menu to overlay the image add this rule:
.btn-group-transform .dropdown-menu > li > a > span {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
color: white;
font-weight: bold;
letter-spacing: 1.25px;
font-size: 20px;
white-space: pre-wrap;
}
Example 2: Open at FullPage and reduce the browser window
/*Body rules are for DEMO ONLY*/
body {
padding-top: 2.5px;
}
/*Body rules are for DEMO ONLY*/
#media (min-width: 768px) {
.btn-group-transform {
position: relative;
width: 100%;
}
.btn-group-transform .dropdown-menu {
position: relative;
display: table;
width: 100%;
min-width: 100%;
margin: 0 auto;
padding: 0;
background: transparent;
border: none;
box-shadow: none;
border-radius: 0;
text-align: center;
}
.btn-group-transform .dropdown-menu > li {
display: inline-table;
width: 20%;
float: none;
padding: 2.5px;
}
.btn-group-transform .dropdown-menu > li > a {
background: none;
transition: all 300ms linear;
padding: 0;
position: relative;
}
.btn-group-transform .dropdown-menu > li > a > img {
max-width: 100%;
height: auto;
margin: auto;
}
.btn-group-transform .dropdown-menu > li > a:hover {
opacity: 0.5;
}
/*Add this rule to use the text inside the dropdown to add a text overlay to the images*/
.btn-group-transform .dropdown-menu > li > a > span {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
color: white;
font-weight: bold;
letter-spacing: 1.25px;
font-size: 20px;
white-space: pre-wrap;
}
.btn-group-transform button {
display: none;
}
}
#media (max-width: 767px) {
/*Body rules are for DEMO ONLY*/
body {
text-align: center;
}
/*Body rules are for DEMO ONLY*/
.btn-group-transform img {
display: none;
}
}
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<div class="btn-group btn-group-transform">
<button type="button" class="btn btn-default dropdown-toggle dropdown-toggle-transform" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>
<a href="#">
<img src="http://placehold.it/600x600/05A3F7/05A3F7"> <span>Personal Capability</span>
</a>
</li>
<li>
<a href="#">
<img src="http://placehold.it/600x600/05A3F7/05A3F7"> <span>Leading Change</span>
</a>
</li>
<li>
<a href="#">
<img src="http://placehold.it/600x600/05A3F7/05A3F7"> <span>Character</span>
</a>
</li>
<li>
<a href="#">
<img src="http://placehold.it/600x600/05A3F7/05A3F7"> <span>Interpersonal Skills</span>
</a>
</li>
<li>
<a href="#">
<img src="http://placehold.it/600x600/05A3F7/05A3F7"> <span>Focus on Results</span>
</a>
</li>
</ul>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
Bootstrap provides Responsive utilities. There are some classes you can use to hide or show something according to the screen.
If I understand your problem, you want to display something on mobile only and other things on the other devices.
Bootstrap has something for you, the visible and hidden classes.
In this JSFiddle, you can find out a example of those classes : https://jsfiddle.net/valentinho14/9f4b53yw/
In addition, Please don't use empty block just to push content, like :
<div class="col-xs-1"></div>
It would be better if you choose to use the classes created for that(offset) :
<div class="col-xs-2 col-xs-offset-1">
Your content
</div>
To have more informations about that, please check the official bootstrap's doc : http://getbootstrap.com/css/#responsive-utilities