当一个人被徘徊时,我一直试图让所有其他链接缩小,但到目前为止它只会收缩链接 .navlink { width: 100px; display:inline-block; background-color: red;}.navlink:hover~.navlink { width: 50px;}.navlink:hover { width:
.navlink { width: 100px; display:inline-block; background-color: red; } .navlink:hover~.navlink { width: 50px; } .navlink:hover { width: 150px; background-color: pink; }
<a class="navlink">link 1</a> <a class="navlink">link 2</a> <a class="navlink">link 3</a> <a class="navlink">link 4</a>您可以尝试使用flexbox,您只需要调整悬停链接,另一个默认会收缩
.container { display: flex; width: 400px; } .navlink { flex: 1; margin: 0 5px; background-color: red; transition: 0.3s all; } .navlink:hover { flex: 3; /*Adjust this to control the size*/ background-color: pink; }
<div class="container"> <a class="navlink">link 1</a> <a class="navlink">link 2</a> <a class="navlink">link 3</a> <a class="navlink">link 4</a> </div>