简体   繁体   English

CSS/PHP 用 div 填充屏幕

[英]CSS/PHP Fill Screen with divs

I am trying to fill the screen with divs, and I'm thinking about using php to dynamically resize the divs based on the screen resoultion, so, for example, 16 divs always appear in each row.我正在尝试用 div 填充屏幕,并且正在考虑使用 php 根据屏幕分辨率动态调整 div 的大小,例如,每行中总是出现 16 个 div。

DIV 间距示例

Example A is the problem, in Example BI resize the divs to fit the screen.示例 A 是问题,在示例 BI 中调整 div 的大小以适合屏幕。

So, is this efficient?那么,这是否有效? I would have something like this for each background image of each div:对于每个 div 的每个背景图像,我都会有这样的东西:

/bgimage.php?id=123456&resize=125

Where resize is calculated by dividing the browser width by 16, or the # of divs I want in each row.其中 resize 是通过将浏览器宽度除以 16 或每行中我想要的 div 数来计算的。

I'm not sure about using this method, because I don't want the divs to appear to small if the resolution is very low.我不确定是否使用这种方法,因为如果分辨率非常低,我不希望 div 看起来很小。

Any other suggestions?还有其他建议吗? Could this be done better using just CSS or javascript?仅使用 CSS 或 javascript 可以做得更好吗? The

I don't see why you need any scripting in any language?我不明白你为什么需要任何语言的脚本?

If you set every div to float left with a width of 6% then 16 divs will take up 96% of the width no matter what the screen is resized to.如果您将每个 div 设置为以 6% 的宽度向左浮动,那么无论屏幕大小调整到什么大小,16 个 div 都将占据 96% 的宽度。 You can wrap them in another div with a 4% margin to handle the remaining 4%.您可以将它们包装在另一个 div 中,留出 4% 的边距来处理剩余的 4%。

You can do this in CSS alone.您可以单独在 CSS 中执行此操作。 Simply set the width of the div to 6.25% (100/16), and then set a min-width for that smallest possible width.只需将 div 的宽度设置为 6.25% (100/16),然后为可能的最小宽度设置一个最小宽度。

http://jsbin.com/ozuxa4 http://jsbin.com/ozuxa4

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

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