使用 javascript 获取 div 当前(渲染)宽度
嘿,我有一个 php 脚本,它从数据库中拖动一些图像并使用 float:left; 显示它们。所以他们从左到右。
然而,除非在CSS中我定义了容器的宽度,否则它们会跳到第二行。
所以问题是!
在我的一生中,我如何让它计算出内容的宽度,然后通过 javascript 设置宽度属性,所有这些都在一次加载中。
我确实有点担心这不太容易实现,因为它必须先渲染图像/布局以获得宽度,然后再调整它。
请大家出主意!! x
Hey, Ive got an php script dragging some images from a database and displaying them using float:left; so they go left to right.
However unless in the css i define i width for the container they jump down onto a 2nd line.
So the question IS!
How for the life of me could I get it to figure out the width of the content and then set the width attribute via javascript all on the one load.
I did have a slight worry that this wouldnt be easily possible as it wud have had to render the images/layout first to get a width before then adjusting it.
Ideas please people!! x
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的问题与浮动流如何工作有关......
如果两个图像浮动并且它们的宽度总和比包含元素更宽,它们将换行(类似于段落中单词换行的方式)。
描述“浮动”元素流程的视觉参考(很难用几句话来描述):
Your question has to do with how the flows of floats work...
If two images are floated and the sum of their widths is wider than the containing element, they will wrap (similar to the way words in a paragraph wrap).
Visual references describing the flow of "float"ed elements (way too difficult to describe in a few words):