【问题标题】:Div's refuse to be vertically stacked close to each otherDiv 拒绝垂直堆叠彼此靠近
【发布时间】:2016-08-10 21:27:29
【问题描述】:

我的 CSS 和 HTML 有问题,我认为找不到解决方法。我试图在页面顶部设置一组 6 个 div,其中包含一个仅包含文本的 div,其下方有一组 3 个 div 宽,每个都包含文本和图像。当前发生的情况是顶部的 6 个块正确显示在顶部,然后有一个大的空白区域,下面有 3 个 div 集。应该在它们之间的文本根本不显示。我的 HTML 代码是:

<div class="page">
<a href="/menu/kale-grain-bowls"><div class="col-m-2 col-2 kale-grain-bowls">Kale & Grain Bowls</div></a>
<a href="/menu/salads"><div class="col-m-2 col-2 salads">Salads</div></a>
<a href="/menu/burgers-sandwiches"><div class="col-m-2 col-2 burgers-sandwiches">Burgers & Sandwiches</div></a>
<a href="/menu/sides"><div class="col-m-2 col-2 sides">Sides</div></a>
<a href="/menu/smoothies-shakes"><div class="col-m-2 col-2 smoothies-milkshake">Smoothies & Milkshakes</div></a>
<a href="/menu/kids-real-meals"><div class="col-m-2 col-2 kids-real-meals">Kid's Real Meals</div></a>
<div class="menu-type>Kale & Grain Bowls</div>
<div class="foodcontent">
<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">kale, sautéed veggies, avocado, black beans, corn, grape tomato, queso fresco, lime, cilantro, chipotle puree, red pepper vinaigrette</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">kale, sautéed veggies, bok choy, tamari almonds, red cabbage, enoki mushrooms, mint, toasted almond-ginger sauce</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">kale, avocado, NH slab bacon, local apples, cherries, dried cranberries, sunflower seeds, scallions, red wine vinegar, olive oil</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">kale, sesame carrots, Brussels sprouts, crunchy chickpeas, pepitas, local egg, tomato vinaigrette</div></div>
<div class="foodblock col-m-3 col-3"><a href="kale-grain-bowls/farmstand-  tomato-basil"><div class="farmstand-tomato-basil">FARMSTAND TOMATO-BASIL</div></a>
<div class="textblock">kale, yellow & green beans, corn, heirloom tomatoes,     grilled halloumi cheese, lima beans, Kalamata olives, sunflower seeds, basil    vinaigrette</div>
</div></div></div>

我的 CSS 是:

    .foodblock{
    float: left;
    margin: 10px;
    height: 400px;
    bottom: 50px;
}
.textblock{
    float: left;
    margin: 20px;
    text-align: center;
}
.menu-type{
    text-align: center;
    font-weight: bold;
    font-family: "Times New Roman", Georgia, Serif;
    font-size: 2.5em;
}
.spicy-avocado-lime{
    height: 200px;
    background-image: url('../images-source/communitybottom.png');
    float: left;
    width: 100%;
}
.toasted-almond-ginger{
    height: 200px;
    background-image: url('../images-source/communitybottom.png');
    float: left;
    width: 100%;
}
.local-apple-bacon-bowl{
    height: 200px;
    background-image: url('../images-source/communitybottom.png');
    float: left;
    width: 100%;
}
.power-bowl{
    height: 200px;
    background-image: url('../images-source/communitybottom.png');
    float: left;
    width: 100%;
}
.farmstand-tomato-basil{
    height: 200px;
    background-image: url('../images-source/communitybottom.png');
    float: left;
    width: 100%;
}
.foodcontent{
    bottom: 500px;
}

如果您知道可能导致此问题的原因,请提供帮助。

【问题讨论】:

  • 我建议使用开发人员工具/萤火虫等来检查元素,这样你就可以立即看到空白空间的位置。我敢打赌它是以下三个选项之一:边距、填充、行高
  • 我检查了页面上的元素,但没有获得任何新知识。它告诉我的只是它是整个页面的一部分的页面 div 的一部分。

标签: html css drupal drupal-7


【解决方案1】:

您的 HTML 中有一堆错误和缺少括号。我已经把它清理干净并扔在小提琴中:

https://jsfiddle.net/7gohamt3/

例如,您在这一行缺少右引号:

<div class="menu-type>Kale & Grain Bowls</div>

这应该可以解决您的问题。

【讨论】:

  • 谢谢你的帮助,这已经奏效了,因为我显然错过了一些要复制的 CSS,所以其他一些事情已经发生了变化,但这是一个简单的修复
  • 好的,显然这个修复并不能很好地转移到其他页面,我将继续调查这个问题。
  • 我仍然无法将文本 div 向上移动以更接近 div 的顶部集,由于所有分离的 CSS,这已被证明很难进行错误测试。
  • 当我将您的 HTML 应用到我的网站并编辑 CSS 以使其再次看起来正确时,由于现在存在的菜单类型 div 发生了变化,并将 HTML 更改应用到它破坏的任何页面除原始页面外的每一页。
【解决方案2】:

如果您正在谈论在成分列表下方创建几何图形的 foodblick,请尝试设置 height:auto 以便 div 符合内容的大小而不是离散的 px 值。

.foodblock{
    height:auto;
    /* rest of declarations */
{

https://jsfiddle.net/x1x6gjw4/

【讨论】:

  • 我目前正在尝试撤消之前的修复,但一旦一切恢复正常,我会测试这个。我指的不是成分列表,而是指带有 col-2 标签的 div。
【解决方案3】:

我猜你的问题是关于“羽衣甘蓝和谷物碗”没有显示。如果是这样,请关闭属性class的引号

<div class="menu-type">Kale & Grain Bowls</div>

在其他 2 个地方关闭 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">kale, avocado, NH slab bacon, local apples, cherries, dried cranberries, sunflower seeds, scallions, red wine vinegar, olive oil</div> </div>

【讨论】:

  • 谢谢,我以为我已经正确关闭了所有内容,但显然没有
  • 我已经关闭了这个页面的这些错误,但我仍然无法将底部的 div 移到顶部。我现在在其他页面上也有错误,我认为这是由于这个 div 关闭问题不仅仅是这一页的问题,但我仍然找不到它们。
  • 我已经恢复了我的旧代码,然后修复了菜单类型标签以使其再次起作用。我现在让我的顶级 div 再次显示内联,但我找不到你所说的关闭标签有什么问题是烤杏仁姜 div 附近的问题。我仍然无法将底部的 div 集向上移动到顶部集
  • 我终于找到并纠正了那些结束标签错误,我的问题仍然存在,我无法将我的 div 向上移动
猜你喜欢
  • 1970-01-01
  • 2018-10-04
  • 2022-06-27
  • 2014-09-14
  • 2019-10-19
  • 1970-01-01
  • 2023-03-15
  • 1970-01-01
  • 2020-11-29
相关资源
最近更新 更多