• How do I avoid li element going down when I open another li element

    50 просмотра

    2 ответа

    So I have this list with some elements in it. The problem is that, when I open one of the li elements in my browser, the other li elements go down too. This is a photo for you to understand it

    image

    HTML:

    <ul class="gadgets-list">
    <li class="gadget"><img src="iconmonstr-keyboard-2-240.png" class="image">Keyboards<span class="caret"></span></a>
    <p class="item">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
    quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
    consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
    cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
    proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
    </li>
    <li class="gadget"><img class="image" src="iconmonstr-mouse-8-240.png">Mouses<span class="caret"></span></a></li>
    <li class="gadget"><img  class="image" src="iconmonstr-headphones-1-240.png">Headsets<span class="caret"></span></a></li>
    <li class="gadget"><img class="image" src="iconmonstr-computer-1-240.png">Monitors<span class="caret"></span></a></li>
    <li class="gadge"><img class="image" src="iconmonstr-cpu-1-240.png">Other components<span class="caret"></span></a></li>
    

    CSS:

    .gadgets-list {
      background-color: white;
      display: inline-block;
      word-spacing: 50px;
      width: 100%;
    }
    .item {
      word-spacing: normal;
    }
    .gadge {
      list-style: none;
      word-spacing: normal;
      display: inline-block;
    }
    p {
      width: 450px
    }
    
    Автор: degorybryant Источник Размещён: 08.11.2019 11:08

    Ответы (2)


    0 плюса

    Решение

    Add vertical-align: top; to your gadget as the lis are inline-block elements, and it all works fine I guess.

    Please let me know your feedback. Thanks!

    PS: typo for the gadget too... :)

    .gadgets-list {
      background-color: white;
      display: inline-block;
      word-spacing: 50px;
      width: 100%;
    }
    .item {
      word-spacing: normal;
    }
    .gadget {
      list-style: none;
      word-spacing: normal;
      display: inline-block;
      vertical-align: top;
    }
    p {
      width: 450px
    }
    <ul class="gadgets-list">
      <li class="gadget">
        <img src="iconmonstr-keyboard-2-240.png" class="image">Keyboards<span class="caret"></span>
        </a>
        <p class="item">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
          dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
      </li>
      <li class="gadget">
        <img class="image" src="iconmonstr-mouse-8-240.png">Mouses<span class="caret"></span>
        </a>
      </li>
      <li class="gadget">
        <img class="image" src="iconmonstr-headphones-1-240.png">Headsets<span class="caret"></span>
        </a>
      </li>
      <li class="gadget">
        <img class="image" src="iconmonstr-computer-1-240.png">Monitors<span class="caret"></span>
        </a>
      </li>
      <li class="gadget">
        <img class="image" src="iconmonstr-cpu-1-240.png">Other components<span class="caret"></span>
        </a>
      </li>

    Автор: kukkuz Размещён: 20.08.2016 10:17

    1 плюс

    There is typo in your css its .gadget not .gadge

    View this jsbin

    Автор: codeninja93 Размещён: 20.08.2016 10:00
    Вопросы из категории :
    32x32