简体   繁体   English

如何使 H1 标签响应?

[英]How can I make the H1 tag responsive?

Hello everyone my question is as follows.大家好我的问题如下。 How can I make the H1 tag responsive so that it doesnt shift boxes on my image.我怎样才能让 H1 标签响应,这样它就不会移动我图像上的框。 I am using bootstrap 4.5.2 for my project.我正在为我的项目使用 bootstrap 4.5.2。

Here is an image on the pc version这是电脑版的图片在此处输入图像描述

Here is an image on the mobile version (the H1 tag has shifted 1 box to the left)这是移动版的图片(H1 标签向左移动了 1 个框) 在此处输入图像描述

Here is my html code这是我的 html 代码

<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter">
    officeMap
</button>

<!-- Modal -->
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered modal-xl" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLongTitle">officeMap</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body" id="dynamic-content">
                <img src="PlanPage/Resources/grid.png" alt="officeMap" class="img-fluid">
                <div class="room1"><h1>1</h1></div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

Here is my css这是我的 css

body {
    background-image: url('Resources/blurred_desk1.jpg');
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
}

.room1 {
    position: absolute;
    bottom: 10%;
    left: 12%;
}

The image im using https://hbr.org/resources/images/article_assets/2013/04/grid.png我使用的图像https://hbr.org/resources/images/article_assets/2013/04/grid.png

You can not use percentage values and expect them to behave this way.您不能使用百分比值并期望它们以这种方式运行。

You can use flexbox and set fix size for image and shrink h1 to get remaining width with flex-shrink-1 .您可以使用flexbox并设置图像的固定大小并缩小h1以使用flex-shrink-1获得剩余宽度。

Something like this: Codepen像这样的东西: Codepen

在此处输入图像描述 在此处输入图像描述

I tried like this and it worked.我这样试过,它奏效了。

@media screen and (min-width: 1200px){
    .room1 {
        position: absolute;
        bottom: 10%;
        left: 12%;
    }
}
@media screen and (max-width: 1199px) and (min-width: 990px) {
    .room1 {
        position: absolute;
        bottom: 10%;
        left: 18%;
    }
}
@media screen and (max-width: 989px) {
    .room1 {
        position: absolute;
        bottom: 10%;
        left: 30%;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM