0

ウェブサイトに div があり、margin-top プロパティを使用して CSS にこの div を配置しようとしています。

私は現在使用しています:

margin-top: -0.5px;

これを行うと、div がわずかに低くなりますが、margin-top: -0.6px; を行うと、それは高すぎるので、0.5 から 0.6 の間の値を見つけようとしています。

次のような小数点以下2桁の値を使用できる方法はありますか:

 margin-top: -0.5.5px; 

これについて何か助けていただければ幸いです、ありがとう?

4

1 に答える 1

0

The short answer is that fractional css pixel ratios are either rounded or truncated.

Conisder the following:

div.someclass {margin-top: 0.55px;}

and percentages

div.someclass {margin-top: 35.55%;}

These values get rounded to the nearest percent by most browsers, and truncated by others. Meaning the above 2 examples will be interpreted either as 0.6px / 0.5px and 35.6% / 35.5% depending on the user's browser.

For more information about fractional css values check out this stackoverflow thread: Are the decimal places in a CSS width respected?

How do we fix this? Unfortunately, you can't really but you could try to offset margin fractions by adding some inner padding with a fraction that offsets the margin.

Example:

div.outer {margin-top: 0.5px;}
div.inner {padding-top: 0.1px;}

This should definitely result in the same output as margin-top: 0.6px but depending on the particulars of your overall css theme you may notice subtle differences.

于 2013-03-26T22:03:23.433 に答える