问题是,当圆向右移动时,它不会悬停。一个可能的解决方案是将其放在一个容器中,该容器将随着圆圈延伸,并将悬停事件绑定到该容器,如下所示。
* {
margin: 0;
padding: 0;
}
:root {
--bg-color: #454678;
--color__1: salmon;
--color__2: lightskyblue;
--color__3: khaki;
--color__4: thistle;
--color__5: mediumturquoise;
}
body {
background-color: indianred;
}
.container {
display: -ms-grid;
display: grid;
grid-template-rows: 2em auto;
grid-template-columns: auto;
grid-template-areas:
"header"
"main";
grid-gap: 2px;
background-color: white;
justify-content: safe left;
align-content: center;
}
header {
grid-area: header;
}
main {
display: grid;
grid-area: main;
grid-template-columns: auto;
grid-template-rows: repeat(8, 1fr);
grid-gap: 10px;
justify-items: start;
align-content: center;
padding: 10px;
}
.circle {
height: 2em;
width: 2em;
border-radius: 50%;
background-color: var(--color__3, khaki);
transition: all 1.5s ease-in-out;
padding: 1em;
margin: 0 10em;
display: grid;
align-items: center;
justify-items: center;
color: transparent;
font-size: 10px;
}
.circle:nth-child(even) {
background-color: var(--color__1);
}
.outer:hover .circle {
-webkit-transform: translateX(100%);
transform: scale(2) translateX(50em);
background-color: var(--color__5, salmon);
color: white;
}
<div class="container">
<header>Press any Number</header>
<main>
<div class="outer"><div class="circle">1</div></div>
<div class="outer"><div class="circle">2</div></div>
<div class="outer"><div class="circle">3</div></div>
<div class="outer"><div class="circle">4</div></div>
<div class="outer"><div class="circle">5</div></div>
<div class="outer"><div class="circle">6</div></div>
<div class="outer"><div class="circle">7</div></div>
<div class="outer"><div class="circle">8</div></div>
</main>
</div>