Iso
Iso

Reputation: 93

css ul getting in the way of :hover

/* GLOBAL */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@200;400;600&display=swap');

:root {
    --nav-hue: #2300d1;
    --background-color: #100e1a;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--background-color);
    font-family: 'Poppins', sans-serif;
    overflow-x: hidden;
}

h1, h2, h3, h4 {
    font-weight: 300;
}

ul {
    list-style: none;
}

a {
    text-decoration: none;
    color: white;
}

/* NAV */
.nav {
    height: 60px;
    width: 100vw;
    background-color: black;
    color: white;
    border-bottom: 0.15rem solid var(--nav-hue);
}

.nav i {
    margin-right: 0.3rem;
}

.logo {
    display: inline;
    padding: 0.1rem 1.5rem;
}

.nav .left-menu, .nav .right-menu {
    display: flex;
    align-items: center;
    margin-top: 0.4rem;
}

.nav .left-menu {
    flex: 2;
    margin-left: 1rem;
}

.nav .right-menu {
    flex: 1;
    margin-left: 10rem;
}

.nav ul li {
    padding: 0 0.8rem;
}

.nav-search {
    border: 1px solid white;
    padding: 0.4rem 0.6rem;
    border-radius: 2px;
    outline: none;
    text-align: center;
}

.nav-search:focus {
    transition: letter-spacing 200ms ease-in-out;
    letter-spacing: 0.02rem;
    border: 1px solid var(--nav-hue);
}

.nav .nav-hover:hover, .nav .nav-hover:hover a, .nav i:hover {
    transition: all 100ms ease-in-out;
    color: var(--nav-hue);
    cursor: pointer;
}

.small-hover:hover {
    transition: all 100ms ease-in-out;
    transform: scale(1.5) translateY(-0.2rem);
}




/* MAIN */
.container {
    max-width: 1100px;
    margin: auto;
    padding: 0.5rem;
}

/* SHOWCASE */
.showcase {
    place-items: center;
    margin-top: 1rem;
    z-index: 2;
    border: none;
}

.showcase-img {
    width: 960px;
    height: 470px;
    border-radius: 2px;
    border: 2px solid black;
    box-shadow: 3px 3px 15px hsl(250, 100%, 41%);
}

.showcase-img img {
    width: 100%;
    height: 100%;
}

.showcase-img img:hover {
    background-color: dodgerblue; /* testing */
    transition: all 0.2s ease-in-out;
    opacity: 0.7;
}

.showcase ul {
    display: flex;
    bottom: 15.6rem;
    position: relative;
    justify-content: space-between;
    width: 85%;
}

.showcase ul li {
    color: black;
    font-size: 2.5rem;
}

.showcase ul li i:hover {
    transition: all 150ms ease-in-out;
    font-size: 2.7rem;
    color: var(--nav-hue);
    cursor: pointer;
}

.showcase ul li i:active {
    transition: all 50ms ease-in-out;
    transform: translateY(0.2rem);
    font-size: 2.9rem;
    color: white;
}

/* UTILS */
/* GRID & FLEX */
.flex {
    display: flex;
    text-align: center;
}

.column {
    flex-direction: column;
}

.grid {
    display: grid;
    grid-template-columns: 1fr;
}

.grid-center {
    place-items: center;
}

.nav-hue {
    color: var(--nav-hue);
}

.bold {
    font-weight: 400;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" referrerpolicy="no-referrer" />
    <link rel="stylesheet" href="all.css">
    <title>GameBuy.com</title>
</head>
<body>

    <!-- NAVBAR -->
    <div class="nav">
        <div class="flex">
            <h1 class="logo">Game<span class="nav-hue bold">Buy.com</span></h1>
                <ul class="left-menu">
                    <li><span class="nav-hover"><i class="fas fa-home"></i><a href="#">Home</a></i></span></li>
                    <li><span class="nav-hover"><i class="fas fa-question"></i><a href="#">About</a></i></span></li>
                </ul>

                <ul class="right-menu">
                    <li><input class="nav-search" type="search" placeholder="SEARCH"></li>
                    <li><i class="fas fa-shopping-cart small-hover"></i></li>
                    <li><i class="fas fa-search small-hover"></i></li>
                </ul>
            </div>

    </div>


    <div class="container">
        <!-- SLIDER SHOWCASE -->
        <div class="showcase grid">
            <div class="showcase-img">
                <img id="image" src="images/arma3.png" alt="">
            </div>
            <ul>
                <li class="left-flash"><i id="left-flash" class="fas fa-chevron-left"></i></li>
                <li class="right-flash"><i id="right-flash" class="fas fa-chevron-right"></i></li>
            </ul>
        </div>
    </div>
    
    <script src="index.js"></script>
</body>
</html>

// When i hover over the showcase-img container the opacity changes but when the mouse goes over the ul which contains 2 li's that are icons the hovering stops and the opacity resets which shouldn't happen, i want the opacity to stay at 0.7 while the mouse is in the showcase-img container, how can i fix this? Thanks!

Upvotes: 1

Views: 51

Answers (1)

Suryansh Singh
Suryansh Singh

Reputation: 1173

Rather than applying :hover directly on image like this .showcase-img img:hover img{} apply it directly on parent div it means .showcase:hover img{}. This should be something like this:

/* GLOBAL */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@200;400;600&display=swap');

:root {
    --nav-hue: #2300d1;
    --background-color: #100e1a;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--background-color);
    font-family: 'Poppins', sans-serif;
    overflow-x: hidden;
}

h1, h2, h3, h4 {
    font-weight: 300;
}

ul {
    list-style: none;
}

a {
    text-decoration: none;
    color: white;
}

/* NAV */
.nav {
    height: 60px;
    width: 100vw;
    background-color: black;
    color: white;
    border-bottom: 0.15rem solid var(--nav-hue);
}

.nav i {
    margin-right: 0.3rem;
}

.logo {
    display: inline;
    padding: 0.1rem 1.5rem;
}

.nav .left-menu, .nav .right-menu {
    display: flex;
    align-items: center;
    margin-top: 0.4rem;
}

.nav .left-menu {
    flex: 2;
    margin-left: 1rem;
}

.nav .right-menu {
    flex: 1;
    margin-left: 10rem;
}

.nav ul li {
    padding: 0 0.8rem;
}

.nav-search {
    border: 1px solid white;
    padding: 0.4rem 0.6rem;
    border-radius: 2px;
    outline: none;
    text-align: center;
}

.nav-search:focus {
    transition: letter-spacing 200ms ease-in-out;
    letter-spacing: 0.02rem;
    border: 1px solid var(--nav-hue);
}

.nav .nav-hover:hover, .nav .nav-hover:hover a, .nav i:hover {
    transition: all 100ms ease-in-out;
    color: var(--nav-hue);
    cursor: pointer;
}

.small-hover:hover {
    transition: all 100ms ease-in-out;
    transform: scale(1.5) translateY(-0.2rem);
}




/* MAIN */
.container {
    max-width: 1100px;
    margin: auto;
    padding: 0.5rem;
}

/* SHOWCASE */
.showcase {
    place-items: center;
    margin-top: 1rem;
    z-index: 2;
    border: none;
}

.showcase-img {
    width: 960px;
    height: 470px;
    border-radius: 2px;
    border: 2px solid black;
    box-shadow: 3px 3px 15px hsl(250, 100%, 41%);
}

.showcase-img img {
    width: 100%;
    height: 100%;
}

.showcase:hover img {
    background-color: dodgerblue; /* testing */
    transition: all 0.2s ease-in-out;
    opacity: 0.7;
}

.showcase ul {
    display: flex;
    bottom: 15.6rem;
    position: relative;
    justify-content: space-between;
    width: 85%;
}

.showcase ul li {
    color: black;
    font-size: 2.5rem;
}

.showcase ul li i:hover {
    transition: all 150ms ease-in-out;
    font-size: 2.7rem;
    color: var(--nav-hue);
    cursor: pointer;
}

.showcase ul li i:active {
    transition: all 50ms ease-in-out;
    transform: translateY(0.2rem);
    font-size: 2.9rem;
    color: white;
}

/* UTILS */
/* GRID & FLEX */
.flex {
    display: flex;
    text-align: center;
}

.column {
    flex-direction: column;
}

.grid {
    display: grid;
    grid-template-columns: 1fr;
}

.grid-center {
    place-items: center;
}

.nav-hue {
    color: var(--nav-hue);
}

.bold {
    font-weight: 400;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" referrerpolicy="no-referrer" />
    <link rel="stylesheet" href="all.css">
    <title>GameBuy.com</title>
</head>
<body>

    <!-- NAVBAR -->
    <div class="nav">
        <div class="flex">
            <h1 class="logo">Game<span class="nav-hue bold">Buy.com</span></h1>
                <ul class="left-menu">
                    <li><span class="nav-hover"><i class="fas fa-home"></i><a href="#">Home</a></i></span></li>
                    <li><span class="nav-hover"><i class="fas fa-question"></i><a href="#">About</a></i></span></li>
                </ul>

                <ul class="right-menu">
                    <li><input class="nav-search" type="search" placeholder="SEARCH"></li>
                    <li><i class="fas fa-shopping-cart small-hover"></i></li>
                    <li><i class="fas fa-search small-hover"></i></li>
                </ul>
            </div>

    </div>


    <div class="container">
        <!-- SLIDER SHOWCASE -->
        <div class="showcase grid">
            <div class="showcase-img">
                <img id="image" src="images/arma3.png" alt="">
            </div>
            <ul>
                <li class="left-flash"><i id="left-flash" class="fas fa-chevron-left"></i></li>
                <li class="right-flash"><i id="right-flash" class="fas fa-chevron-right"></i></li>
            </ul>
        </div>
    </div>
    
    <script src="index.js"></script>
</body>
</html>

Upvotes: 1

Related Questions