【问题标题】:removing space between vertical divs删除垂直 div 之间的空间
【发布时间】:2009-08-15 05:15:59
【问题描述】:

我有三个垂直对齐的 div 彼此重叠。顶部和底部只是在播放器的顶部和底部显示图像。因此协调变成这样

<div>
 <img>top</img>
<div>
<div>
  <div></div>
  <div></div>
  <div></div>
</div>
<div>
 <img>bottom</img>
</div>

现在中间 div 的顶部和底部之间有白线/空格。但是我明确地将边距和待处理以及边框设置为零,但仍然没有解决方案。

这个问题不会出现在 IE6/IE7/IE8 等浏览器中,而是所有其他浏览器。

感谢 bobince,它通过设置垂直对齐:底部来处理顶部图像,但不适用于底部图像。我想把谁放在首位。

好的,这里是详细代码

<div id="top" >
    <img alt="topimage" style="vertical-align:bottom">
      <xsl:attribute name="src">
        <xsl:value-of select="TopImage"/>
      </xsl:attribute>
    </img>
  </div>
  <div id="container" style="clear:both;display:block;margin: 0 0 0 0;padding: 0 0 0 0;text-align:left;border:0 none;">
    <div id="left" style="margin: 0 0 0 0;padding: 0 0 0 0;float: left;">
      <img alt="left image"  style="margin: 0 0 0 0;padding: 0 0 0 0;vertical-align:bottom">
        <xsl:attribute name="src">
          <xsl:value-of select="LeftImage"/>
        </xsl:attribute>
      </img>
    </div>

    <div id="flashde260252-c874-4c67-b1aa-64ebe80bb701"  style="margin: 0 0 0 0;padding: 0 0 0 0;float:left;border:0;vertical-align:bottom">
      <embed id="flashde260252-c874-4c67-b1aa-64ebe80bb7010" height="308" width="512" allowfullscreen="true" wmode="transparent" quality="high" bgcolor="#ffffff" name="flashde260252-c874-4c67-b1aa-64ebe80bb7010" style="margin: 0 0 0 0;padding: 0 0 0 0;"  type="application/x-shockwave-flash">
        <xsl:attribute name="src">
          <xsl:value-of select="Movie"/>
          <xsl:text>?flvfile=</xsl:text>
          <xsl:value-of select ="Destination"/>
          <xsl:text >&amp;lang=e&amp;environment=PROD</xsl:text>
        </xsl:attribute>
      </embed>
    </div>

    <div id="rightimage" style="margin: 0 0 0 0;padding: 0 0 0 0;float:left;">
      <img alt="rightimage"  style="vertical-align:bottom">
        <xsl:attribute name="src">
          <xsl:value-of select="RightImage"/>
        </xsl:attribute>
      </img>
    </div>
  </div>
  <!-- <div id="bcontainer" style="margin: 0 0 0 0;padding: 0 0 0 0;text-align:left;border-left:0;border-right:0;border-top:0;border-bottom:0px;border:none;">-->
  <div id="bottom" style="clear:both;display:block;margin: 0 0 0 0;padding: 0 0 0 0;vertical-align:top;text-align:left;border:0 none">
    <img alt="subscribe" src="IRBBottom.jpg" usemap="#promomap" border="0" style="vertical-align:top">
      <xsl:attribute name="src">
        <xsl:value-of select="BottomImage"/>
      </xsl:attribute>
    </img>
  </div>
  <!-- </div> -->
  <div id="toc" style="clear:both;display:block;text-align:left;">
    <ol style="list-style:none;font-size:small;font-weight:bold">
      <li>* Includes all matches from main pitch, plus selected matches from pitch 2 - see FAQ for details.</li>
      <li>** Includes all matches on Finals Day, March 7th from main pitch - see FAQ for details.</li>
      <li>*** All matches on main pitch will be live and matches on pitch 2 will be on demand - see FAQ for details.</li>
    </ol>
  </div>
  <map name="promomap">
    <area shape="rect" coords="229,46,350,137" href="index.html" alt="Subscribe or Login" title="Subscribe or Login"/>
    <area shape="rect" coords="410,47,528,137" href="XXX.html" alt="R Video" title="Ro"/>
  </map>
  <script type="text/javascript">
    <xsl:text disable-output-escaping="yes">
  function showMovie(player,movie,endthumb,destination){
    var so = new SWFObject(player+'?flvfile='+movie+'&amp;endthumb='+endthumb +'&amp;endlink='+destination,'flashde260252-c874-4c67-b1aa-64ebe80bb7010','512','308','8', '#ffffff', 'high','');
    so.addParam('wmode', 'transparent');so.addParam('allowfullscreen', 'true');so.write('flashde260252-c874-4c67-b1aa-64ebe80bb701');
  }
  </xsl:text>
    <xsl:text> showMovie('</xsl:text>
    <xsl:value-of select="Player"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="Movie"></xsl:value-of>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="EndThumb"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="Destination"/>
    <xsl:text>');</xsl:text>
  </script>
</div>

:) 现在除了 IE 的 lol 之外,它在设置 line-height 之后都可以工作了

【问题讨论】:

  • 你能把你的代码贴出来让我们看看吗?
  • 如果您包含能够重现您的问题的示例 HTML 和 CSS,会更容易提供帮助。
  • 代码作为原始 HTML 包含在内;添加了要修复的代码块。
  • 实际上这是 XSLT 转换,所以粘贴代码需要发布很多东西,所以我只是尽量放。但我会看看我是否可以粘贴更多

标签: html css


【解决方案1】:

只需将顶部和底部 div 的 line-height 属性设置为 0

示例代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <title>Test</title>
    <style type="text/css">
        #top {
            background-color: #f00;
            line-height: 0px;
        }
        #middle {
            background-color: #0f0;
        }
        #bottom {
            background-color: #00f;
            line-height: 0px;
        }
    </style>
</head>
<body>
    <div id="top">
        <img src="http://i.stackoverflow.com/Content/Img/stackoverflow-logo-250.png"
            alt="Stackoverflow" />
    </div>
    <div id="middle">
        <div>This is the first middle div child.</div>
        <div>This is the second middle div child.</div>
        <div>This is the third middle div child.</div>
    </div>
    <div id="bottom">
        <img src="http://www.gravatar.com/avatar/ae3e50c947379163d74b6de6fa01d509?s=32&amp;d=identicon&amp;r=PG"
            alt="Gripsoft avatar" />
    </div>
</body>

【讨论】:

【解决方案2】:

如果它在除 IE 之外的所有设备中都能正常工作,那么如果图像标记后有空格,则会出现 IE 错误。试试这个:

<div>
    <img /></div>

而不是这个:

<div>
    <img />
</div>

【讨论】:

【解决方案3】:

图像位于内联框的文本基线上。在图像的左侧和右侧添加文本以验证这一点。文本基线下方有空间为字母的下行(‘g’、‘y’等)以及行距腾出空间。

将图像的 CSS 样式“vertical-align”设置为“top”或“bottom”(视情况而定),使其与文本行的边缘而不是基线对齐。

【讨论】:

    【解决方案4】:

    你可以给图片@​​987654321@。或者,您可以使用 &lt;br/&gt; 跟随图像或将其包装在 div 中(确保没有空格)。在这种情况下,我更喜欢使用 display: block,除非您出于某种原因需要将 2 张图片放在一起。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-24
      • 1970-01-01
      • 2013-07-20
      • 1970-01-01
      相关资源
      最近更新 更多