简体   繁体   English

浮动div内容直接位于所选div下方,即使div换行

[英]Floating divs with content directly below selected div, even if divs wrap

Thanks in advance for any assistance. 在此先感谢您的协助。

I am trying to create a row of fixed height/width div's with borders (squares): 我正在尝试创建带有边框(正方形)的固定高度/宽度div的行:

[ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ]

When one of those div's is clicked, another div, with content relating to the clicked div will appear below: 当单击其中一个div时,具有与单击的div相关的内容的另一个div将显示在下面:

[ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ]
--^----------------------------------------
CONTENT #1
-------------------------------------------

or 要么

[ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ]
--------^-----------------------------------
CONTENT #2
--------------------------------------------

I have all that working just fine, however I want to improve my code so that if viewing the page from a device with a smaller resolution, and the divs 1-5 wrap, the div with the corresponding content will sit just below the appropriate div: 我的所有工作都很好,但是我想改善代码,以便从分辨率较低的设备上查看页面,并使用divs 1-5换行,具有相应内容的div会位于相应div的正下方:

[ 1 ] [ 2 ] [ 3 ] 
--------^-----------------------------------
CONTENT #2
--------------------------------------------
[ 4 ] [ 5 ]

Instead of... 代替...

[ 1 ] [ 2 ] [ 3 ]
        ^
[ 4 ] [ 5 ]
-------------------------------------------
CONTENT #2
--------------------------------------------

I'm searching for a solution that doesn't require clunky javascript's to predetermine screen resolutions etc. 我正在寻找不需要笨拙的javascript来预先确定屏幕分辨率等的解决方案。

I've been at this for a while Anyone have any thoughts or ideas for me? 我已经有一段时间了,有人对我有什么想法或想法吗?

Best Regards 最好的祝福

Matt 马特

You have to do it with css border-bottom property, so that wherever div's gets positioned there will be a border placed at their bottom. 您必须使用css border-bottom属性来执行此操作,以便div定位的任何位置都将在其底部放置边框。 By using this logic, you can implement the way you mentioned by manipulating div width's with respect to browser width and making adjustments in css properties. 通过使用此逻辑,可以通过相对于浏览器宽度操纵div宽度并在css属性中进行调整来实现上述方法。 I hoped you got an idea to initiate it. 我希望您有个主意。

Here are content containers that wrap with an additional content container appearing on hover: http://jsbin.com/vepayi/2/edit?html,css,output 这是内容容器,其中包含一个附加的内容容器,该容器在悬停时出现: http : //jsbin.com/vepayi/2/edit?html,css,output

Do you need functionality on click? 您需要点击功能吗? What is the purpose of this UI? 这个用户界面的目的是什么?

Id advise not to follow the CSS only route, but just for fun, see fiddle : ID建议不要遵循仅CSS路线,而只是为了好玩, 请参阅小提琴

HTML 的HTML

<div class="box">
    <div class="num">
        <div class="num_in"><a href="#hell1">1</a>
        </div>
        <div id="hell1" class="hid">hello!</div>
    </div>
    <div class="num">
        <div class="num_in"><a href="#hell2">2</a>
        </div>
        <div id="hell2" class="hid">hello 2!</div>
    </div>
    <div class="num">
        <div class="num_in"><a href="#hell3">3</a>
        </div>
        <div id="hell3" class="hid">hello3!</div>
    </div>
    <div class="num">
        <div class="num_in"><a href="#hell4">4</a>
        </div>
        <div id="hell4" class="hid">hello 4!</div>
    </div>
    <div class="num">
        <div class="num_in"><a href="#hell5">5</a>
        </div>
        <div id="hell5" class="hid">hello 5!</div>
    </div>
</div>

CSS 的CSS

.box {
    display:block;
    border:1px solid #f00;
}
.num {
    display:inline-block;
    width:200px;
    border:1px solid #000;
    margin:10px;
    vertical-align:top;
    text-align:center
}
.hid {
    display:none;
    transition: all 1.5s ease-in-out;
}
.hid:target {
    display:block;
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM