I am trying to make this dropdown button using flexbox but it's not working as I want. It's not displaying when I hover around the button using display properties. Can someone edit this code so that the dropdown menu works?
Is this what you want
function Enable(){
x = document.getElementById("Ulist");
if(x.className == "display"){
x.className += " active";
}else{
x.className == "display";
}
}
li{
list-style: none;
}
.Maincover{
display: flex;
flex-direction: column;
align-items: center;
height: 300px;
}
button{
font-family: montserrat;
font-weight: 500;
width: 100px;
border-radius: 5px;
color: white;
border: 0px;
padding: 5px 10px;
text-align: center;
background-color: tomato;
}
.list{
font-family: rubik;
text-align: center;
margin-top: 10px;
}
.display{
padding:0px;
display: none;
}
.display.active{
display: block;
}
.hoverbutton:hover ~ .display{
display: block;
}
<div class="Maincover">
<button class="hoverbutton" onclick="Enable()">Hover Here</button>
<ul class="display" id="Ulist">
<li class="list" id="lists">List item 1</li>
<li class="list" id="lists">List item 2</li>
<li class="list" id="lists">List item 3</li>
</ul>
</div>
Here I have attached the html and css code for hoverable dropdown menu using flex.
.menu-area{
margin: 0;
padding: 0;
box-sizing: border-box;
width:150px;
display:flex;
flex-direction:column;
justify-content:center;
}
.menu-area a{
display: flex;
align-items: center;
justify-content: center;
color: #fff;
background: darkslategrey;
height: 60px;
font-family:Poppins;
font-weight: bold;
text-decoration: none;
}
.menu-area a:hover{
background: tomato;
color: #fff;
}
.menu-area ul{
list-style: none;
display: flex;
}
.menu-area li{
position: relative;
width: 100%;
text-align: center;
}
.menu-area li:hover .dropdown-1 > li{
display: block;
top: 0;
}
.dropdown-1 li{
display: none;
position: relative;
}
.dropdown-1{
position: absolute;
display: flex;
flex-direction: column;
width: 100%;
}
.dropdown-1 li:hover .dropdown-2 li{
display: block;
}
.dropdown-2 li{
display: none;
}
.dropdown-2{
display: flex;
flex-direction: column;
position: absolute;
top: 0;
left: 100%;
width: 100%;
}
.banner-area{
background-image: linear-gradient(rgba(0,0,0,0.5),rgba(0,0,0,0.5)),url(https://i.postimg.cc/Y0YM36yL/aa.jpg);
-webkit-background-size:cover;
background-size:cover;
background-position: center center;
display: flex;
align-items: center;
justify-content: center;
height: calc(100vh - 60px);
}
.banner-area h1 {
text-transform: uppercase;
color: #fff;
font-size: 100px;
font-family: poppins;
letter-spacing: 2px;
}
<div class="menu-area">
<ul>
<li>Dropdown
<ul class="dropdown-1">
<li>service one</li>
<li>service two</li>
<li>service three
</li>
</ul>
</li>
</ul>
</div>
Related
I am a beginner at HTML, and I was trying to make a web page to gain experience. I wanted to create this menu but I want it to have options on both sides of it. Just like the HOME, ABOUT ME, etc. options is on the right side, I want similar options on the left side too but am not able to figure it out. Any help would be greatly appreciated.
The HTML code:
<div id="menu">
<nav class="navl" style="justify-content: right">
<ul>
<li class="navulli">
<a href="C:\Users\vivek\Desktop\html-css-course\LegendsOfTime\LOT_Home.html">
Home
</a>
</li>
</ul>
</nav>
</div>
The CSS code:
#menu {
width: 100%;
height: 30px;
background-size: cover;
justify-content: right;
margin: 0px;
padding: 0px;
}
.navl {
width: 100%;
height: 150%;
line-height: 10px;
margin-right: 60px;
display: flex;
background-color: black;
opacity: 0.6;
margin: 0px;
}
.navulli {
display: inline-block;
transition: 0.7s all;
font-family: Century Gothic, CenturyGothic, AppleGothic, sans-serif;
place-items: left;
margin: 0px;
}
.navulli:hover {
opacity: 0.4;
height: 20px;
border-radius: 20px;
}
nav ul li a {
text-decoration: none;
color: white;
padding: 30px;
justify-content: right;
font-size: calc(1rem + 0.2vw);
margin-top: 0px;
}
i {
text-decoration: none;
color: white;
justify-content: right;
padding: 15px;
font-size: calc(1rem + 0.5vw);
margin-top: 0px;
}
One possible solution would be to use a flexbox with justify-content: space-between;
nav {
background: silver;
padding: 1em;
display: flex;
justify-content: space-between;
}
nav ul {
display: inline-block;
margin: 0;
padding: 0;
}
nav ul li {
list-style: none;
display: inline;
margin: 0 1em;
}
<nav>
<ul>
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
<ul>
<li>four</li>
<li>five</li>
<li>six</li>
</ul>
</nav>
I am trying to create a simple web page and I want the links' background covers the whole space in navbar but it covers only the text around it.
My code is here:
.navbar {
width: 105%;
height: 5vw;
display: flex;
flex-direction: row;
background-color: #008083;
z-index: 10;
}
.navbar ul {
list-style: none;
margin: 0;
padding: 0px;
overflow: hidden;
}
.navbar li {
float: left;
}
.navbar li a {
text-decoration: none;
color: black;
padding: 1px;
text-align: center;
}
.tab {
width: 100%;
display: flex;
background-color: grey;
justify-content: center;
align-items: center;
margin: 1px;
}
<nav class="navbar">
<ul>
<li>Biography</li>
<li> Novels </li>
<li> Films </li>
</ul>
</nav>
Any suggestions?
You can remove the height from the navbar class so, it'll take the available height. Also, you can add height to .navbar li (Optional, if you want to use some custom height).
.navbar {
width: 105%;
/*height: 5vw;*/
display: flex;
flex-direction: row;
background-color: #008083;
z-index: 10;
}
.navbar ul {
list-style: none;
margin: 0;
padding: 0px;
overflow: hidden;
}
.navbar li {
float: left;
/*height: 100%;(Optional)*/
}
.navbar li a {
text-decoration: none;
color: black;
padding: 1px;
text-align: center;
}
.tab {
width: 100%;
display: flex;
background-color: grey;
justify-content: center;
align-items: center;
margin: 1px;
}
<nav class="navbar">
<ul>
<li>Biography</li>
<li> Novels </li>
<li> Films </li>
</ul>
</nav>
i don't understand exact your problem but if your problem with the default margin and padding its a solution
* {
padding: 0;
margin: 0;
}
.navbar {
width: 105%;
height: 5vw;
display: flex;
flex-direction: row;
background-color: #008083;
z-index: 10;
}
.navbar ul {
list-style: none;
margin: 0;
padding: 0px;
overflow: hidden;
}
.navbar li {
float: left;
/*height: 100%;(Optional)*/
}
.navbar li a {
text-decoration: none;
color: black;
padding: 1px;
text-align: center;
}
.tab {
width: 100%;
display: flex;
background-color: grey;
justify-content: center;
align-items: center;
margin: 1px;
}
<nav class="navbar">
<ul>
<li>Biography</li>
<li> Novels </li>
<li> Films </li>
</ul>
</nav>
I have removed some unnecessary style from your code & build this using CSS display: flex; instead of float. Now .tab is covering full height with background.
Here is the working example:
.navbar {
background-color: #008083;
z-index: 10;
}
.navbar ul {
list-style: none;
margin: 0;
padding: 0;
overflow: hidden;
display: flex;
align-items: center;
}
.navbar li {
margin: 0;
padding: 0;
}
.navbar li a {
text-decoration: none;
color: black;
text-align: center;
padding: 10px;
display: block;
}
.tab {
background-color: grey;
}
<nav class="navbar">
<ul>
<li>Biography</li>
<li> Novels </li>
<li> Films </li>
</ul>
</nav>
I'm trying to write the code for a fitness supplement webshop, and as I am making the navigation bar, this weird problem has come up. The unordered list is neither aligned vertically nor horizontally.
HTML:
<div class="menus">
<ul menuList>
<li>SUPPLEMENTER</li>
<li>ACCESSORIES</li>
<li>TØJ</li>
<li>ANDET</li>
</ul>
</div>
CSS:
.menus {
background-color: #00C9FF;
height: 42px;
width: 100%;
padding: 0;
margin: 0;
display: flex;
flex-direction: row;
justify-content: center;
bottom: 0%;
}
.menus ul li {
list-style: none;
padding-left: 50px;
padding-right: 50px;
}
.menus ul {
display: flex;
flex-direction: row;
margin-top: auto;
}
.menus ul li a {
font-weight: 800;
font-style: italic;
font-size: 30pt;
text-decoration: none;
color: white;
}
If you needed this:
body {
margin: 0;
}
.menus {
background-color: #00C9FF;
height: 50px;
width: 100%;
padding: 0;
margin: 0;
display: flex;
flex-direction: row;
justify-content: center;
bottom: 0%;
}
.menus ul li {
list-style: none;
padding-left: 50px;
padding-right: 50px;
}
.menus ul {
display: flex;
flex-direction: row;
margin-top: auto;
}
.menus ul li a {
font-weight: 800;
font-style: italic;
font-size: 30pt;
text-decoration: none;
color: white;
}
<div class="menus">
<ul menuList>
<li>SUPPLEMENTER</li>
<li>ACCESSORIES</li>
<li>TØJ</li>
<li>ANDET</li>
</ul>
</div>
Then the body margin was not set to 0 and the navbar needed a little bit more of height.
And yes... that code is not responsive.
I tried to play all around the codes, but I didn't find a solution. Can anyone help me to center all content inside the border box?. I tried to search everywhere and I can't find the solution. Advance Thanks.
https://i.stack.imgur.com/f17JF.png
.menubar {
width: 50vw;
height: 5rem;
background-color: #283747;
margin: auto;
border-bottom-left-radius: 10rem;
border-bottom-right-radius: 10rem;
position: relative;
}
.mainMenu {
list-style-type: none;
text-align: center;
position: relative;
}
li.navbar {
list-style-type: none;
display: inline-block;
padding: .8rem 6rem 1rem 3rem;
text-transform: uppercase;
background: #fff;
width: 1.5rem;
height: 1.5rem;
border-radius: 1rem;
}
li.navbar a {
color: #000;
text-decoration: none;
}
<div class="menubar">
<nav>
<ul class="mainMenu">
<li class="navbar">Hub</li>
<li class="navbar">Blog</li>
<li class="navbar">News</li>
</ul>
</nav>
</div>
If you want to center the nav inside the .menubar container, give it these styles: display: flex; justify-content: center; align-items: center;. Then remove the default browser left padding on .mainMenu by giving it padding: 0.
.menubar {
width: 50vw;
height: 5rem;
background-color: #283747;
margin: auto;
border-bottom-left-radius: 10rem;
border-bottom-right-radius: 10rem;
position: relative;
display: flex;
justify-content: center;
align-items: center;
}
.mainMenu {
list-style-type: none;
text-align: center;
position: relative;
padding: 0;
}
li.navbar {
list-style-type: none;
display: inline-block;
text-transform: uppercase;
background: #fff;
border-radius: 1rem;
}
li.navbar a {
color: #000;
text-decoration: none;
display: inline-block;
padding: 1rem 3rem 1rem 3rem;
}
<div class="menubar">
<nav>
<ul class="mainMenu">
<li class="navbar">Hub</li>
<li class="navbar">Blog</li>
<li class="navbar">News</li>
</ul>
</nav>
</div>
Do You want this?
.menubar {
height: auto;
background-color: #283747;
margin: auto;
position: relative;
}
.mainMenu {
list-style-type: none;
text-align: center;
position: relative;
vertical-align: middle;
}
li {
list-style-type: none;
display: inline-block;
padding: 1rem 4rem 1rem 3rem;
background: #fff;
width: 1.5rem;
height: 1.5rem;
border-radius: 1rem;
margin: 30px auto;
}
li.navbar a {
color: #000;
text-decoration: none;
text-transform: uppercase;
}
<div class="menubar">
<nav>
<ul class="mainMenu">
<li class="navbar">Hub</li>
<li class="navbar">Blog</li>
<li class="navbar">News</li>
</ul>
</nav>
</div>
jsfiddle
If I am using
display: flex;
align-items: center;
how to make horizontal align of ul to right?
.navigation {
display: flex;
align-items: center;
width: 100%;
height: 80px;
background: rgb(255, 255, 255);
}
ul {
list-style: none;
/*float:right;*/
}
li {
display: inline-block;
}
a {
padding: 10px;
width: 80px;
text-decoration: none;
display: block;
text-align: center;
}
<div class="navigation">
<ul>
<li><a>Contacts</a></li>
<li><a>About</a></li>
<li><a>FAQ</a></li>
<li><a>Other</a></li>
</ul>
</div>
You can do this with justify-content: flex-end on .navigation
.navigation {
display: flex;
align-items: center;
justify-content: flex-end;
width: 100%;
height: 80px;
background: rgb(255, 255, 255);
}
ul {
list-style: none;
display: flex;
padding: 0;
}
a {
padding: 10px 25px;
width: 80px;
text-decoration: none;
text-align: center;
}
<div class="navigation">
<ul>
<li><a>Contacts</a></li>
<li><a>About</a></li>
<li><a>FAQ</a></li>
<li><a>Other</a></li>
</ul>
</div>
Add flex-direction: row-reverse; to .navigation
.navigation {
display: flex;
align-items: center;
width: 100%;
height: 80px;
background: rgb(255,255,255);
flex-direction: row-reverse;/* Here is what you are looking for*/
}
ul {
list-style:none;
border:1px solid black;
}
li {
display:inline-block;
}
a {
padding: 10px;
width: 80px;
text-decoration: none;
display: block;
text-align: center;
}
<div class="navigation">
<ul>
<li><a>Contacts</a></li>
<li><a>About</a></li>
<li><a>FAQ</a></li>
<li><a>Other</a></li>
</ul>
</div>