【发布时间】:2019-05-07 11:00:06
【问题描述】:
我在我的 HTML 页面上显示产品。有些产品有大细节,有些产品有小细节。当我展示这些产品时,具有大细节的产品div 比具有小细节的产品具有更高的高度。为了解决这个问题,我为div 分配了高度,但它不起作用,因为当我在移动设备中打开我的页面时,产品的详细信息会从其div 溢出。然后我尝试使用媒体查询更改div 的类:如果宽度col-md-6 更改为col-md-12。我使用jquery 进行了此更改,但它只影响第一个div。
这个问题的标准解决方案是什么?。
$(window).resize(function() {
if ($(window).width() < 991) {
alert("window");
$( "product612" ).removeClass( "col-md-6" ).addClass( "col-md-12" );
$("product612").toggleClass('col-md-6 col-md-12');
}
});
.product{
background-color: rgba(92, 90, 90, 0.096);
word-wrap:break-word;
position: relative;
text-align: center;
padding: 40px 20px;
margin: 15px 0px;
height: 433.4px !important;
}
.product:after {
content: "";
background-color: rgba(2, 2, 2, 0.781);
position: absolute;
left: 0;
top: 0;
bottom: 0;
width: 0%;
z-index: -1;
-webkit-transition: 0.2s width;
transition: 0.2s width;
}
.product:hover p{
color: white !important;
}
.product:hover:after
{
width: 100%;
height: auto;
}
.product p{
color: rgb(80, 80, 80) !important;
font-size: 17px;
line-height: 18px;
font-weight: 500;
font-family: Avant Garde, Avantgarde, Century Gothic, CenturyGothic, AppleGothic, sans-serif;
}
.product>img {
height: 150px;
width: 250px;
margin: 0px auto 12px auto;
margin-left: auto;
border-radius: 15%;
}
<div class="container" >
<div class="row">
<div class="section-header text-center" >
<h1 class="glow title">Products</h1>
</div>
{% for product in products %}
<div id="product612" class="col-md-6 col-sm-12 col-xs-12">
<div class="product">
<img src="{{product.image.url}}" class="img-responsive " alt="product picture">
<h4>{{product.name}}</h4>
<p>{{product.detail}}</p><br>
</div>
</div>
{% endfor %}
</div>
</div>
【问题讨论】:
-
使用
vw而不是px -
当您使用
bootstrap时,您不应该以必须更改col-的方式构建您的页面,因为已经使用col-mdcol-sm等构建了引导程序。 . 你应该只允许在移动设备上改变高度 -
你当然不应该用 JavaScript 做这个。
-
@DanielRoseman 我该怎么做?
-
getbootstrap.com/docs/4.0/layout/grid 请阅读文档 - 它充分解释了如何为不同的屏幕宽度设置不同的列大小
标签: javascript jquery html css django