doushao8421 2011-07-15 11:20
浏览 49
已采纳

获取实际宽度而不是自动使用PHP

How can I determine the explicit width of a HTML element that has width auto using PHP?

JQuery has the ability to do this if width:auto; is used it can compute the actual width.

Get the current computed width for the first element in the set of matched elements.

JQuery probably does this with the help of the browser as it is client side.

How can I achieve this using PHP? I have the HTML as a string.

Update

All CSS is inline, if the width is auto, the only thing left to determine the width of the element is its immediate parent and/or its contents.

  • 写回答

2条回答 默认 最新

  • druzuz321103 2011-07-15 11:25
    关注

    The only way this would be possible in PHP is if you have both the HTML and the complete CSS as strings AND the width of the element is defined in absolute pixels or the width of its container (or the parent's container, etc) is defined in absolute pixels. If all these conditions were true, it would still be extremely difficult to figure out. Basically you'd have to code a rendering engine in PHP.

    If you were really lucky, the element you needed would have an inline style="width:px" and you could parse for that attribute.

    This is possible in Javascript because the browser knows its own size. Under most circumstances, the HTML in a string doesn't have a size until rendered in a browser.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 processing提取音乐节奏
  • ¥15 python进程启动打包问题
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条