简体   繁体   English

100%的高度和宽度,CSS和动态内容

[英]100% Height and Width, CSS and Dynamic Content

I've looked around and haven't found QUITE what I'm looking for yet, so hopefully this question hasn't already been answered somewhere else! 我环顾四周,还没有找到我想要的东西,所以希望这个问题尚未在其他地方得到解答!

Anyways, the layout in question can be found HERE . 无论如何,可以在这里找到有问题的布局。 What I am trying to achieve is a fixed width left column, and fluid width content area. 我要实现的是固定宽度的左列和流体宽度内容区域。 For the most part, it works just fine. 在大多数情况下,它工作正常。 However, when content expands beyond the browser window's height or width, the sections don't seem to expand like I would want. 但是,当内容扩展到浏览器窗口的高度或宽度之外时,这些部分似乎并没有像我想要的那样扩展。 Notice how to grey bar at the top doesn't reach the right of the page content, and the height of the left column doesn't reach the bottom of the page content either. 请注意,顶部的灰色条如何不到达页面内容的右侧,并且左列的高度也不到达页面内容的底部。

Am I right in thinking this stems from the fact that setting something to 100% height or 100% width via CSS is static? 我是否认为这是因为通过CSS将某些内容设置为100%高度或100%宽度是静态的事实是否正确? ie Whatever the height/width of the browser window was when the CSS was called is saved and that's that? 即保存CSS时浏览器窗口的高度/宽度是多少,就是这样?

If that's the case, maybe I need to look into some other methods of setting the height and widths of my elements. 如果是这种情况,也许我需要研究设置元素高度和宽度的其他方法。 Any ideas? 有任何想法吗? Also, note that the dummy content in the page is an image for now. 另外,请注意,页面中的虚拟内容目前只是图像。 I wanted to blur out names, etc. to keep data private. 我想模糊名称等以保持数据私有。

THANKS FOR ALL OF YOUR HELP!!! 感谢您所有的帮助!!!

How about something like this... 这样的事情怎么样...

The left column will only go as far as the right content though. 左边的列将只到达右边的内容。 If you want it to expand to the height of the viewport when there's not enough content to fill you'll need some javascript or you'll have to use a repeating background that fills the html 如果要在没有足够的内容填充时将其扩展到视口的高度,则需要使用一些JavaScript或使用重复的背景填充html

Demo: http://jsfiddle.net/wdm954/KyUfN/ 演示: http//jsfiddle.net/wdm954/KyUfN/

<div id="wrapper">
    <div id="left">left</div>
    <div id="right">       
        <div id="content">
        <div id="top">top</div>
            content
        </div>
    </div>
</div>

CSS... CSS ...

/* clearfix */
#wrapper:after, #right:after {
    content: ".";
    display: block;
    height: 0;
    clear: both;
    visibility: hidden;
    font-size: 0;
}

#wrapper, #right {
    display: inline-block;
}

#wrapper, #right {
    display: block;
    -height: 1px;
}
/* end clearfix */

#wrapper {
    background-color: #000000;
}

#left {
    float: left;
    width: 300px;
    color: #FFF;
}

#right {
    margin-left: 300px;
}

#top {
    height: 100px;
    background-color: #DEDEDE;
    border-bottom: 1px solid #B8B8B8;
}

#content {
    background-color: #F4EBEB;
    height: 600px;
    width: 1200px;
}

If the background is the main problem, you can just style the wrapper. 如果背景是主要问题,则可以设置包装的样式。 This is what I ended up doing for an unruly sidebar, as I didn't want to resort to JS and other solutions didn't work for me. 这就是我最终为不规则的侧栏所做的事情,因为我不想求助于JS,而其他解决方案也对我不起作用。 In my case, the issue with the sidebar came because of jQuery tabs, that are part of the theme. 就我而言,侧栏的问题是由于jQuery选项卡(属于主题)而引起的。 When I switched to the tabs, the sidebar wouldn't extend to the full height, so the background wouldn't either. 当我切换到选项卡时,侧栏不会扩展到整个高度,因此背景也不会。

HTML 的HTML

<div id="wrapper" class="sidebar-right">
    <div id="maincontent">
    #content
    </div>
    <div id="sidebar-right">
    #sidebar content
    </div>
</div>

CSS (this presumes 960 grid with 280px sidebar) CSS (假定960网格带有280px边栏)

#wrapper.sidebar-right{
    background: white url('images/bg.png');
    background-repeat: repeat-y; /*repeats down the length of the page*/
    background-position: 680px 0px; /*moves it into place*/
    }

If you have different sidebars, or full-width layouts, change the background image/position and style accordingly. 如果您使用不同的侧边栏或全角布局,请相应地更改背景图像/位置和样式。 Hope that helps someone. 希望能对某人有所帮助。

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

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