css - 使代码镜像 block 填充 Safari 中页面的其余部分

标签 css cross-browser flexbox height ui-codemirror

我要制作一个满足以下条件的页面:

  • 它包含第一部分的一些文本和一个 第二部分代码镜像
  • 第一部分中的文本几乎是固定的(因此它们的高度几乎是固定的),我希望代码镜像的高度恰好填满页面的其余部分。如果代码镜像中有很多文本,则使用滚动。

然后,我做这个plunker :

<style>
    .rb {
        display: flex;
        flex-direction: column;
        height: 100%;
    }

    .rb .CodeMirror {
        flex: 1;
    }
</style>

<div class="rb">
    1<br/>2<br/>3<br/>4<br/>
    <textarea ng-model="body" ui-codemirror="option"></textarea>
</div>

它在 Chrome 中完美运行,但在 Safari 中不起作用:代码镜像的高度不正确;我们立即看到问题:

enter image description here

有人知道怎么解决吗?我曾经有一个使用 calc 的解决方案(减去一个固定的 px),但我找不到了。

最佳答案

为什么不使用 height: 100% 而不是 flex: 1

.rb .CodeMirror {
  height: 100%;
}

更新:

为了 future 的用户,上面的方法不起作用,但是对于 Safari 和 Chrome,calc 都起作用了,所以:

.rb .CodeMirror {
  calc(100% - 80px); /* notice the spaces around "-" */
}

其中 80px 是原始帖子中描述的“第一部分”的高度。

Image from Safari 10.1.2 Plunker

关于css - 使代码镜像 block 填充 Safari 中页面的其余部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45394245/

相关文章:

javascript - CSS 和 &lt;input type ='file' > - 讨论

html - 当我们使用 flex 调整窗口大小时,自动调整具有适当间隙和宽度的 div

jquery - css 设计更改设备到设备

javascript - 无法将长 json 保存到 Internet Explorer 11 中的文件

css - 跨浏览器 CSS 是否需要 "CSS Reset"?

html - 使用 flexbox 固定左侧栏

css - 必要时将元素调整为两行

html - Flexbox div 文本环绕

html - float div 在 Chrome 中的 iframe 内的小程序上方不可见

css - float :right behaves differently in chrome and safari when using internal style sheet instead of inline style