【问题标题】:Resize two halves of a browser screen调整浏览器屏幕的两半
【发布时间】:2017-04-05 06:05:07
【问题描述】:

如何做到这一点将鼠标悬停在两个元素之间的边界上(这里在分隔蓝色和红色的垂直线上) 是否可以调整每个元素的宽度?

我正在寻找https://stackedit.io/editor的行为

这是否可以直接通过<textarea> 调整大小的可能性?

* { margin: 0; border: 0; padding: 0; }
textarea { background-color: red; width: 50%; position: absolute; top:0; left:0; height: 100%; }
#separator { cursor: ew-resize; position: absolute; top:0; width:1%; left:50%; height: 100%; }
#right { background-color: blue; width: 49%;  position: absolute; top:0; right:0; height: 100%;}
<textarea>hello</textarea>
<div id="separator"></div>
<div id="right">yo</div>

【问题讨论】:

标签: javascript html css


【解决方案1】:

有点像这样:

* { margin: 0; border: 0; padding: 0; }
html,body { height: 100% }
textarea { background-color: red; width: 50%; height: 100%; resize: horizontal; min-width: 1px; max-width: 99%; float: left; }
div { background-color: blue; height: 100%}
textarea:active {width: 1px;}
<textarea>hello</textarea>
<div>yo</div>

请注意,textarea:active 样式是必需的,因为 issue with chrome 不允许将元素的大小调整为小于其初始宽度。在 chrome 修复它之前解决它是一个糟糕的 hack。

【讨论】:

  • 不错@RobertMcKee,但是当悬停在垂直线上的 anywhere 时如何调整大小?目前它只在悬停页面底部时有效...
  • 那么你需要一些更复杂的东西,可能需要一些 javascript 和另一个元素作为分隔符。
  • 在最初的问题中,我有一个分隔符#separator,您认为是否可以在没有 javascript 的情况下重用它并拥有这种行为?
  • 有趣的是,您的原始问题有一个分隔符,因为我复制了您的问题以形成我的问题,但它没有。但是,如果不使用 javascript,我想不出一种方法来重用它。
猜你喜欢
  • 2012-01-28
  • 1970-01-01
  • 1970-01-01
  • 2023-03-11
  • 1970-01-01
  • 2021-12-22
  • 1970-01-01
  • 2013-10-11
  • 2022-01-26
相关资源
最近更新 更多