【问题标题】:HTML5 + CSS3 Backwards compatibility on calc() css functioncalc() css 函数的 HTML5 + CSS3 向后兼容性
【发布时间】:2013-12-02 18:54:58
【问题描述】:

这是小提琴:http://jsfiddle.net/F793U/1/

我正在创建一个包含 4 个部分的 Web 应用程序,这些部分占据了 100% 的窗口空间。其中两个部分,侧边栏和内容,有自己的滚动条。永远不应该看到浏览器滚动条。为此,我使用了 css calc() 函数。

我的问题是:有没有更简单的方法来实现这一点?而且,如果没有,我如何将它应用到旧版浏览器(例如 IE 8 及更早版本)?

HTML:

<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="css/style.css" type="text/css">
</head>
<body>
    <div class="header-wrap">
        <div class="header">
            <div class="logo"><h4>Header</h4></div>
        </div>
    </div>
    <div class="content-wrap">
        <div class="side-bar">
            Sidebar
        </div>
        <div class="content-top">
            <div class="top">Content-Top</div>
        </div>
        <div class="content">
           <br />
           <div style="width: 95%; margin: 0 auto;">
                Content
            </div>
        </div>
    </div>
</body>
</html>

CSS:

* {
    margin: 0;
    padding: 0;
}
html, body {
    height: 100%;
    background: #d4d4d4; 
    font-family: "helvetica neue", Tahoma, Sans;
}
::-webkit-scrollbar {  
    width: 12px;  
}  
::-webkit-scrollbar-track {  
    background-color: #cecece;  
    border-left: 1px solid #ccc;  
}  
::-webkit-scrollbar-thumb {  
    background-color: #c0c0c0;  
    border-radius: 6px;
}  
    ::-webkit-scrollbar-thumb:hover {  
    background-color: #aaa;  
} 
.header-wrap {
    width: 100%;
    height: 30px;
}
.header {
    width: 100%;
    height: 29px;
    background: #c0c0c0;
    background: -webkit-linear-gradient(bottom, #cacaca,#eaeaea); /* For Safari */
    background: -o-linear-gradient(bottom, #cacaca, #eaeaea); /* For Opera 11.1 to 12.0 */
    background: -moz-linear-gradient(bottom, #cacaca, #eaeaea); /* For Firefox 3.6 to 15 */
    background: linear-gradient(bottom, #cacaca, #eaeaea); /* Standard syntax */
    border-bottom: 1px solid #a0a0a0;
    top: 0;
}
.content-wrap {
    top: 0;
    bottom: 0;
    right: 0;
    left: 0;
    height: 100%;
    width: 100%;
    min-width: 800px;
    height: -moz-calc(100% - 31px);
    height: -webkit-calc(100% - 31px);
    height: calc(100% - 31px); 
}
.side-bar {
    overflow-y: scroll;
    width: 280px;
    min-width: 280px;
    border-right: 1px solid #a0a0a0;
    height: 100%;
    padding: 0 10px;
    float: left;
}
.content-top {
    margin-left: 300px;
    margin-right: 0;
}
.top {
    width: 100%;
    height: 98px;
    border-bottom: 2px groove #fff;
}
.content {
    overflow-y: scroll;
    height: 100%;
    height: -moz-calc(100% - 100px);
    height: -webkit-calc(100% - 100px);
    height: calc(100% - 100px); 
    margin-top: 0;
    margin-left: 300px;
    margin-right: 0;
    margin-bottom: 0;
}

【问题讨论】:

  • CSS Calc alternative的可能重复
  • 啊,是的,它似乎确实是那个问题的副本。对不起。我进行了快速搜索,但没有使用“替代”。
  • 实际上,回想起来,我不确定先前答案中的 box-sizing 是否会对我的情况有所帮助,因为根本没有使用填充。

标签: html css cross-browser backwards-compatibility


【解决方案1】:

如果您想解决这个特殊情况,我建议您(也许有点讽刺)尝试依靠昔日良好的旧表格布局。但是,如果您想在不使用&lt;table&gt; 的情况下正确执行此操作,它确实会有点棘手,因为display:table 没有与colspanrowspan 属性等效的属性。

这意味着您可能需要使用比以前更多的容器,但仍然没有什么特别复杂的。

我做了一个相当基本的JSFiddle 来告诉你我的意思。

HTML

<div class="outer">
    <div class="header">Header</div>
    <div class="contentRow">
        <div class="contentTable">
            <div class="leftCol">Sidebar</div>
            <div class="rightCol">
                <div class="rightTable">
                    <div class="topContent">Top content</div>
                    <div class="content">Content</div>
                </div>
            </div>
        </div>
    </div>
</div>

CSS

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}
.outer {
    display: table;
    height: 100%;
    width: 100%;
}
.header {
    background: blue;
    display: table-row;
    height: 30px;
}
.contentRow {
    display: table-row;
}
.contentTable {
    display: table;
    width: 100%;
    height: 100%;
}
.leftCol {
    background: red;
    display: table-cell;
    width: 280px;
    min-width: 280px;
    height: 100%;
}
.rightCol {
    display: table-cell;
    height: 100%;
}
.rightTable {
    display: table;
    width: 100%;
    height: 100%;
}
.topContent {
    background: green;
    display: table-row;
    height: 100px;
}
.content {
    background: orange;
    display: table-row;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-22
    • 1970-01-01
    • 1970-01-01
    • 2011-08-27
    • 2014-07-03
    • 2012-08-18
    相关资源
    最近更新 更多