0

这个问题将是页眉和页脚固定,内容可滚动固定页眉,页脚与可滚动内容的重复,如果不是一个细节,这对我来说非常重要 - 我不想为内容指定固定的高度和宽度.

http://jsfiddle.net/mark69_fnd/PWRDa/包含一个带有虚拟数据的真实表单,展示了问题 - 调整窗口大小使滚动条出现,但在页面上,而不是在表单上。在当前布局中,菜单栏和状态栏被滚动到视图之外,我希望它们保持固定,而表单数据被滚动。

请不要提供绝对宽度和/或高度的解决方案。我更喜欢用 javascript 计算它们,而不是将它们烘焙到 CSS 中,除非它是 100%。当然,纯 HTML/CSS 解决方案更可取。

这是CSS:

html, body, .yui3-app-views {
    height: 100%;
    width: 100%;
}

.container {
    position: relative; /* needed for footer positioning*/
    margin: 0 auto;
    height: auto;
    min-height: 100%;
    background-color: #eee;
}

.content {
    background-color: #ddd;
    padding: 0em 0em 2em; /* bottom padding for footer */
    overflow: auto;
}

#footer {
    position: absolute;
    width: 100%;
    bottom: 0; /* stick to bottom */
    background-color: #ccc;
}

#status {
    border: solid 1px #000000;
}

#status .error {
    color: red;
    font-weight: bold;
}

/* ------------------------------------------------------------------------------------*/
.char {
    display: inline-block;
    vertical-align: top;
}

.line {
    white-space: nowrap;
}

/* --------------------------------- fieldset and legend ------------------------------*/
.fieldset {
    border: 2px groove threedface;
    margin-top: 1em;
}

.fakeFieldset {
    padding: 2px;
}

.fieldset > div.legend:first-child {
    display: inline-block;
    text-align: left;
    margin-left: 10px;
    background: #ddd;
    position: relative;
    top: -0.7em;
}

.merge-bottom {
    margin-bottom: -2px;
}

/* ------------------------------------ Forms ------------------------------*/

form div {
    white-space: nowrap;
}

form select, form input {
    margin: 2px;
    border: 1px groove;
}

form label:not(.same-line) {
    width: 8em;
    text-align: right;
    display: inline-block
}

#cust-balance {
    text-align: center;
}

.ccExpDate {
    width: 2em;
}

#cust-salutation {
    width: 4em;
}

.postalCode {
    width: 7em;
}

#cust-ccAddress {
    width: 20em;
}
​
4

1 回答 1

2

// 使用来自询问者的输入进行更新。

很好用。我的宽度设置为 100%,但如果你愿意,当然你可以在 JS 中做到这一点。

您需要提供页眉和页脚position:fixed

我还在.contentdiv 中添加了一些填充,以便为顶部标题腾出空间。

如下所示:

html, body, .yui3-app-views {
    height: 100%;
    width: 100%;
}

.content {
    background-color: #ddd;
    padding: 2em 0em; /* padding for footer and header */
}

.menubar {
     position: fixed;
     top: 0px;
     width: 100%;
     z-index:1;
}

#footer {
    position: fixed;
    width: 100%;
    bottom: 0; /* stick to bottom */
    background-color: #ccc;
}
于 2012-10-28T04:10:14.347 回答