简体   繁体   English

自动增加div高度(父级为100%)并保留顶部和底部边距?

[英]Increase a div height automatically (100% parent) leaving a top and bottom margin?

http://jsfiddle.net/YumHS/ http://jsfiddle.net/YumHS/

In the page given in the jsfiddle der is a sidebar in the cont div. 在jsfiddle der给出的页面中,是cont div中的侧边栏。

<section class="cont">
                <div class="sidebar">
                    <ul>
                      <li>sidebar</li>
                    </ul>
                </div>
                <div class="content">
                  <div class="cm_logo"><img src="img/turf_cm_logo.png"></div>
                </div>
</section>

The sidebar has a right border. 侧边栏有一个右边框。 Der is a 10px margin in the top side of the sidebar. Der是侧边栏顶部的10px边距。 Similarly I want 10 margin in the bottom part also. 同样,我也希望底部有10个边距。 I have used 100% height so that div.sidebar fills up entire screen. 我使用了100%的高度,以便div.sidebar填满整个屏幕。 But with this method margin is not available at bottom since i'm using a sticky footer. 但是用这种方法,因为我使用的是粘性页脚,所以底部没有边距。 What can I do for this? 我该怎么办? Please help. 请帮忙。

Check the jsfiddle for the demo, to understand my question 查看jsfiddle进行演示,以了解我的问题

See the fiddle for code and demo 有关代码和演示,请参见小提琴

Fiddle: http://jsfiddle.net/YumHS/2 小提琴: http//jsfiddle.net/YumHS/2

Demo: http://jsfiddle.net/YumHS/2/embedded/result/ 演示: http : //jsfiddle.net/YumHS/2/embedded/result/

Updated fiddle: 1280 x 800 Resolution as per your requirement. 更新小提琴: 1280 x 800分辨率,根据您的要求。

http://jsfiddle.net/YumHS/5/embedded/result/ http://jsfiddle.net/YumHS/5/embedded/result/

To get the desired output i use image of 1px x 2000px. 为了获得所需的输出,我使用1px x 2000px的图像。 and adjust the position of background image see the css below, you can set the height( see 110%; ) of background image as you want. 并调整背景图片的位置,请参见下面的CSS,您可以根据需要设置背景图片的高度(请参见110%; )。

.sidebar {
    position: fixed;
    top: 100px;
    width: 227px;
    /*border-right: 1px solid #949698;*/
    height: 100%;
    background: url("http://img152.imageshack.us/img152/8141/fullbar.png") no-repeat right 110%;
}

In my system it is looking like below image: 在我的系统中,如下图所示:

在此处输入图片说明

Updated fiddle http://jsfiddle.net/YumHS/11/embedded/result/ - with 2px space space in sidebar and footer. 更新了小提琴 http://jsfiddle.net/YumHS/11/embedded/result/-边栏和页脚中有2px的空格。

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

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