我应该使用 % 还是 'px'在 HTML 中
无论是 HTML、XHTML 还是 HTML5,您都会发现到处都是令人讨厌的百分比。然而……我看到很多网站都不敢靠近它们。然而大学总是鼓励我使用它们。
那么我应该使用哪个?哪一个会带来更好的网站设计,为什么?
我知道要避免使用高度,尽管如果我想使用百分比,HTML5 确实不喜欢我不指定高度。
感谢您抽出时间阅读。
Regardless of whether it is HTML, XHTML or HTML5 you find those annoying percentages littered throughout the place. Yet... I see an awful lot of websites dare not go near them. Yet I was always encouraged through uni to use them.
So which should I be using? Which would lead to better site design and why?
I'm aware to avoid the use of height although HTML5 really doesn't like me not specifying height if I want to use percentages.
Thanks for taking the time to read.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这实际上取决于您想要构建什么。
有时我需要建立一个可供有某些残障人士阅读的网站。例如,如果老年人也访问您的网站,那么使用 % 是很好的选择,这样他们就可以放大您的页面,并且布局仍然看起来很漂亮。
It really depends on what you do you want to build up.
Sometimes I need to build a website which could be read by people with certain disabilities. If for example also older people visit your site its good to use % so that they could zoom in your page and the layout still looks pretty.
对于字体,如果您不希望修复 Internet Explorer 中的字体大小,则应使用百分比(或 em、rems)。如果您使用像素,则在浏览器设置中更改默认字体大小的 Internet Explorer 用户将不会看到字体增大/减小。因此,这可能会使该浏览器中的用户难以阅读您的文本。
Dan Cederholm 的Bulletproof Web Design 的第一章是一个很好的资源。
对于布局,使用百分比或 em 将使您的设计更灵活地更改字体大小/本地化等。本书也对此进行了介绍。
For fonts, you should use percentages (or em's, or rems) if you don't wish to fix the font size in Internet Explorer. If you use pixels, then users of Internet Explorer who change their default font size in their browser settings won't see the fonts increase/decrease. So this makes your text potentially less readable for users in that browser.
A great resource for this is the first chapter of Dan Cederholm's Bulletproof Web Design.
For layout, using percentages or em's will make your design more flexible to changing font sizes/localization etc. This is also covered in the book.