简体   繁体   English

我如何才能使最后一个div不会在悬停时流入下一行?

[英]How can I make it so the last div does not flow into the next line on hover?

I want to make it so that the div with the id #watching-margin does not get pushed over into the next line of divs when I hover on the 11th div. 我想这样做,以便当我将鼠标悬停在第11个div上时,标识为#watching-margin的div不会被推到div的下一行。 Instead, I'd like it so that it would just move to the right without interruption, and possibly just hiding part of the id #watching-margin to keep the flow nice. 相反,我希望它能够不间断地向右移动,并且可能只是隐藏ID#watching-margin的一部分以保持流程顺畅。 Thank you! 谢谢!

 #section{ width:100%; margin:auto; overflow:hidden; } .container{ width:80%; margin:auto; margin-top:20px; text-align:center; padding:2px; } .watching{ position:relative; width:12%; float:left; border:1px solid black; height:250px; background-color:red; } .watching img{ width:100%; height:200px; } .watching{ margin-left:-50px; transition:.3s ease; } .watching:hover{ margin-right:50px; transition:.3s ease; } #watching-margin{ margin-left:-50px; } #watching-margin:hover{ margin-right:0; overflow:hidden; } 
 <section id=section> <div class="container"> <div class="watching"> <div class="img"></div> </div> <div class="watching"> <div class="img"></div> </div> <div class="watching"> <div class="img"></div> </div> <div class="watching"> <div class="img"></div> </div> <div class="watching"> <div class="img"></div> </div> <div class="watching"> <div class="img"></div> </div> <div class="watching"> <div class="img"></div> </div> <div class="watching"> <div class="img"></div> </div> <div class="watching"> <div class="img"></div> </div> <div class="watching"> <div class="img"></div> </div> <div class="watching"> <div class="img"></div> </div> <div class="watching" id="watching-margin"> <div class="img"></div> </div> <div class="watching"> <div class="img"></div> </div> <div class="watching"> <div class="img"></div> </div> </div> </section> 

An idea is to switch to inline-block element instead of float and use white-space:nowrap on container so that you keep them always in the same line: 一个想法是切换到inline-block元素而不是float,并在容器上使用white-space:nowrap ,以便始终将它们保持在同一行:

 #section { width: 100%; margin: auto; overflow: hidden; } .container { width: 80%; margin: auto; margin-top: 20px; text-align: center; padding: 2px; font-size:0; white-space:nowrap; } .watching { position: relative; width: 12%; display: inline-block; border: 1px solid black; height: 250px; background-color: red; font-size:initial; } .watching img { width: 100%; height: 200px; } .watching { margin-left: -50px; transition: .3s ease; } .watching:hover { margin-right: 50px; transition: .3s ease; } #watching-margin { margin-left: -50px; } #watching-margin:hover { margin-right: 0; overflow: hidden; } 
  <section id=section> <div class="container"> <div class="watching"> <div class=img></div> </div> <div class="watching"> <div class=img></div> </div> <div class="watching"> <div class=img></div> </div> <div class="watching"> <div class=img></div> </div> <div class="watching"> <div class=img></div> </div> <div class="watching"> <div class=img></div> </div> <div class="watching"> <div class=img></div> </div> <div class="watching"> <div class=img></div> </div> <div class="watching"> <div class=img></div> </div> <div class="watching"> <div class=img></div> </div> <div class="watching"> <div class=img></div> </div> <div class="watching" id="watching-margin"> <div class=img></div> </div> <div class="watching"> <div class=img></div> </div> <div class="watching"> <div class=img></div> </div> </div> </section> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用jQuery,我如何将鼠标悬停在一个元素上并使其其余兄弟姐妹更改大小? 没有DIV下降到下一行? - Using jQuery how can i on hover make an element active and make the rest of its siblings change sizes? without DIV dropping to the next line? 如何使按钮将类应用于文档流中的下一个div? - How can I make a button apply a class to the next div in the document flow? 是否可以在ap的最后一行旁边流动div容器? - Is it possible, to flow a div container right next to the last line of a p? 如何在div悬停内容上进行悬停? - How can I make a hover with content on a div hover? 我如何在div后面划一条线以使其不出现在CSS中的悬停上? - How can I make a line behind a div not to show up on hover in css? 如何使一行中的最后一个 div 溢出到下一行? - How do i make the last div in a row overflow into the next row? HTML:如何在div包装中创建一系列复选框到下一行? - HTML: How can I make a series of checkboxes within a div wrap to the next line? 由于只有文本溢出,我该如何使长文本的div转到下一行? - How can I make a div with long text go to next line as it was only text-overflow? 浮动的图像不会计入DIV宽度,我该怎么做? - A floated image does not count toward DIV width, how can I make it so? 如何在div的右侧制作悬停框? - How can I make hover box on the right side of my div?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM