如何在CSS中设置min-font-size [英] How to set min-font-size in CSS
问题描述
我想为HTML页面中的每个元素设置最小字体大小。
I want to set a minimum font size to every element in my HTML page.
例如,如果有字体大小小于12px的元素,将改为12px。
但是如果有字体大小为12px的元素,则它们不会改变。
For example if there are elements with font-size less then 12px, then they will change to 12px.
But if there are elements with font-size grater then 12px, they will not change.
有任何方法使用CSS?
Is there any way to do it with CSS?
推荐答案
否。虽然您可以使用 font-size
属性在 body
上设置基本字体大小, size将覆盖该元素的基本规则。为了做你正在寻找的,你将需要使用Javascript。
No. While you can set a base font size on body
using the font-size
property, anything after that that specifies a smaller size will override the base rule for that element. In order to do what you are looking to do you will need to use Javascript.
您可以遍历页面上的元素,并使用类似的东西更改较小的字体:
You could iterate through the elements on the page and change the smaller fonts using something like this:
$("*").each( function () {
var $this = $(this);
if (parseInt($this.css("fontSize")) < 12) {
$this.css({ "font-size": "12px" });
}
});
这里是一个小提琴,你可以看到它: http://jsfiddle.net/mifi79/LfdL8/2/
Here is a Fiddle where you can see it done: http://jsfiddle.net/mifi79/LfdL8/2/
这篇关于如何在CSS中设置min-font-size的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!