简体   繁体   English

div宽度在较低分辨率下无法拉伸100%

[英]div width not stretching 100% on lower resolutions

I'm working on a website for a client, and I'm not excellent at css... still in the process of learning a lot about divs. 我正在为客户开发一个网站,但我在CSS方面并不出色...仍在学习有关div的很多知识。 I made a div that is supposed to stretch 100% of the page, and it works, unless a user is browsing from a lower resolution (1024 x 768 for example) and has to scroll horizontally, the div will then only extend to the original length of the browser window. 我制作了一个div,该div应该可以拉伸100%的页面,并且可以正常工作,除非用户从较低分辨率(例如1024 x 768)浏览并且必须水平滚动,否则div只会扩展到原始分辨率浏览器窗口的长度。

That coupled with the fact that my footer is behaving the same way, and is not sticking to the bottom of the page. 再加上我的页脚具有相同的行为,并且没有停留在页面底部的事实。

The code/website can be found at: http://cliqthis.com/temp/roadhouse/index.php 可以在以下位置找到该代码/网站: http : //cliqthis.com/temp/roadhouse/index.php

Thank you for any assistance, or an explanation of why this is happening would be helpful as I am still in the process of learning. 谢谢您的协助,或者解释为什么会这样,因为我仍在学习中。

You see the scrollbar for resolution 1024x768 because <div id='container'> has a width of 1064 pixels set on it. 您会看到分辨率为1024x768的滚动条,因为<div id='container'>的宽度设置为1064像素。 The parent div will have a minimum width of 1064 due to this. 因此,父div的最小宽度为1064。

Are we talking about the black bars not extending all the way to the right? 我们是在谈论黑条没有一直延伸到右边吗?

You need to make sure not only that those divs' widths are 100%, but that all their ancestors' widths are also 100%. 您不仅需要确保这些div的宽度为100%,而且必须确保其所有祖先的宽度也为 100%。 With normal (static) positioning, the 100% width means 100% of the element's parent's width. 在常规(静态)定位下,100%宽度表示元素父级宽度的100%。

Using the Web Developer addon in Firefox, with Outline Current Element turned on should prove very helpful in determining which elements aren't as wide as they need to be. 事实证明,在Firefox中使用Web Developer插件并启用Outline Current Element时,对确定哪些元素没有需要的宽度非常有用。 (Move your mouse around the page and it will outline the element you're over, and tell you the css selector path to it). (将鼠标移到页面上,它将概述您结束的元素,并告诉您CSS的选择器路径)。

Also you might want to compare the structure to the original template you used. 另外,您可能想将结构与您使用的原始模板进行比较。 It seems odd to me that, for example, you have an empty div.#footer element, and then a table.foot element after it, rather than inside of it. 例如,您有一个空的div。#footer元素,然后是一个table.foot元素,而不是它的内部,这对我来说似乎很奇怪。 Perhaps you accidentally broke something there? 也许您不小心弄坏了那里的东西?

设置div的最小宽度。

div.class { /* ... */ min-width: ___px !important; /* ... */ }

一个问题<div><button>在较低的分辨率上</button></div><div id="text_translate"><p>我正在制作一个基于文本的 RPG,一切正常,但是当我在按钮中有很多文本时,在较低的分辨率(例如 iphone 5、5se)上,我的按钮会被推出盒子(div)。</p><p> 任何想法?</p><p> HTML:</p><pre> &lt;div class="container"&gt; &lt;div id="text"&gt;Text&lt;/div&gt; &lt;div id="option-buttons" class="btn-grid"&gt; &lt;button type="button" class="btn"&gt; Option 1&lt;/button&gt; &lt;button type="button" class="btn"&gt; Option 1&lt;/button&gt; &lt;button type="button" class="btn"&gt; Option 1&lt;/button&gt; &lt;button type="button" class="btn"&gt; Option 1&lt;/button&gt; &lt;/div&gt; &lt;/div&gt;</pre><p> CSS:</p><pre> body { font-family: 'Roboto Mono', monospace; margin: 0; padding: 0; display:flex; justify-content: center; align-items: center; width: 100vw; height: 100vh; background-color: #474a56; }.container{ border-radius: 10px; width: 950px; max-width: 80%; background-color: white; padding: 2%; box-shadow: 0 0 10px 2px; text-align: center; }.btn-grid{ display: grid; grid-template-columns: repeat(2, auto); gap: 18px; margin-top: 2rem; }.btn{ font-family: 'Roboto mono', monospace; color: white; background-color: #474a56; border: 1px solid #d3d5fd; border-radius: 3.8px; padding: 10px 20px; outline: none; font-size: 1.1rem; }</pre></div> - Problem with a <div> and <button> on lower resolutions

暂无
暂无

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

相关问题 IE浏览器 <div> 到100%宽度 - IE Stretching My <div> to 100% Width 一个问题<div><button>在较低的分辨率上</button></div><div id="text_translate"><p>我正在制作一个基于文本的 RPG,一切正常,但是当我在按钮中有很多文本时,在较低的分辨率(例如 iphone 5、5se)上,我的按钮会被推出盒子(div)。</p><p> 任何想法?</p><p> HTML:</p><pre> &lt;div class="container"&gt; &lt;div id="text"&gt;Text&lt;/div&gt; &lt;div id="option-buttons" class="btn-grid"&gt; &lt;button type="button" class="btn"&gt; Option 1&lt;/button&gt; &lt;button type="button" class="btn"&gt; Option 1&lt;/button&gt; &lt;button type="button" class="btn"&gt; Option 1&lt;/button&gt; &lt;button type="button" class="btn"&gt; Option 1&lt;/button&gt; &lt;/div&gt; &lt;/div&gt;</pre><p> CSS:</p><pre> body { font-family: 'Roboto Mono', monospace; margin: 0; padding: 0; display:flex; justify-content: center; align-items: center; width: 100vw; height: 100vh; background-color: #474a56; }.container{ border-radius: 10px; width: 950px; max-width: 80%; background-color: white; padding: 2%; box-shadow: 0 0 10px 2px; text-align: center; }.btn-grid{ display: grid; grid-template-columns: repeat(2, auto); gap: 18px; margin-top: 2rem; }.btn{ font-family: 'Roboto mono', monospace; color: white; background-color: #474a56; border: 1px solid #d3d5fd; border-radius: 3.8px; padding: 10px 20px; outline: none; font-size: 1.1rem; }</pre></div> - Problem with a <div> and <button> on lower resolutions div 拉伸到指定宽度 - div stretching to specified width CSS:将图像拉伸至100%宽度 - CSS: Stretching image to 100% width style =“width:100%”正在拉伸包含div。 我不想要它 - style=“width:100%” is stretching the containing div. I don't want it to 为什么引导D-flex类阻止我的div伸展100%的宽度? - Why does bootstraps d-flex class stop my div from stretching 100% width? 将DIV拉伸到窗口的高度和宽度的100%,但不小于800x600px - Stretching DIV to 100% height and width of window but not less than 800x600px 将 DIV 设为祖父母的 100% 高度,同时拉伸祖父母的宽度 - Make DIV 100% height of grandparent, while also stretching grandparent's width CSS-段落拉伸了DIV的宽度 - CSS - Paragraph is stretching the width of the DIV SVG 波在 Safari 中未拉伸到 100% 宽度 - SVG wave not stretching to 100% width in Safari
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM