Why are my links in html ul li not working? - html

I'm currently trying to build my first website (homework). For my dropdown menu, I used Dev Ed's tutorial for a dropdown menu, and it is working except that I can't click on the links in the dropdown bits.
(the mouse coursor still changes into that hand-symbol though)
How can I fix this?
nav {
grid-column: 1/5;
background: #2E3045;
justify-content: center;
border-radius: 10px;
}
nav a,
button {
text-decoration: none;
font-size: 1.7vw;
font-family: Bahnschrift, sans-serif;
color: #DFB830;
font-weight: bold;
}
/* horizontal-menu */
.menu {
height: auto;
display: flex;
justify-content: space-around;
align-items: center;
}
/* styling horizontal-menu buttons */
.dropdown button,
.dd-buttons {
background: none;
border: none;
cursor: pointer;
text-transform: uppercase;
padding-top: 1%;
padding-bottom: 1%;
}
.menu button:hover,
.dd-buttons:hover {
color: #ECEEFF;
}
/* styling the dropdown arrow */
#media only screen and (max-width: 480px) {
.menu img {
max-width: 7px;
height: auto;
display: inline-block;
}
}
#media only screen and (min-width: 481px) {
.menu img {
max-width: 15px;
height: auto;
display: inline-block;
}
}
/* dropdown list */
.dropdown {
position: relative;
}
.dropdown ul {
position: absolute;
background: #DFB830;
margin-top: 8px;
min-width: 150%;
display: flex;
justify-content: space-around;
align-items: center;
flex-direction: column;
list-style: none;
border-radius: 5px;
opacity: 0;
pointer-events: none;
transition: all 0.4s ease;
transform: translateY(10px);
}
/* styling dropdown menu list items */
.dropdown li {
width: 100%;
height: 100%;
line-height: 250%;
display: flex;
justify-content: center;
align-items: center;
transition: all 0.4s ease;
}
.dropdown a {
font-size: 1.5vw;
color: #2E3045;
}
/* when hovering over dropdown list */
.dropdown li:hover {
background-color: #E9CF72;
}
.dropdown button:focus+ul {
opacity: 1;
pointer-events: all;
transform: translateY(0px);
}
<!------------------------ menu ------------------------>
<nav>
<div class="menu">
<button class="dd-buttons">YouthDuo</button>
<button class="dd-buttons">Galactic Spirit</button>
<div class="dropdown">
<button>Feng Shui <img src="images/dropdown icon.png"></button>
<ul>
<li>Feng Shui Basics</li>
<li>CD's and DVD's</li>
<li>Books and EBooks</li>
</ul>
</div>
<div class="dropdown">
<button>Color Alchemy <img src="images/dropdown icon.png"></button>
<ul>
<li>Living in Color</li>
<li>Guided Training</li>
<li>Jami Lin's Products</li>
</ul>
</div>
</div>
</nav>

remove the pointer-events:none
.dropdown ul {
position: absolute;
background: #DFB830;
margin-top: 8px;
min-width: 150%;
display: flex;
justify-content: space-around;
align-items: center;
flex-direction: column;
list-style: none;
border-radius: 5px;
opacity: 0;
transition: all 0.4s ease;
transform: translateY(10px);
}

Related

Texts not aligning even if I use the "align-items" property to center

I cant seem to get the nav bar items to align to the center even if I set the align-items value to center, I cant seem to find any part of code which commands the nav bar items to stick to the right either!
I need a solution to this
#import url('https://fonts.googleapis.com/css2?family=Poppins:wght#200;300;400;500;600;700&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
nav {
display: flex;
height: 80px;
width: 100%;
background: #1b1b1b;
align-items: center;
justify-content: space-between;
padding: 0 50px 0 100px;
flex-wrap: wrap;
}
nav .logo {
color: #fff;
font-size: 35px;
font-weight: 600;
}
nav ul {
display: flex;
align-items: center;
flex-wrap: wrap;
list-style: none;
}
nav ul li {
margin: 0 5px;
}
nav ul li a {
color: #f2f2f2;
text-decoration: none;
font-size: 18px;
font-weight: 500;
padding: 8px 15px;
border-radius: 5px;
letter-spacing: 1px;
transition: all 0.3s ease;
}
nav ul li a:hover {
color: #111;
background: #fff;
}
nav .menu-btn i{
color: #fff;
font-size: 22px;
cursor: pointer;
display: none;
}
input[type="checkbox"] {
display: none;
}
#media (max-width: 1000px) {
nav{
padding: 0 40px 0 50px;
}
}
#media (max-width: 920px) {
nav .menu-btn i{
display: block;
}
#click:checked ~ .menu-btn i:before {
content: "\f00d";
}
nav ul {
position: fixed;
top: 80px;
left: -100%;
background: #111;
height: 100vh;
width: 100%;
text-align: center;
display: block;
transition: all 0.3s ease;
}
#click:checked ~ ul {
left: 0;
}
nav ul li {
width: 100%;
margin: 40px 0;
}
nav ul li a {
width: 100%;
margin-left: -100%;
display: block;
font-size: 20px;
transition: 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
#click:checked ~ ul li a {
margin-left: 0px;
}
nav ul li a:hover {
background: none;
color: cyan;
}
}
.content {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
z-index: -1;
width: 100%;
padding: 0 30px;
color: #1b1b1b;
}
.content div {
font-size: 40px;
font-weight: 700;
}
That's my CSS code, I tried to do what I could but I cant fix the problem
display: flex;
justify-content: flex-end;
align-items: center;
justify-content: flex-end; = inserts elements to the right x-axis position.
first of all to make it horizontally center you need to make the justify-content:center not the align-items
your code should be
nav{
/*...*/
justify-content:center;
/*...*/
}

Is there a way for me to center the LI in my navigation bar?

I'm following this guide for a responsive navigation bar that works for mobile and for web
https://www.youtube.com/watch?v=D-h8L5hgW-w&t=7225s
Sorry in advance if its a very easy solution.
Im struggling to center my navigation bar. Right now its placed left side.
<body>
<!-- Navigation bar-->
<div class="navbar">
<img id="mobile-cta" class="mobile-menu" src="/images/open.svg" alt="Open Navigation">
<nav>
<img id="mobile-exit" class="mobile-menu-exit" src="../images/close.svg" alt="Close Navigation">
<ul class="primary-nav">
<li class="current">Forside</> </li>
<li>Portfolio</li>
<li>Kontakt</li>
</ul>
</nav>
</div>
<body>
That looks like this
Picture of navbar
Picture of mobile version, this one is totally fine
And this is my whole CSS for the navbar.
/* Code for Navigation bar */
.navbar {
background: white;
padding: 1em;
position: sticky;
top: 0px;
width: 100%;
/* Hides the navigation menu when on mobile */
nav {
display: none;
}
.mobile-menu {
cursor: pointer;
}
/* Defines distance from logo and if the list should have dots etc. */
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
}
nav.menu-btn {
display: block;
}
/* Mobile menu navigation */
nav {
position: fixed;
z-index: 999;
width: 66%;
right: 0;
top: 0;
background: black;
height: 100vh;
padding: 1em;
ul.primary-nav {
margin-top: 5em;
}
li {
// Mobile menu text
a {
color: white;
text-decoration: none;
display: block;
padding: .5em;
font-size: 1.5em;
text-align: right;
&:hover {
color: #1e73be;
}
}
}
}
a {
display: block;
position: relative;
padding: 0em 0;
}
// Controls the text after animation
a::after {
content: '';
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 0.2em;
background-color: #1e73be;
opacity: 0;
transition: opacity 300ms, transform 300ms;
}
li a::after {
opacity: 1;
transform: scale(0);
transform-origin: center;
}
li a:hover::after,
li a:focus::after {
transform:scale(1);
font-weight: bold;
}
.mobile-menu-exit {
float: right;
margin: .5em;
cursor: pointer;
}
// Controls when to switch from mobile to website view.
#media only screen and (min-width: 768px) {
.mobile-menu,
.mobile-menu-exit {
display: none;
}
.navbar nav {
display: flex;
justify-content: space-between;
background: none;
position: unset;
height: auto;
width: 100%;
padding: 0;
ul {
display: flex;
text-align: center;
}
a {
color: black;
font-size: 1em;
padding: .1em 1em;
}
ul.primary-nav {
margin: 0;
}
// CSS for the current tab in navbar for web
li.current a {
color: #1e73be;
}
li a {
color: black;
border: 3px;
font-weight: bold;
border-radius: 5em;
margin-top: 0;
&:hover {
color: #1e73be;
}
}
}
}
On your min-width media query on .navbar nav use justify-content: center; instead of space-between so that your ul is centered. Then set another media query instructing the same width but max-width and then change it back to justify-content: space-between; to position your logo.
I've added a fiddle since you are using SCSS.

how to make a responsive navigation on the top

I want to make a responsive navigation on my website.
i didn't use a grid
I tried
#media screen and (max-width: 600px) {
.menu{
height: 100%;
width: 15px;
float: top;
}}
but that don't work
I want it to get on the top of my website
So some suggestions:
Send the html code or jsut some of it.
You can also try adding margin: 0; to the body:
body{
margin: 0;
}
You will also need to add a background - color:
.menu {
background-color: red;
}
And more stuff could be added but you can check this:
https://www.w3schools.com/howto/howto_css_style_header.asp
This helps a lot
You can use this codepen which I had made yesterday or may be before that, I don't remember :-
https://codepen.io/CodingPencil/pen/abEWzXp
Or just copy my code here :-
HTML -
<nav>
<div>
Something
</div>
<div>
<ul id="nav">
<li>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
<div class="menu" id="menu">
<span></span>
<span></span>
<span></span>
</div>
</nav>
CSS -
*,
*::after,
*::before {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Poppins", sans-serif;
}
:root {
--nav-bg: #03000e;
--main-clr: dodgerblue;
}
nav {
display: flex;
align-items: center;
justify-content: space-around;
position: fixed;
width: 100%;
background: #03000e;
}
nav .logo {
color: #fff;
text-decoration-color: var(--main-clr);
font-size: 22px;
font-family: "Playfair Display", serif;
font-weight: 100;
}
nav ul {
--padding: 20px;
--font-size: 17px;
list-style: none;
display: flex;
align-items: center;
font-size: var(--font-size);
overflow-y: hidden;
transition: 1s ease;
}
nav ul li {
padding: var(--padding);
}
nav ul li a {
color: #fff;
text-decoration: none;
position: relative;
}
nav ul li a::after {
content: "";
width: 0%;
height: 2.5px;
border-radius: 99px;
background: var(--main-clr);
position: absolute;
bottom: 0;
left: 0;
transition: 0.3s ease;
}
nav ul li a:hover::after {
width: 100%;
}
nav .menu {
width: 22px;
height: 16px;
cursor: pointer;
display: none;
align-items: center;
flex-direction: column;
justify-content: space-between;
position: relative;
margin: 20px;
}
nav .menu span {
width: 100%;
height: 2px;
border-radius: 99px;
background: #fff;
transition: 0.3s ease;
transform-origin: left;
}
nav .menu.active span {
background: var(--main-clr);
}
nav .menu.active span:nth-child(1) {
transform: rotate(40deg);
}
nav .menu span:nth-child(3) {
transform-origin: left;
}
nav .menu.active span:nth-child(3) {
transform: rotate(-40deg);
}
nav .menu.active span:nth-child(2) {
transform: scale(0);
}
#media (max-width: 910px) {
nav .menu {
display: flex;
}
nav ul {
--height: 0px;
flex-direction: column;
background: var(--nav-bg);
position: absolute;
width: 100%;
left: 0;
top: 56px;
height: var(--height);
transition: 1s ease;
}
nav ul.active {
--height: calc(
(((var(--padding) * 2) + (var(--font-size) * 1.5))) * var(--childenNumber)
);
transition: 1s ease;
}
nav ul li {
width: 100%;
text-align: center;
}
nav ul li a {
width: 100%;
text-transform: capitalize;
}
}
And the JAVASCRIPT -
const navigation = document.getElementById("nav");
const menu = document.getElementById("menu");
menu.addEventListener("click", () => {
navigation.style.setProperty("--childenNumber", navigation.children.length);
navigation.classList.toggle("active");
menu.classList.toggle("active");
});
There are many references available on the web you can take references from w3schools.com, bootstrap, codepen etc.
try below one,
<!DOCTYPE html>
<html>
<head>
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover {
background-color: #111;
}
</style>
</head>
<body>
<ul>
<li><a class="active" href="#home">Home</a></li>
<li>News</li>
<li>Contact</li>
<li>About</li>
</ul>
</body>
</html>
References:
https://getbootstrap.com/docs/5.0/components/navbar/
https://www.w3schools.com/css/css_navbar.asp
Note: float:top is not working

Hover effect isn't working in the sub-sub menu

I would like to create a dropdown menu that displays an image in the second dropdown. I have written the CSS code as it should be written, and I think there is no problem with the structure of my HTML code as well. So, after hovering on Afyon White list item, there should be displayed an image(position is not adjusted yet) but it does not. Any suggestions?
/* regardless */
li {
list-style: none;
text-transform: uppercase;
}
/* theme.scss */
.MegaMenu__Inner {
display: flex;
justify-content: space-between;
align-items: flex-start;
flex-wrap: nowrap;
flex-direction: column;
margin: 0 auto;
padding: 0 10px;
}
#media screen and (min-width: 1240px) {
.MegaMenu__Inner {
max-width: 1280px;
margin-left: auto;
margin-right: auto;
}
}
/* sca-jqueryblabla.scss */
.MegaMenu__Item {
display: inline-block;
position: relative;
width: 5rem;
transition: all 0.9s ease-in-out;
}
.MegaMenu__Item > .MegaMenu__Title {
display: inline-block;
}
.MegaMenu__Item > .MegaMenu__Title:hover {
transition: all 0.9s ease-in-out;
}
.MegaMenu__Title--dropdown {
display: none;
position: absolute;
z-index: 1;
width: 100%;
margin-top: -1.5rem;
margin-left: 4rem;
width: 100%;
transition: all 0.9s ease-in-out;
}
.DropdownList--li {
width: 9rem;
padding: 0.4rem;
}
.MegaMenu__Title--dropdown .DropdownList {
display: block;
position: relative;
}
.MegaMenu__Item:hover .MegaMenu__Title--dropdown {
display: block;
transition: all 9s ease-in-out;
}
.MegaMenu__Item.MegaMenu__Item--fit {
cursor: pointer;
padding: 0.5rem;
text-align: center;
background-color: white;
}
.MegaMenu__Item.MegaMenu__Item--fit a {
text-decoration: none;
color: #5c5c5c;
}
.MegaMenu__Item {
position: relative;
}
.Linklist {
position: absolute;
}
.DropdownList {
position: relative;
display: inline-block;
}
.color-nav {
display: none;
position: absolute;
width: 10rem;
height: 10rem;
border: 3px solid black;
}
.DropdownList--li:hover .color-nav {
display: inline-block;
}
<div class="MegaMenu__Item MegaMenu__Item--fit">
<a href="" class="MegaMenu__Title Heading Text--subdued u-h7"
>White</a>
<div class="MegaMenu__Title--dropdown">
<ul class="DropdownList DropdownList_White">
<li class="DropdownList--li DropdownList_White--li">
<a>Afyon White</a>
</li>
<div class="color-nav">
<img src="" alt="">
</div>
</ul>
</div>
</div>
The following <div>:
<div class="color-nav">
<img src="" alt="">
</div>
should be inside the <li> that has the class DropdownList--li DropdownList_White--li in order to be able to be selected as per your CSS which is:
.DropdownList--li:hover .color-nav {
display: inline-block;
}
That is, above, you are selecting .color-nav as a child of .DropdownList--li, but in your HTML the .color-nav is not its child.

Can't Horizontally Align

I am trying to horizontally align the social icons in my footer but I can't figure it out.
#font-face {
font-family: 'free pixel';
src: url(../assets/fontface/FreePixel.ttf);
font-style: normal;
}
body {
background-color: black;
}
a {
text-decoration: none;
}
a:visited{
text-decoration: none;
}
a:hover {
text-decoration: none;
}
li {
list-style: none;
}
h1 {
color: white;
}
/* x Global & General x */
nav {
display: flex;
justify-content: space-around;
align-items: center;
min-height: 8vh;
background-color: black;
font-family: 'free pixel';
}
.logo{
color: green;
font-size: 30px;
cursor: pointer;
}
.k-hole-logo{
color: green;
}
.nav-links{
display: flex;
justify-content: space-around;
width: 30%;
}
.nav-links a{
color: green;
text-decoration: none;
letter-spacing: 3px;
font-size: 15px;
}
.nav-links li {
list-style: none;
}
.burger {
display: none;
cursor: pointer;
}
.burger div {
width: 25px;
height: 3px;
margin: 5px;
background-color: green;
transition: all 0.3s ease;
}
#media screen and (max-width: 1024px){
.nav-links{
width: 60%;
}
}
#media screen and (max-width: 768px){
body{
overflow-x: hidden;
}
.nav-links{
position: absolute;
right: 0px;
height: 92vh;
top: 8vh;
background-color: black;
display: flex;
flex-direction: column;
align-items: center;
width: 33%;
transform: translateX(100%);
transition: transform 0.5s ease-in;
}
.nav-links li{
opacity: 0;
}
.burger{
display: block;
}
}
.nav-active{
transform: translateX(0%);
}
#keyframes navLinkFade{
from{
opacity: 0;
transform: translateX(50px);
}
to {
opacity: 1;
transform: translateX(0px);
}
}
.toggle .line1 {
transform: rotate(-45deg) translate(-5px, 6px);
}
.toggle .line2 {
opacity: 0;
}
.toggle .line3 {
transform: rotate(45deg) translate(-5px, -6px);
}
#social-icons {
position: fixed;
bottom: 0;
width: 100%;
}
#social-icons ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
#social-icons ul li a{
display: block;
color: green;
text-align: center;
padding: 16px;
text-decoration: none;
}
I have included all the CSS in case it is some issue with priority and I've done something in a previous section that is wrong. I am trying to center the social icons and have them be horizontally aligned with a bit of space between them...the section of the HTML I am trying to alter looks like this:
<footer>
<div id="social-icons">
<ul>
<li>
<i class="fab fa-twitter-square"></i>
</li>
<li>
<i class="fab fa-facebook-square"></i>
</li>
<li>
<i class="fab fa-instagram-square"></i>
</li>
</div>
</ul>
</div>
</footer>
Thanks! I appreciate the help!
First, remove the display: block from the <a> style, that's working against you.
Second, you want to declare a style for each <li> that says you want them to be displayed inline.
Third, you want to tell the whole #socialicons <div> to display the text centered on the page.
Here's what I'd change the CSS to:
#social-icons {
position: fixed;
bottom: 0;
width: 100%;
text-align: center;
}
#social-icons ul {
list-style-type: none;
padding: 0;
overflow: hidden;
}
#social-icons li {
display: inline;
}
#social-icons ul li a{
color: green;
text-align: center;
padding: 16px;
text-decoration: none;
}
If you are trying to align the items using Flexbox CSS properties, you need to apply display: flex; in the element wrapping the items you want to align.
In your specific case modify the #social-icons ul to include display: flex and this should do the trick.
#social-icons ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
display: flex;
}