简体   繁体   English

HTML / CSS-并排放置多个DIV元素,每个div为浏览器的宽度/高度的100%

[英]HTML/CSS - Positioning several DIV elements side by side, each div being 100% width/height of the browser

I can't figure this out and it's probably fairly simple. 我无法弄清楚,这可能很简单。 I have several DIV elements that I need placed side by side (with no margin in between), and each div must have a set width of 100% of the browser width and min-height of 100% of the browser. 我有几个DIV元素需要并排放置(中间没有空白),并且每个div的设置宽度必须为浏览器宽度的100%,最小高度为浏览器的100%。

Like I said I'm sure there's a quick and easy trick to this, I just couldn't find much in my research. 就像我说的那样,我敢肯定有一个快速简便的技巧,我只是在研究中找不到很多东西。 Thank you much! 非常感谢!

Update: This seems to work: http://pastebin.com/kuQyfwuG 更新:这似乎可行: http : //pastebin.com/kuQyfwuG

Maybe you can wrap all your divs in a container div whose width is a lot bigger than the width of the browser (or at least the total width of all your divs laid side by side): 也许您可以将所有div包装在一个容器div中,该容器的div宽度比浏览器的宽度大得多(或者至少是并排放置的所有div的总宽度):

HTML 的HTML

<div id="container">
  <div class="element"></div>
  <div class="element"></div>
  <div class="element"></div>
  <div class="element"></div>
  <div class="element"></div>
</div>

CSS 的CSS

body {
  overflow: hidden;
}

#container {
  width: 10000px;
  height: 100%;
}

.element {
  min-height: 100%;
  ...
}

jQuery jQuery的

$('.element').css('width', window.innerWidth);

body was given the property overflow: hidden; body被赋予了属性overflow: hidden; so that no horizontal scrollbars will be shown because of #container 's size. 因此,由于#container的大小,将不会显示水平滚动条。 And since giving .element a width of 100% will make it as wide as the #container element, you can add a little jQuery to make their width equal to the window's/browser's width. 并且由于将.element的宽度设置为100%将使其与#container元素一样宽,因此您可以添加一些jQuery以使其宽度等于窗口/浏览器的宽度。

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

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