当我们想要元素水平排列的时候,inline-block或者float是最好的选择了,但是当父元素的宽高都设置了的时候,子元素会失效,如下:

代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
.item1 {
background: red;
width: 100%;
height: 100px;
display: inline-block
}

.item2 {
width: 100%;
height: 100px;
display: inline-block;
background-color: yellow;
}
</style> </head> <body> <div class="warp"> <div class="item1"></div> <div class="item2"></div> </div> </body> </html>

  效果:

当inline-block或者float失效的时候怎么弄

 

很明显不是我们想要的效果,你把怎么解决呢,只需要一句代码即可:

 

  .warp {
            white-space: nowrap;
        }

  当inline-block或者float失效的时候怎么弄

 

相关文章:

  • 2022-12-23
  • 2022-01-15
  • 2021-10-01
  • 2022-02-12
  • 2021-11-28
  • 2021-06-07
猜你喜欢
  • 2021-12-12
  • 2022-12-23
  • 2021-09-25
  • 2022-02-28
  • 2022-03-02
  • 2022-12-23
相关资源
相似解决方案