html - 使用引导类在具有不同断点的同一行上设置图像和文本的顺序
问题描述
我在同一行中有一个图像和文本,图像在前,文本在其左侧。我想要做的是当屏幕缩小到小断点并且调整图像大小时返回到左侧时,使文本显示在图像上方。我在文本标签下方有图像标签。这是我的代码。
<div class="container-fluid">
<div class="row">
<div class="col-md-10 order-2 col-sm-10 order-1 flex-column">
<h2>Alignment</h2>
<p> Alignment helps organize and order the content, controlling how the eye flows from one
component to the next. It is the organization and creation of invisible lines. Without
alignment, users will have a hard time recognizing how elements relate to eachother, and
your page will look messy and disorganized.</p>
</div>
<div class="col-md-2 order-1 col-sm-2 order-2 flex-column">
<img src="carp4.jpg" class="">
</div>
</div>
</div>
解决方案
您不需要将顺序从 1 反转到 2,因为两个断点以相同的顺序反转。如果需要,请在断点上切换它,例如order-1 order-sm-2
.
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid">
<div class="row">
<div class="col-sm-10 order-2">
<h2>Alignment</h2>
<p>Alignment helps organize and order the content, controlling how the eye flows from one component to the next. It is the organization and creation of invisible lines. Without alignment, users will have a hard time recognizing how elements relate to eachother, and your page will look messy and disorganized.</p>
</div>
<div class="col-sm-2 order-1">
<img src="https://picsum.photos/100/100" alt="" class="img-fluid w-100" />
</div>
</div>
</div>
您还可以flex-column-reverse
用于超小屏幕和flex-sm-row-reverse
小屏幕及以上。这样你就可以避免使用order-*
. order-*
在超过 2 列的情况下很方便。
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid">
<div class="row flex-column-reverse flex-sm-row-reverse">
<div class="col-sm-10">
<h2>Alignment</h2>
<p>Alignment helps organize and order the content, controlling how the eye flows from one component to the next. It is the organization and creation of invisible lines. Without alignment, users will have a hard time recognizing how elements relate to eachother, and your page will look messy and disorganized.</p>
</div>
<div class="col-sm-2">
<img src="https://picsum.photos/100/100" alt="" class="img-fluid w-100" />
</div>
</div>
</div>
但是,如果您可以切换图像和文本列,这似乎过于复杂。
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid">
<div class="row">
<div class="col-sm-2">
<img src="https://picsum.photos/150/100" alt="" class="img-fluid w-100" />
</div>
<div class="col-sm-10">
<h2>Alignment</h2>
<p>Alignment helps organize and order the content, controlling how the eye flows from one component to the next. It is the organization and creation of invisible lines. Without alignment, users will have a hard time recognizing how elements relate to eachother, and your page will look messy and disorganized.</p>
</div>
</div>
</div>
这是一个jsfiddle来调整结果大小并进行播放。
推荐阅读
- google-apps-script - 如何在网站管理员中验证 Google Apps 脚本的所有权
- google-sheets - 如何在 SUMIFS 中使用基于一组数字的标准?
- javascript - 使用动态键访问 Javascript 对象值
- vue.js - 在vue js中以反应方式从父组件重置子组件数据属性值
- html - HTML+CSS-顶部导航栏和2张图片之间的文字
- laravel - 类 Illuminate\Support\Facades\RateLimiter 未找到
- macports - 使 MacPorts 打印校验和的命令是什么
- javascript - React-Leaflet:添加 L.TileLayer 打破地图
- css - Font Awesome 5 适用于 Chrome 但不适用于 Safari
- php - php 如果雄蕊导致页面显示为空白