【发布时间】:2018-03-20 06:38:21
【问题描述】:
我在单个类中使用多个引导列。现在,当标题使用clear:both 时,我实现了列换行。但是当项目没有标题时,移动视图中唯一的问题是无法将列左对齐。这是我的示例代码,我还附上了屏幕供您参考。
<div class="itemat htile1 col-xs-12">
<div class="secn-frst1">
<h4 class="tileh4 a">600mm x 600mm</h4>
<div class="col-sm-3 col-xs-6 applyclear">
<p>content</p>
</div>
<div class="col-sm-3 col-xs-6 applyclear">
<p>content</p>
</div>
<div class="col-sm-3 col-xs-6 applyclear">
<p>content</p>
</div>
<div class="col-sm-3 col-xs-6 applyclear">
<p>content</p>
</div>
<div class="col-sm-3 col-xs-6 applyclear">
<p>content</p>
</div>
<div class="col-sm-3 col-xs-6 applyclear">
<p>content</p>
</div>
</div>
下面写jquery
$(window).on('load resize', function() {
if ($(window).width() <= 767) {
//alert();
$(".posts.Homogeneous div[class*='htile'] .col-sm-3 .tileh4:has(.versn)").parent().css("clear", "both");
$(".posts.Porcelain div[class*='htile'] .col-sm-3 .tileh4:has(.versn)").parent().css("clear", "both");
$(".posts.Ceramic div[class*='htile'] .col-sm-3 .tileh4:has(.versn)").parent().css("clear", "both");
$(".posts.Homogeneous .htile1 div[class*='secn-frst'] .col-sm-3 .tileh4:has(.versn)").parent().css("clear", "both");
$(".posts.Porcelain .htile1 div[class*='secn-frst'] .col-sm-3 .tileh4:has(.versn)").parent().css("clear", "both");
$(".posts.Ceramic .htile1 div[class*='secn-frst'] .col-sm-3 .tileh4:has(.versn)").parent().css("clear", "both");
//div has no title cleat none
$(".posts.Homogeneous div[class*='htile'] .col-sm-3 .tileh4:has(.vhide)").parent().css("clear", "none");
$(".posts.Porcelain div[class*='htile'] .col-sm-3 .tileh4:has(.vhide)").parent().css("clear", "none");
$(".posts.Ceramic div[class*='htile'] .col-sm-3 .tileh4:has(.vhide)").parent().css("clear", "none");
} else {
$(".posts.Homogeneous div[class*='htile'] .col-sm-3 .tileh4:has(.versn),.posts.Homogeneous div[class*='htile'] .col-sm-3 .tileh4:has(.vhide)").parent().css("clear", "none");
$(".posts.Porcelain div[class*='htile'] .col-sm-3 .tileh4:has(.versn),.posts.Porcelain div[class*='htile'] .col-sm-3 .tileh4:has(.vhide)").parent().css("clear", "none");
$(".posts.Ceramic div[class*='htile'] .col-sm-3 .tileh4:has(.versn),.posts.Ceramic div[class*='htile'] .col-sm-3 .tileh4:has(.vhide)").parent().css("clear", "none");
$(".posts.Homogeneous .htile1 div[class*='secn-frst'] .col-sm-3 .tileh4:has(.versn),.posts.Homogeneous .htile1 div[class*='secn-frst'] .col-sm-3 .tileh4:has(.vhide)").parent().css("clear", "none");
$(".posts.Porcelain .htile1 div[class*='secn-frst'] .col-sm-3 .tileh4:has(.versn),.posts.Porcelain .htile1 div[class*='secn-frst'] .col-sm-3 .tileh4:has(.vhide)").parent().css("clear", "none");
$(".posts.Ceramic .htile1 div[class*='secn-frst'] .col-sm-3 .tileh4:has(.versn),.posts.Ceramic .htile1 div[class*='secn-frst'] .col-sm-3 .tileh4:has(.vhide)").parent().css("clear", "none");
}
});
//remove classname row in mobile
$(window).on('load resize', function() {
if ($(window).width() <= 767) {
var cnt = $(".posts.Homogeneous .htile1 .row").contents();
$(".posts.Homogeneous .htile1 .row").replaceWith(cnt);
}
});
【问题讨论】:
-
你需要修改内联样式 clear : both in width
-
没有沙文。使用上述 jquery 应用的内联样式。 div 使用 php 代码重复。
-
好的。我认为你可以修改它。否则使用这个。 // 返回浏览器视口的宽度 $( window ).width(); // 返回 HTML 文档的宽度 $( document ).width();
-
获取宽度并为该特定宽度添加一些jquery
-
听不懂你在说什么。你不明白我的问题检查截图。并尽可能写出答案。
标签: php jquery html css twitter-bootstrap