【问题标题】:Smaller resolution makes images tiny (bootstrap-5 Fluid)较小的分辨率使图像变小(bootstrap-5 Fluid)
【发布时间】:2021-05-20 18:56:05
【问题描述】:

目前正在发生的事情: 当使用 Chrome 浏览器设备工具栏工具以不同的分辨率测试我的网站时,我注意到当我将设备屏幕缩小到“Mobile-s”320 像素时,我页面上的内容变得几乎无法阅读。这也导致图像非常小,更不用说分解到单个字母堆叠在一起的句子了。

我希望发生的事情:我希望卡片中的内容随着屏幕分辨率的降低而缩小,但也变得可读并且图像保持足够大以便被看到。

我在项目中使用的内容:

  1. html
  2. CSS
  3. Booststrap 5

这是我的博客部分的 html:

您可以看到我在最外层的 div 中使用了 container-fluid

   <h2 class="display-6 mb-5">My blog:</h2>
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-4 ">
                        <div class="card " >
                            <img src="img/1.jpg" class="card-img-top " alt="...">
                            <div class="card-body ">
                                <h5 class="card-title">Card title</h5>
                                <p class="card-text">Some quick example text to build on the card 
                                   title and make up the bulk of the card's content.</p>
                                <a href="#" class="btn btn-primary">Go somewhere</a>
                            </div>
                        </div>
                    </div>

这是我的图片部分的 html:

你可以看到我也在最外面的 div 中使用 container-fluid

 <h2 class="display-6">My projects:</h2>
            <div class="container-fluid">
                <div class="row gy-5"> <!--gy-5 will provide spacing between each image -->
                    <div class="col-md-6"><img src="img/1.jpg" alt="Portfolio image" class="img-fluid thumbnail">
                    </div>
                    <div class="col-md-6"><img src="img/1.jpg" alt="Portfolio image" class="img-fluid thumbnail">
                    </div>
                    <div class="col-md-6"><img src="img/1.jpg" alt="Portfolio image" class="img-fluid thumbnail">
                    </div>
                    <div class="col-md-6"><img src="img/1.jpg" alt="Portfolio image" class="img-fluid thumbnail">
                    </div>
                    <div class="col-md-6"><img src="img/1.jpg" alt="Portfolio image" class="img-fluid thumbnail">
                    </div>
                    <div class="col-md-6"><img src="img/1.jpg" alt="Portfolio image" class="img-fluid thumbnail">
                    </div>

                </div>
            </div>

这是我的 CSS 中包含的内容:

    body, html{
    height: 100%;

}

body{
    font-weight: 200;
    font-size: 1.5rem;
    color: #444;
}

.intro-left{
    background: url("../img/1.jpg");/*concrete background*/
    position: fixed;
    left: 0;
    width: 33.3333%;
    height: 100%;
    color: white;

}

@media(max-width: 768px) { /*@media rule will add the code inside only if the max-width is 768px */
    .intro-left{
        height: 80vh;
        margin-bottom: 0;
        position: relative;
        width: 100%;
    }

}

.avatar{
    width: 10rem;
    height: 7em;
    border-radius: 50%;
    margin: 1rem;
}

.full-height {
    height: 100%;
}

.quote{
    float: right;
}

section{
    margin: 5rem;
    font-size: 1.2rem;
}

a{
    color: #444;
    text-decoration: none;
}

卡片目前在 320 像素上的显示效果

图像当前在 320 像素上的外观

卡片应该在 320 像素上的外观

图像应该在 320 像素上的显示效果

【问题讨论】:

    标签: html css bootstrap-4 bootstrap-5


    【解决方案1】:

    您在 col-md-6 中定义了图像的 DIV 的大小,您必须定义不同大小的类。

    例如:

    <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-3 col-xxl-3">
        <img src="img/1.jpg" alt="Portfolio image" class="img-fluid thumbnail">
    </div>
    

    我建议学习引导网格系统文档https://getbootstrap.com/docs/5.0/layout/grid/#grid-options

    【讨论】:

    • 你能把整个代码放在 jsfiddle 中以便能够有更多的细节吗?
    【解决方案2】:

    减少节边距会增加元素的大小。这是因为应用于 section 类的边距会导致整个元素周围出现间隙。与最初的问题产生的差距是 5rem。随着分辨率的降低,由边距产生的间隙保持其 5rem,因此当屏幕结果降低时,使用 section 类的元素变得更小。一旦这个边距减少到 0.1rem,它就会减少所有边的间隙,这会导致元素在分辨率降低时变得更大/可读。

    从这里:

    section{
       margin: 5rem; 
       font-size: 1.2rem;
     }
    

    到这里:

    section{
       margin: 0.1rem; 
       font-size: 1.2rem;
     }
    

    【讨论】:

    • 请解释其工作原理和原因,并提供示例代码。作为一个问答网站,这将有助于未来的用户了解您的解决方案并自行实施。
    猜你喜欢
    • 2016-03-13
    • 2018-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多