简体   繁体   English

使用HTML和CSS&JS创建流畅全屏布局的最佳技术?

[英]Best technique to create fluid fullscreen layout with HTML & CSS & JS?

What would be the best way to create fluid layout, which would fill the screen in both, horizontally and vertically ? 什么是创建流体布局的最佳方式,它将在水平和垂直方向 填充屏幕 (The layout should be 100% height of the window, so no scrollbars should be visible nor no scrolling required) (布局应该是窗口的100%高度,因此不应该看到滚动条,也不需要滚动)

I'm thinking purely as techniques go, since the elements of the layout will be changing. 我正在考虑纯粹的技术,因为布局的元素将会发生变化。

Example could be something like this: 示例可能是这样的:

---------------------------------------
| HEADER  100% x 100px                |
---------------------------------------
|         |                 |         |
| SIDEBAR |      FILL       | SIDEBAR |
| 200px   |                 | 30%     |
| x 100%  |                 | x 100%  |
|         |                 |         |
|         |                 |         |
---------------------------------------
  1. Header, that spans the whole screen, 标题,横跨整个屏幕,
  2. Sidebars, that are floated to the edges, and which span the rest of the available height 侧边栏,浮动到边缘,并跨越可用高度的其余部分
  3. And fill element, that fills the rest in horizontally and vertically 和填充元素,水平和垂直填充其余元素

Currently it looks like this can only be achieved with JavaScript manipulation on window resize (as far as the height and fill goes). 目前看起来这只能通过窗口调整大小的JavaScript操作来实现(就高度和填充而言)。

But what if we add/remove elements , like add bar on top of the header, or take another sidebar away? 但是,如果我们添加/删除元素 ,例如在标题顶部添加栏,或者采取另一个侧边栏,该怎么办? The whole layout should still be filling the screen without any code or style changes. 整个布局仍应填充屏幕,不需要任何代码或样式更改。 I'm somewhat stumped on how to approach this whole thing. 我有点难以理解如何处理这整件事。

Penny for your thoughts Internet? 便士你的想法互联网?

You don't have to have JavaScript - you can do it using HTML + CSS... 您不必拥有JavaScript - 您可以使用HTML + CSS来实现...

There are lots of three-column solutions here: 这里有很多三栏解决方案:

http://css-discuss.incutio.com/wiki/Three_Column_Layouts http://css-discuss.incutio.com/wiki/Three_Column_Layouts

Edit: Height Issue 编辑:高度问题

If you just want fluid with entire height, here is a solution I've mocked up on JSFiddle... 如果你只想要整个高度的流体,这里有一个我在JSFiddle上嘲笑的解决方案......

http://jsfiddle.net/Sohnee/qJjyc/ http://jsfiddle.net/Sohnee/qJjyc/

Update: 更新:

Here is an example with a header, to demonstrate how you take it into account... 这是一个带标题的示例,用于演示如何将其考虑在内...

http://jsfiddle.net/qJjyc/1/ http://jsfiddle.net/qJjyc/1/

If you are not targeting Internet Explorer, you can position:absolute , box-sizing:border-box , and a lot of top , right , bottom , left , width , and height to create nice full screen layouts, and you have a lot of control over where elements are placed related to its container. 如果您没有定位Internet Explorer,您可以position:absolutebox-sizing:border-box ,以及很多toprightbottomleftwidthheight以创建漂亮的全屏布局,并且您有很多控制与其容器相关的元素放置位置。

With border-box sizing, you don't have to worry that border and padding will expand the box. 使用border-box大小调整,您不必担心borderpadding会扩展框。

See this for an example: http://jsfiddle.net/thai/jtYDP/2/ 请看这个例子: http//jsfiddle.net/thai/jtYDP/2/

It works in Firefox and Chrome. 它适用于Firefox和Chrome。

I've modified Thai's jsfiddle to include a footer and I removed the right sidebar, I've set a min height and a min width to the main container and used more div to be able to manipulate paddings without breaking the page. 我修改了泰语的jsfiddle以包含一个页脚,我删除了右侧边栏,我已经为主容器设置了一个最小高度和一个最小宽度,并使用了更多的div来操作填充而不会破坏页面。 I also added some jQuery to hide and show the sidebar. 我还添加了一些jQuery来隐藏和显示侧边栏。 It works pretty well. 它工作得很好。

I had to make a web app so I used that layout. 我不得不制作一个网络应用程序,所以我使用了那个布局。

http://jsfiddle.net/gableroux/jtYDP/35/ http://jsfiddle.net/gableroux/jtYDP/35/

Hiding and showing sidebar change the size of content dynamically (using margins) so it may help some of you :). 隐藏和显示侧边栏动态地改变内容的大小(使用边距),这可能会帮助你们中的一些人:)。 Now my app feels really good. 现在我的应用感觉非常好。

I hope it helps. 我希望它有所帮助。

My favorite way to do it is this one . 我最喜欢这样做的方法就是这个 No JavaScript needed. 不需要JavaScript。

I just kind of rolled my own , not exactly there but I'd use it :D 我只是在推动我自己 ,不完全在那里,但我会用它:D

Only thing is making the columns 100% high... 唯一让柱子高100%......

也许YAML可以为你提供帮助。

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

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