admin管理员组文章数量:1293365
I am trying to create a list of images and each occupies 4 columns in medium and larger screens and occupies 12 columns on smaller screens.
However, when I try to resize the screen to smaller size (using toggle device toolbar) the images still occupies the same col as the medium screen.
mobile-view
According to the documentation:
Breaking columns to a new line in flexbox requires a small hack: add an element with width: 100% wherever you want to wrap your columns to a new line.
Ref: .3/layout/columns/#column-breaks
I also tried the following but not working.
w-100 d-block d-sm-block d-md-none
col-12 d-block d-md-none
When I change the d-md-none
to d-lg-none
, it works but I want to hide it starting from medium screen.
Ref: .3/utilities/display/#hiding-elements
I am doing something wrong here?
<link rel="stylesheet" href="/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<div class="container">
<div class="row mt-1">
<div class="col-12 col-md-4">
<div class="listing-item">
<img class="img-fluid img-thumbnail" src="">
</div>
</div>
<!-- show in smaller screen and hide on medium and larger -->
<div class="w-100 d-block d-md-none"></div>
<div class="col-12 col-md-4">
<div class="listing-item">
<img class="img-fluid img-thumbnail" src="">
</div>
</div>
<!-- show in smaller screen and hide on medium and larger -->
<div class="w-100 d-block d-md-none"></div>
<div class="col-12 col-md-4">
<div class="listing-item">
<img class="img-fluid img-thumbnail" src="">
</div>
</div>
</div>
</div>
I am trying to create a list of images and each occupies 4 columns in medium and larger screens and occupies 12 columns on smaller screens.
However, when I try to resize the screen to smaller size (using toggle device toolbar) the images still occupies the same col as the medium screen.
mobile-view
According to the documentation:
Breaking columns to a new line in flexbox requires a small hack: add an element with width: 100% wherever you want to wrap your columns to a new line.
Ref: https://getbootstrap/docs/5.3/layout/columns/#column-breaks
I also tried the following but not working.
w-100 d-block d-sm-block d-md-none
col-12 d-block d-md-none
When I change the d-md-none
to d-lg-none
, it works but I want to hide it starting from medium screen.
Ref: https://getbootstrap/docs/5.3/utilities/display/#hiding-elements
I am doing something wrong here?
<link rel="stylesheet" href="https://cdn.jsdelivr/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<div class="container">
<div class="row mt-1">
<div class="col-12 col-md-4">
<div class="listing-item">
<img class="img-fluid img-thumbnail" src="https://placehold.co/600x400">
</div>
</div>
<!-- show in smaller screen and hide on medium and larger -->
<div class="w-100 d-block d-md-none"></div>
<div class="col-12 col-md-4">
<div class="listing-item">
<img class="img-fluid img-thumbnail" src="https://placehold.co/600x400">
</div>
</div>
<!-- show in smaller screen and hide on medium and larger -->
<div class="w-100 d-block d-md-none"></div>
<div class="col-12 col-md-4">
<div class="listing-item">
<img class="img-fluid img-thumbnail" src="https://placehold.co/600x400">
</div>
</div>
</div>
</div>
Share
Improve this question
edited Feb 13 at 13:33
isherwood
61.1k16 gold badges120 silver badges169 bronze badges
asked Feb 12 at 17:42
JayJay
12 bronze badges
4
|
2 Answers
Reset to default 0You should try this: d-none d-sm-block
Yours might be not working because of overriding, as you mentioned the same thing multiple times.
I found that adding this tag <meta name="viewport" content="width=device-width, initial-scale=1">
tells the browser how to scale and display the page on different screen sizes - now the issue is resolved.
Ref: https://developer.mozilla./en-US/docs/Web/HTML/Viewport_meta_tag
本文标签:
版权声明:本文标题:html - Bootstrap 5.3.x: Why does "w-100 d-block d-md-none" not work when I try to break a column to a new line 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741578337a2386422.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
w-100 d-md-none
which should show by default until the md breakpoint and above. Though, I think what you have should work... – Daniel Black Commented Feb 12 at 18:03