menu bar does not display - html

good morning, I have a problem with the menu bar, which when placing the logo makes the bar bigger, and I have a submenu, which does not display the options. I attach the code in case anyone can collaborate.
HOME
ABOUT
CONTACT
MENU
Ingresar
Buscar
Codigo QR
.imgBarra {
width: 30px;
height: 30px;
position: relative;
background: none;
align-items: flex-start;
padding: 0px;
margin: 0px;
margin-left: -20px;
margin-top: 20px;
}
.Barra li a{
text-decoration: none;
color: rgb(255, 255, 255);
padding: 20px;
display: block;
}
.Barra li{
display: inline-block;
text-align: center;
position: relative;
}
.Barra li a:hover{
background-color: aquamarine;
color: black;
}
.submenu{
position: absolute;
background: #e8e8e8;
width: 120%;
visibility: hidden;
}
.submenu li a{
display: block;
padding: 15px;
color: #fff;
font-family: Arial;
text-decoration: none;
}
.submenu li a:hover{
display: block;
transition: all .3s;

If your logo is .imgBarra, you don't need to add the property align-items: flex-start;
no display: flex; property has been set.
If you want to align it at the left of your header, you need to set the property to the container .barra.
Basically, if you set align-items: flex-start; to your logo container it will align all the children inside your logo container, not the logo itself.
To control the height and the alignment of the header properly you need to be careful with paddings and consider all the children inside.
Supposing that your HTML is like that:
<div class="barra>
<div class="imgBarra">Logo</div>
<ul>
<li>
Home
</li>
<li>
About
</li>
<li>
Contact
</li>
</ul>
</div>
To have an height of 110px total [30px(logo) + 40px(20px top + 20px bottom header padding) + 40px(20px top + 20px bottom links padding)], your CSS should look like this:
.barra {
position: relative;
padding: 20px;
display: flex;
align-items: center; /* to align vertically in the center all the children inside the header, so imgBarra and the li */
justify-content: space-between; /* or any other property to align horizontally the content inside the header */
}
.imgBarra {
width: 30px;
height: 30px;
}
.barra ul li a {
padding: 20px;
}
Regarding the submenu let's suppose your HTML looks like this, by hovering on "Home" the user should see your dropdown.
<div class="barra">
<div class="imgBarra">Logo</div>
<ul>
<li class="hasDropdown">
<a class="dropdownTrigger" href="#">Home</a>
<div class="dropdown">
<ul>
<li>Submenu Item 1</li>
<li>Submenu Item 2</li>
<li>Submenu Item 3</li>
</ul>
</div>
</li>
<li>
About
</li>
<li>
Contact
</li>
</ul>
</div>
To trigger and show the submenu you first need to hide the dropdown with visibility:hidden; then give this CSS rule which basically says "when hovering on "Home" (identified by the class dropdownTrigger) change the dropdown class to visiblity: visible;.
Your CSS should look like this:
.hasDropdown {
position: relative;
}
.dropdown {
visibility: hidden; /* Dropdown hidden by default */
position: absolute /* You will position it relatively to its parent hasDropdown */
top: 20px;
left: 0;
display: flex;
align-items: flex-start;
}
.dropdownTrigger:hover .dropdown {
visibility: visible;
}
As you can see in the dropdown container I have added the properties display: flex; and align-items: flex-start;, so all the children inside .dropdown will be aligned to the left, as said before. The property align-items will work only if display: flex; has been set.

Related

How to move an image vertically downwards inside a navigation menu with HTML and CSS

Currently there is a functional and togglable navigation menu within a webpage. An image is also embedded within the navigation menu, position below the text.
It would be nice to reposition the image to be at the very bottom of the navigation menu to eliminate any empty space below it. What would be the best approach to accomplish this?
Here is a picture for context.
HTML
<html>
<div id="sideNav">
<nav>
<ul>
<li>HOME</li>
<li>COVID-19</li>
<li>SERVICES</li>
<li>REVIEWS</li>
<li>CONTACT</li>
</ul>
<div id="nav_pic">
<img src ="images/nav_lotus.JPEG">
</div>
</nav>
</div>
</html>
CSS
#sideNav{
width: 200px; /*changes the width of sideNav*/
height: 100vh;
position: fixed;
right: -250px; /*make side bar intially hidden*/
top:0;
background: #009688;
z-index: 2;
transition: 0.33s;
}
.nav ul li{
list-style: none;
margin: 45px 15px;
}
.nav ul li a{
text-decoration: none;
color: #fff;
font-family: 'Raleway', sans-serif;
}
.nav_pic{
vertical-align: bottom;
}
Add flex style to nav container.
nav {
height: 100%;
display: flex;
flex-direction: column;
justify-content: space-between;
}

How can I center the navigation bar, but have more navigation on the top right in fixed positions

So I have some code here and I wanted to have my main navigation in the middle and then the account and cart tabs on the top right. I want it in a way where the tabs that say "buy,sell,trade... etc" are directly in the middle and not in the middle of the left side of the page and the account and cart containers.
CSS
header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 30p 10%;
text-align: center;
transition: all 0.4s ease 0s;}
.navigation {
list-style: none;
width: 10000px;
margin: 1%;}
.navigation li {
display: inline-block;
padding: 10px 20px;
float: center;}
.navigation li a {
transition: all 0.4s ease 0s}
.navigation li a:hover{
color:#75593e }
.home {
width: 65px;
height: 55px;
background: url("/images/ClosedBoxLogo.png");}
.home:hover {
background: url("/images/OpenBox.png") no-repeat;}
/* Cart and Account */
.rightside {
display: flex;
list-style: none;
align-items: center;
justify-content: space-between;}
.rightside li {
padding: 10px 20px;}
And this is my HTML
<body>
<header>
<ul class="navigation">
<li>Buy</li>
<li>Sell</li>
<li><img class="home" src="images/CloseBox.png" alt="Close Box" onmouseover="this.src='images/OpenBox.png';" onmouseout="this.src='images/CloseBox.png';"/></li>
<li>Sell</li>
<li>Buy</li>
</ul>
<ul>
<div class="rightside">
<li> Account </li>
<li> Cart </li>
</div>
</ul>
</header>
</body>
One approach you could take is making the header position relative while the right side ul is position absolute. This takes the right list items out of the natural DOM flow so the main navigation is completely centered. By making the header relative, you can align the right list items however you want relative to the parent. Keep in mind that you will have to edit the design for mobile responsiveness as the right links will no longer adhere to flexbox styling while positiond absolute.
Edits I made to your code:
Added 'position: relative;' to header and fixed your padding missing the "x" in "px"
Removed the div with class "rightside" and moved the class to that parent ul
Added 'position: absolute; right: 0; margin: auto 0;' to the class "rightside". Margin: 'auto 0;' vertically centers the li's to the parent
Working JsFiddle: https://jsfiddle.net/bzjxnw4h/
header {
position: relative;
display: flex;
justify-content: space-between;
align-items: center;
padding: 30px 10%;
text-align: center;
transition: all 0.4s ease 0s;}
.navigation {
list-style: none;
width: 10000px;
margin: 1%;}
.navigation li {
display: inline-block;
padding: 10px 20px;
float: center;}
.navigation li a {
transition: all 0.4s ease 0s;}
.navigation li a:hover{
color:#75593e; }
.home {
width: 65px;
height: 55px;
background: url("/images/ClosedBoxLogo.png");}
.home:hover {
background: url("/images/OpenBox.png") no-repeat;}
/* Cart and Account */
.rightside {
position: absolute;
right: 0;
margin: auto 0;
display: flex;
list-style: none;
align-items: center;
justify-content: space-between;}
.rightside li {
padding: 10px 20px;}
<body>
<header>
<ul class="navigation">
<li>Buy</li>
<li>Sell</li>
<li><img class="home" src="images/CloseBox.png" alt="Close Box" onmouseover="this.src='images/OpenBox.png';" onmouseout="this.src='images/CloseBox.png';"/></li>
<li>Trade</li>
<li>Middle Man</li>
</ul>
<ul class="rightside">
<li> Account </li>
<li> Cart </li>
</ul>
</header>
</body>
Check this if it will work for you or you want some changes and also remove or change your
onhover img if possible cause it will not look good : https://codepen.io/the-wrong-guy/pen/ZEQXRRx?editors=1100

Positioning a circle underneath text in CSS

I'm trying to position a 5px x 5px circle in the centre of the underneath of the links in a nav to indicate which page the user is currently on, but I'm not sure how I should be going about this.
Currently I have this: Image
I am trying to do this:
Image
This is the code:
<ul id="nav-menu">
<li class="nav-menu-item">
Our work
</li>
<li class="nav-menu-item">
What we do
</li>
<li class="nav-menu-item">
Blog
</li>
<li class="nav-menu-item">
Contact
</li>
</ul>
nav {
height: 70px;
background: #fff;
display: flex;
align-items: center;
padding: 0 75px;
}
#nav-logo-link {
flex: 1;
}
#nav-logo {
height: 35px;
}
#nav-menu {
list-style: none;
padding: 0;
white-space: nowrap;
}
#nav-menu > li {
display: inline;
margin: 0 10px;
}
#nav-menu > li > a {
text-decoration: none;
color: #000;
}
I have tried putting an <i> element within the <li> and then positioning it as absolute, and whilst I can put it down at the correct height (since the nav height is static), when I set it as left: 0;, it jumps to the left hand side of the entire nav. I tried putting a <div> within the <li> but that didn't do anything.
Any ideas?
You can use an after pseudo element to do this along with a UTF8 character, see the following fiddle.
Edit: I'm assuming you want this to happen when the user clicks a link and is then on that page hence why I've used a data attribute, the previous answer does it on hover.
I've made three amendments to your code here:
Added position: relative; to your anchors, this allows me to use position: absolute in the next css block:
nav-menu > li > a {
text-decoration: none;
color: #000;
position: relative;
}
Added the pseudo element absolutely positioned at 50% of the anchor width, I've also set it's width and then centred it within that by using a negative margin of half its width. This relies on you setting the selected item with a little bit of javascript, see point 3. You may want to adjust the colour:
nav-menu > li > a[data-selected=true]:after {
content: "\25CF";
position: absolute;
top: 1.1em;
left: 50%;
width: 10px;
margin-left: -5px;
color: cadetblue;
}
Added a data-selected="true" attribute to the selected anchor, you need to do this in javascript as a different anchor is selected. This allows the css in step 2 to select the right anchor.
This can be done by adding a nav-menu-item:after{ rule which adds a circle after the <li> tag then set the display for the #nav-menu > li { to inline-block and you should get the desired result on hover
nav {
height: 70px;
background: #fff;
display: flex;
align-items: center;
padding: 0 75px;
}
#nav-logo-link {
flex: 1;
}
#nav-logo {
height: 35px;
}
#nav-menu {
list-style: none;
padding: 0;
white-space: nowrap;
}
#nav-menu > li {
display: inline-block;
margin: 0 10px;
}
#nav-menu > li > a {
text-decoration: none;
color: #000;
}
.nav-menu-item:hover:after {
content: "\25CF";
display: block;
opacity: 1;
margin-left: auto;
margin-right: auto;
}
.nav-menu-item::after {
content: "\25CF";
opacity: 0;
color: #1ba9b3;
display: block;
margin-left: auto;
margin-right: auto;
width: 5px;
height: 5px;
}
<nav>
<ul id="nav-menu">
<li class="nav-menu-item">
Our work
</li>
<li class="nav-menu-item">
What we do
</li>
<li class="nav-menu-item">
Blog
</li>
<li class="nav-menu-item">
Contact
</li>
</ul>
</nav>
If you want to show the dot when selected you can use javascript to set the class to be <li class="nav-menu-item selected"> then in css you would change .nav-menu-item:hover:after { to .nav-menu-item.selected:after {
Hope this helps!

Make absolute element sit directly below relative element

I'm currently building a dropdown nav bar that activates upon hover.
I would like the dropdown nav to display directly under the PORTFOLIO link when hovered over, it's currently displaying over to the right.
Styling and what not is going to come later, I wanted this bit sorted before carrying on.
<div class="twelve columns">
<ul class="navigation six columns offset-by-three">
<li>HOME</li>
<li>PORTFOLIO</li>
<div class="sub-hover">
Photos
Physical
Write
Studies
</div>
<li>ABOUT</li>
<li>CONTACT</li>
</ul>
</div>
.navigation {
display: flex;
flex-direction: row;
justify-content: center;
}
.navigation li {
display: inline-block;
padding: 10px 20px;
}
.submenu {
position: relative
}
.sub-hover {
position: absolute;
display:;
margin-top: 25px;
padding: 5px 10px;
}
.sub-hover a {
display: block;
}
.submenu:hover .sub-hover {
display: block;
}
There are a couple things you need to change:
You need to place your .sub-hover inside of the portfolio <li> instead of outside of it.
Display your .sub-hover div when .submenu is hovered. You can accomplish this by using the CSS sibling selector ~.
Display your .sub-hover div when the div itself is hovered.
In your .sub-hover div, use padding instead of margin so the div won't disappear when you move your mouse from the title to the dropdown.
CSS
.sub-hover {
padding-top: 25px;
}
.submenu:hover ~ .sub-hover {
display: block;
}
.sub-hover:hover {
display: block;
}
.navigation {
display: flex;
flex-direction: row;
justify-content: center;
}
.navigation li {
display: inline-block;
padding: 10px 20px;
}
.submenu {
position: relative
}
.sub-hover {
position: absolute;
display:;
padding-top: 25px;
padding: 5px 10px;
display: none;
}
.submenu:hover ~ .sub-hover {
display: block;
}
.sub-hover:hover {
display: block;
}
.sub-hover a {
display: block;
}
.submenu:hover .sub-hover {
display: block;
}
<div class="twelve columns">
<ul class="navigation six columns offset-by-three">
<li>HOME</li>
<li>PORTFOLIO
<div class="sub-hover">
Photos
Physical
Write
Studies
</div>
</li>
<li>ABOUT</li>
<li>CONTACT</li>
</ul>
</div>
This will take a little tweaking of your markup, but a common way to deal with this boils down to
<ul class="navigation">
<li>
<a>main menu item 1</a>
<li>
<a>main menu item 2</a>
<ul>
<li>
<a>drop down 1 under menu item 2</a>
</li>
<li>
<a>drop down 2 under menu item 2</a>
</li>
</ul>
<li>
</ul>
and
.navigation {
list-style: none
}
.navigation li {
display: inline-block;
position: relative;// required for positioning the dropdown relative to the parent menu item
}
.navigation li li {
display: block
}
.navigation ul {
display: none;
position: absolute;
top: 100%;// makes the dropdown "hang" from the menu
left: 0;// tweak as needed
width: 100px;//some value required here
}
.navigation li:hover ul {
display: block
}
The keys to your question are putting the dropdown inside the main menu item, making the main menu item position: relative, and making the dropdown position: absolute; top: 100%; width: something and left: something or right: something

How to get html5/css3 navigation bar to align at the top?

I'm building myself a website on html css etc. (college work so that's a reason why) however I've had struggle with my navigation bar.
The first thing is that it goes to the side of the page which I don't want. I want it at the top like for example the bar at the top of stack overflow. I'm using flexbox for my navigation bar and i like the sizes of each section. My code is:
body {
background-color: #000000;
color: #FFFFFF;
font-family: Georgia;
}
nav {
background-color: #000000;
color: #888;
margin: 0px 0px 0px 0px;
overflow: hidden;
width: 100%;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
}
nav ul {
float: left;
display: block;
margin: 0;
padding: 0;
}
nav ul li {
float: top;
list-style: none;
text-align: center;
}
nav > ul > li > a {
color: #aaa;
display: block;
line-height: 56px;
padding: 0;
text-decoration: none;
text-align: center;
}
nav > ul > li:hover > a {
color: rgb(255, 255, 255);
}
<nav>
<ul>
<li>
<h1>Title</h1>
</li>
<li>Home
</li>
<li>Forum
</li>
<li>Music
</li>
<li>About
</li>
<li>Shop
</li>
</ul>
</nav>
float:top
Is invalid.
The CSS float property can be declared as left || right, or left as it is
Floating elements can be tricky at the best of times. Instead, you could use something like display:inline-block instead.
more info on floating elements
All about floats
A float is a box that is shifted to the left or right on the current
line. The most interesting characteristic of a float (or "floated" or
"floating" box) is that content may flow along its side (or be
prohibited from doing so by the 'clear' property). Content flows down
the right side of a left-floated box and down the left side of a
right-floated box. The following is an introduction to float
positioning and content flow; the exact rules governing float behavior
are given in the description of the 'float' property. ~ w3.org
DEMO:
nav ul li {
display:inline-block;
vertical-align:middle;
list-style: none;
text-align: center;
}
body {
background-color: #000000;
color: #FFFFFF;
font-family: Georgia;
}
nav {
background-color: #000000;
color: #888;
margin: 0px 0px 0px 0px;
overflow: hidden;
width: 100%;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
}
nav ul {
display: inline-block;
margin: 0;
padding: 0;
}
nav ul li {
display:inline-block;
vertical-align:middle;
list-style: none;
text-align: center;
}
nav > ul > li > a {
color: #aaa;
display: block;
line-height: 56px;
padding: 0;
text-decoration: none;
text-align: center;
}
nav > ul > li:hover > a {
color: rgb(255, 255, 255);
}
<nav>
<ul>
<li>
<h1>Title</h1>
</li>
<li>Home
</li>
<li>Forum
</li>
<li>Music
</li>
<li>About
</li>
<li>Shop
</li>
</ul>
</nav>
you are doing a great job. I would like to suggest a few things as I have already experienced some problems.
Use Bootstrap. All you need to do is include a CSS and a JavaScript file and write navbar in class = "navbar navbar-default navbar-fixed-top" and automatically it will be placed at the top with much better looks and having responsive design. It is not difficult at all. It will hardly take and hour or two to understand and implement it in your website.