【问题标题】:CSS not displying as expectedCSS 未按预期显示
【发布时间】:2016-08-04 15:48:36
【问题描述】:

我一直在建立一个网站,一切都按预期运行,直到我突然无法在同一行显示任何内容,即使之前在该网站上运行过类似的代码。即使是相同的图像和 div CSS,该站点也会以不同的方式显示图像。我正在使用 HTML 和 CSS 在 Drupal 上进行构建。我的 HTML 代码是

<div class="foodblock col-m-3 col-3"><a href="kale-grain-bowls/spicy-avocado-lime"><div class="spicy-avocado-lime">SPICY AVOCADO & LIME</div></a>
<div class="textblock"></div></div>
<div class="foodblock col-m-3 col-3"><a href="kale-grain-bowls/toasted-almond-ginger"><div class ="toasted-almond-ginger">TOASTED ALMOND & GINGER</div></a>
<div class="textblock"></div></div>
<div class="foodblock col-m-3 col-3"><a href="kale-grain-bowls/local-apple-bacon"><div class="local-apple-bacon-bowl">LOCAL APPLE & BACON BOWL</div></a>
<div class="textblock"></div></div>
<div class="foodblock col-m-3 col-3"><a href="kale-grain-bowls/power-bowl"><div class="power-bowl">POWER BOWL</div></a><div class="textblock"></div></div>

我的css是:

.foodblock{
    float: left;
    clear: both;
    margin: 15px;
    height: 300px;
}
.textblock{
    float: left;
}
.spicy-avocado-lime{
    height: 200px;
    background-image: url('../images-source/communitybottom.png');
    float: left;
}
.toasted-almond-ginger{
    height: 200px;
    background-image: url('../images-source/communitybottom.png');
    float: left;
}
.local-apple-bacon-bowl{
    height: 200px;
    background-image: url('../images-source/communitybottom.png');
    float: left;
}
.power-bowl{
    height: 200px;
    background-image: url('../images-source/communitybottom.png');
    float: left;
}/*for mobile phones: */
    [class*="col-"]{
        width:100%;
    }

@media only screen and (min-width: 600px) {
    /* For tablets: */
    .col-m-1 {width: 8%;}
    .col-m-2 {width: 16%;}
    .col-m-2-5 {width: 21.55%;}
    .col-m-3 {width: 24%;}
    .col-m-4 {width: 32.5%;}
    .col-m-5 {width: 40%;}
    .col-m-6 {width: 48%;}
    .col-m-7 {width: 56%;}
    .col-m-8 {width: 65.7%;}
    .col-m-9 {width: 72%;}
    .col-m-10 {width: 80%;}
    .col-m-11 {width: 88%;}
    .col-m-12 {width: 96%;}
}
@media only screen and (min-width: 768px){
    /*for mobile desktop: */
    .col-1 {width: 8%;}
    .col-2-5 {width: 21.55%;}
    .col-2 {width: 16%;}
    .col-3 {width: 24%;}
    .col-4 {width: 32.5%;}
    .col-5 {width: 40%;}
    .col-6 {width: 48%;}
    .col-7 {width: 56%;}
    .col-8 {width: 65.7%;}
    .col-9 {width: 72%;}
    .col-10 {width: 80%;}
    .col-11 {width: 88%;}
    .col-12 {width: 96%;}
}

【问题讨论】:

    标签: html css drupal


    【解决方案1】:

    删除 clear:both;来自 CSS 中 .foodblock 选择器的属性。这将显示您的 cols 内联。

    【讨论】:

    • 谢谢,我以为我已经尝试删除它,但显​​然没有。如果它不显示内联,这解决了问题。 power-bowl div 图像显示小于所有其他图像的问题仍然存在。
    • 您的所有代码看起来都有效,并且包括 power-bowl 在内的所有 div 都是相同的。我想你已经知道了,如果你设置更小的宽度,比如你的 col div 的 20%,它们将是内联的。现在,我没有指向您的图像的完整链接,所以我看不出您是否需要将图像保存为相同大小。 power-bowl div 只是显得更小,因为里面有两个词,而其他 div 有更多。 Power-bowl div、local-bacon-apple 等 div 将继承 col div 的大小。
    • 由于您修复了清除清除,我的图像是内联的。 div 肯定更小。所有的图像都是相同的,所以它们应该是相同的大小。我包含指向我的网站图像的链接。 imgur.com/KSlPTEF。字数应该不会影响这一点,因为 col div 的宽度设置为 no?
    • 啊,对。将 power-bowl、local-bacon 和其他两个 div 的宽度设置为 100%。这样就可以了。
    • 谢谢,我今天刚刚能够测试它,它似乎已经工作了谢谢。
    猜你喜欢
    • 2015-11-19
    • 2023-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多