PHP根据宽度确定字体大小 [英] PHP Determining Font Size based off of width

查看:163
本文介绍了PHP根据宽度确定字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有元素的静态宽度,以及由用户插入的未知字符串长度。我试图保持JavaScript,否则这个问题将通过使用其他职位描述的jQuery方法解决。

我生成一个静态页面与PHP赢得了'我想要计算的文本的大小,以适应内部的div。

这是可能的,只有如下:
- 字符串长度
- 容器宽度
- 使用PHP的服务器端



如果可以,请帮我找到正确的解决方案如果这是关于一个HTML元素的话,那么这个元素就是一个HTML元素,你将无法以100%的可靠性确定PHP的宽度。您必须在客户端浏览器中实际渲染元素才能找到它,并且只能使用JavaScript。



再加上客户端有很多因素会影响结果:


  • 操作系统的文本大小级别

  • 浏览器的缩放级别

  • 客户机上使用的字体的可用性


    您可能最好使用普通缩放在平均网页浏览器中手动确定元素的宽度(或者如果是动态文本,也许使用@Jared提议的)


    I have static width of an element, and an unknown string length which is inserted by the user. I'm trying to keep javascript out otherwise this problem would be solved via using jQuery method described in other posts.

    I'm generating a static page with php that won't change and I'm trying to calculate the size of the text in order to fit inside the div.

    Is this possible with only having the following: - String Length - Width of Container - Server side with PHP

    and if so could you please lend me a hand in finding the correct solution?

    Cheers

    解决方案

    If this is about an HTML element, you will not be able to determine the width in PHP with 100% reliability. You would have to actually render the element in the client browser to find it out, and that is possible only using JavaScript.

    Plus there are many factors on client side that can play into the result:

    • The operating system's text size level
    • The browser's zoom level
    • The availability of the font used on the client machine

    You may be best off manually determining the element's width in an average web browser with normal zoom (or if it's dynamic text, maybe use what @Jared proposes)

    这篇关于PHP根据宽度确定字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆