HTML 字体大小未按预期工作?

问题描述 投票:0回答:1

我当前的 HTML 标签字体大小为 16px。每当我尝试使用检查工具减小屏幕宽度时。它变得太小了。我尝试了下面的脚本。即使 Chrome 的屏幕宽度正在减小,它仍然会记录 980 和 981,除非 chrome 上的宽度低于 242。

function adjustFontSize() {
    console.log(window.innerWidth);
    var fontSize = window.innerWidth < 980 ? 26 : 16;
    document.documentElement.style.fontSize = fontSize + "px";
}
adjustFontSize();
window.addEventListener("resize", adjustFontSize);

我什至尝试使用@media来使用CSS,但似乎没有任何效果。我不知道为什么。

@media screen and (max-width: 768px)

屏幕尺寸太小,在手机屏幕上。

完整代码,如果有帮助的话

<div class="container-fluid p-4 vh-100">
        <div class="d-flex justify-content-around column-gap-3 h-100">
            {% comment %} Left Wrapper {% endcomment %}
            <div class="d-flex flex-column justify-content-between align-items-center flex-grow-1">
                {% comment %} Back Button {% endcomment %}
                <a href="" class="align-self-baseline btn btn-outline-primary rounded-4 d-flex align-items-center py-2 fs-6 fw-semibold"><span class="material-symbols-outlined fs-5 pe-2">arrow_back</span>Back to home page</a>
                {% comment %} Login Wrapper {% endcomment %}
                <form action="" class="m-0 d-flex flex-column align-items-center" method="post">
                    <span class="d-block d-lg-none fs-1 fw-medium">Welcome to Your <br> SETC <span class="text-gradient">Client Portal</span></span>
                    <div class="d-none d-lg-flex flex-column align-items-center wrapper-1">
                        <span class="fs-1 fw-medium">Welcome to IRSplus</span>
                        <span class="fs-1 fw-medium text-gradient">Client Portal</span>
                    </div>
                    <div class="d-flex flex-column align-items-center row-gap-3">
                        <div class="d-flex flex-column mt-5">
                            <div class="form-floating mb-3">
                                <input type="email" class="form-control rounded-4" id="floatingInput" placeholder="[email protected]">
                                <label for="floatingInput">Email*</label>
                            </div>
                            <div class="form-floating">
                            <input type="password" class="form-control rounded-4" id="floatingPassword" placeholder="Password">
                            <label for="floatingPassword">Enter Password</label>
                            </div>
                            <div class="d-flex mt-3 justify-content-between column-gap-5">
                            <div class="irs-checkbox">
                                <input class="inp-cbx" id="cbx-46" type="checkbox" />
                                <label class="cbx" for="cbx-46"><span>
                                    <svg width="12px" height="10px" viewbox="0 0 12 10">
                                    <polyline points="1.5 6 4.5 9 10.5 1"></polyline>
                                    </svg></span><span class="fw-medium">Remember me</span>
                                </label>
                            </div>
                            <a href="" class="text-decoration-none">Forgot Password?</a>
                            </div>
                        </div>
                        <div class="d-flex flex-column mt-5 align-items-center">
                            <button type="submit" class="btn btn-primary rounded-4 d-flex align-items-center justify-content-center py-3 w-50">Login <span class="material-symbols-outlined fs-5 ps-1">arrow_outward</span></button> 
                            <span class="fs-6 mt-3">Don't have an account yet?</span>
                            <a href="" class="text-decoration-none">Register new Account</a>
                        </div>
                    </div>
                </form>
                {% comment %} Footer {% endcomment %}
                <div class="d-none d-xxl-flex w-100 justify-content-between align-items-center">
                    <span class="fs-6 text-body-secondary fw-light text-break w-50" style="white-space:pre"> 
FYI - The Portal is designed for desktop &
table users only. Mobile app coming soon.
                    </span>
                    <span class="fs-6 text-end" style="white-space:pre">
Need help? Call support at <span class="fw-semibold">(</span> 
or email at <a href="" class="text-decoration-none"></a>
                    </span>
                </div>
                <div class="d-flex d-xxl-none flex-column justify-content-between align-items-center">
                    <span class="text-center border-bottom border-2 pb-2 mb-2">Need help? Call support at <span class="fw-semibold">(312)312-3119</span>  <br> or email at <a href="mailto:support@irsplus" class="text-decoration-none">[email protected]</a></span>
                    <span class="fs-6 text-body-secondary fw-light w-75 text-center">FYI - The Portal is designed for desktop & table users only. Mobile app coming soon.</span>
                </div>
            </div>
            {% comment %} Right Wrapper {% endcomment %}
            <div class="d-none d-sm-none d-md-none d-lg-flex w-50 position-relative" >
                <div class="w-100 h-100 position-absolute rounded-5" style="background-image:linear-gradient(190.06deg, rgba(57, 108, 240, 0.2) 6.22%, rgba(57, 108, 240, 0) 52.87%), linear-gradient(16.9deg, rgba(57, 108, 240, 0.4) 16.97%, rgba(57, 108, 240, 0) 51.41%);"></div>
                <img src="{% static 'images/new-design/signup/login-image.png' %}"  class="rounded-5 img-fluid object-fit-cover" alt="" srcset="">
            </div>
        </div>
    </div>
html css responsive-design font-size
1个回答
0
投票

原来我忘记了这个标签

<meta name="viewport" content="width=device-width, initial-scale=1" /> 

感谢@A Haworth

© www.soinside.com 2019 - 2024. All rights reserved.