gpt4 book ai didi

javascript - 通过更改浏览器宽度,根据其原始值更改字体大小

转载 作者:行者123 更新时间:2023-11-28 09:42:58 25 4
gpt4 key购买 nike

当浏览器大小(宽度)介于两个特定数字之间时,如何使用 jQuery、JS、CSS 以及按百分比更改字体大小值所需的一切。

例如

<div class="Fsize">Sample text<div>

<style>
//a sample size, lets say it can be anything
font-size: 100px;
</style>


<script>
//what should be here to change font-size to for example 30% of its original value (100px), which is 30px. when browser size (width) is between 700px to 1000px.
</script>

我不能使用 Media 媒体查询。下面是我使用它的示例。CSS 中的百分比根据 body {font-size} 而不是其原始值(此处为 250)更改字体大小。

<div class="font">Some Text</div>

<style>
.font {
font-size: 250px;
}


@media (max-width: 600px) {
.font {
font-size: 100%;
}
}
</style>

最佳答案

font-size 属性是相对于父元素的字体大小

http://www.w3.org/TR/css3-fonts/#font-size-prop

这意味着如果您想使用媒体查询通过百分比更改字体大小,您需要先为容器设置相对字体大小。

.container{
font-size:40px;
}

.font{
font-size: 100%;
}

@media (min-width: 400px) and (max-width: 800px){
.font {
font-size: 200%;

}
}

http://jsbin.com/bisirojoquxa/1/

您可以使用容器,或在 body 元素中设置字体大小,然后从那里缩放。我建议使用基于 Sass 的响应式字体大小解决方案,例如以下内容:

https://github.com/dmtintner/UtilityBelt

关于javascript - 通过更改浏览器宽度,根据其原始值更改字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25347937/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com