3

当子元素的数量不同时,有没有办法将子按钮元素粘贴到父元素的底部?

父元素是固定高度的,可以垂直滚动以防子元素溢出。在这种情况下,按钮应该在子列表的末尾,但是如果没有子元素,或者子元素的大小不推动父元素溢出,它应该在父元素的底部。

有没有纯css解决方案?

谢谢

4

3 回答 3

4

*编辑为更可靠的方法:

基本上,如果我理解正确,您可以使用粘性页脚逻辑 - 就在面板内:

HTML:

<div class="panel-container">
    <div class="panel-content">
        <div class="wrapper">
            <p>asdfasdfasdfadfs</p>
            <!--<p>asdfasdfasdfadfs<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br></p>-->
            <div class="push"></div>
        </div>
        <div class="footer">
            <button>Click click!</button>
        </div>
    </div>
</div>

CSS

.panel-container {width:300px;height:300px;margin:20px;background:#f2f2f2;overflow:auto;}
.panel-content {
    height: 100%;
}
.wrapper {
    min-height: 100%;
    height: auto !important;
    height: 100%;
    margin: 0 auto -30px; 
}
.footer, .push {
    height: 30px; /* .push must be the same height as .footer */
}
.footer {background:#ccc;}

工作示例: http: //jsfiddle.net/9SHdN/47/(取消注释注释<p>以查看长文本滚动)

于 2012-07-10T14:24:12.390 回答
1

好的,我不知道我是否真的理解你的问题,但这里是一个尝试:

父 div:

<div class="options_div"> 
   <p>Text inside</p>

   <ul class="options">
       <li>option 1</li>
       <li>option 2</li>
       <li>option 3</li>
   </ul>

   <input type="button" name="go" value="Goooo!" />
</div>

CSS:

.options_div {
    width: 300px;
    height: 200px;
    overflow: scroll;
}

.options_div>ul {
    list-style: none;
}

.options_div>ul>li {
    /* do what everrrr you want with it */
}

此代码生成一个 200px 高的 div,按钮位于底部。如果 ul 中有任何选项,则按钮将被按下并始终停留在列表的末尾。

希望这可以帮助!

于 2012-07-10T14:42:48.910 回答
1

这是一个想法:

.panel {position:relative;height:300px;width:300px;background:#f2f2f2;overflow:auto;}

.varyingContent { height:280px; display:table-cell; }

.button { position:relative; height:20px;}

<div class="panel">
        <div class="varyingContent">
        asdfadf
        <br />
        <br />
        asdfadf
        <br />
        <br />
        asdfadf
        <br />
        <br />
        asdfadf
        <br />
        <br />
        asdfadf
        <br />
        <br />
        asdfadf
        <br />
        <br />
        asdfadf
        <br />
        <br />
        asdfadf
        <br />
        <br />
        asdfadf
        <br />
        <br />
        asdfadf
        <br />
        <br />
        </div>
        <button class="button">test</button>
    </div>

希望这可以帮助

于 2012-07-10T15:10:56.853 回答