为什么在CSS中使用百分比值作为div的宽度? [英] Why use percentage value for div's width in CSS?

查看:69
本文介绍了为什么在CSS中使用百分比值作为div的宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读有关CSS的文章。我发现许多作家建议使用%值作为div的宽度或高度。

I am reading articles about css. I found out that many of writers suggest to use % value for div's width or height.

我一直都在使用像素。

为什么要使用div的宽度或高度的%值代替像素?

Why should I use % value for div's width or height instead of pixels?

优点是什么?

推荐答案

由于不一致,我个人不喜欢这样的网站,该网站的主要内容区域的宽度为%。最好在整个网站上使用大约1000像素的像素宽度,也许要少一些,以使其适用于所有分辨率。

I, personally, dislike websites which have a % width for the main content area because of the inconsistency. It's best to use a pixel width of about 1000 pixels, maybe a bit less, for the whole website so that it will work for all resolutions.

对于在主要内容区域,我倾向于使用百分比宽度,因为我真的不想同时计算精确的像素值。无论如何,结果都是固定不变的,因为它的百分比是恒定的,而不是显示器的分辨率,显示器的分辨率因用户而异。

As for elements inside the main content area, I tend to use percent widths because I don't really want to both with calculating the exact pixel values. The result is set in stone anyway because the thing that it's a percentage of is constant, as opposed to the monitor's resolution, which varies between users.

总结起来:由于父元素的宽度固定(像素),因此每个用户要获得相同结果时仅使用百分比。否则,您的设计会出现不一致的情况,以致于您无法使用任何浮华的图像,而且对于使用大/小显示器的用户,该网站可能看起来很丑陋。如果您要使用百分比宽度,则只需测试具有不同分辨率的网站!

To sum it up: only use percentages when every user is going to get the same result because of a parent element having a fixed (pixel) width. Otherwise there will be inconsistencies in your design, making it so that you can't use any flashy images and the website may look ugly to users with giant / tiny monitors. If you are going to use percentage widths you simply have to test the website with different resolutions!

这篇关于为什么在CSS中使用百分比值作为div的宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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