one div gets bigger while the other gets smaller

前端 未结 3 416
死守一世寂寞
死守一世寂寞 2021-01-18 20:43

I\'m new to javascript, I\'m wondering how to get .contact from a 30% width to 40% when I go with my mouse over .contact. This works, but while .contact gets bigger I want .

3条回答
  •  难免孤独
    2021-01-18 21:08

    You can do it with Flexbox

    flex: 1 makes .contact expand to the rest of the available space.

    You would then only need to define the width for .div and its width when .contact is hovered.

    .content {
      display: flex;
    }
    
    .contact{
      background-color:red;
      flex: 1
    }
    
    .div {
      width: 70%;
      background-color: blue;  
    }
    
    .contact:hover + .div {
      width: 60%
    }

    Text

    More textt

    Text

    More textt

提交回复
热议问题