首页 > 解决方案 > CSS悬停不执行其他元素

问题描述

/* 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;
}

i {
    margin-right: 0.3rem;
}

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

.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.05rem;
    border: 1px solid var(--nav-hue);
}

.nav .nav-hover:hover, .nav .nav-hover:hover a, 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;
}

.showcase-img {
    width: 960px;
    height: 400px;
    border-radius: 4px;
}

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

.showcase-img img:hover {
    transition: all 120ms ease-in-out;
    opacity: .3;
}

.showcase-img:hover + .showcase-text {
    transition: all 120ms ease-in-out;
    opacity: 1;
}

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

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

.showcase .showcase-text {
    display: inline-flex;
    flex-direction: column;
    position: absolute;
    bottom: 18.73rem;
    text-align: center;
    color: white;
    opacity: 0;
}

.showcase .showcase-text:hover, .showcase .showcase-text a:hover {
    opacity: 1;
}

.showcase .showcase-text h1 {
    font-size: 3rem;
    font-weight: bold;
    margin-bottom: 1rem;
}

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

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

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

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

.bold {
    font-weight: 400;
}

/* BUTTONS */
.btn {
    text-align: center;
    border: 1px solid white;
    padding: 0.5rem 1rem;
    margin: 0 12rem;
}

.btn:hover {
    transition: all 200ms ease-in-out;
    background-color: black;
    color: white;
}
<!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 src="images/read-dead-2.png" alt="">
            </div>
            <div class="showcase-text">
                <h1>Red Dead Redemption 2</h1>
                <a href="#" class="btn">Buy Now</a>
            </div>
            <ul>
                <li class="left-flash"><i class="fas fa-chevron-left"></i></li>
                <li class="right-flash"><i class="fas fa-chevron-right"></i></li>
            </ul>
        </div>
    </div>
    
</body>
</html>

// 当我将鼠标悬停在showcase-img 容器上时,我想降低容器的不透明度并增加showcase-text 容器的不透明度,但是我找不到实现此目的的好方法,左右按钮是也妨碍了我,我试着给他们一个显示:inline-flex; 但无济于事,当我将鼠标悬停在showcase-text div上时,showcase-img容器的不透明度会发生变化,但我也不希望这种情况发生,感谢您的帮助!

标签: htmlcss

解决方案


推荐阅读