【问题标题】:Text wrapping around a div环绕 div 的文本
【发布时间】:2013-07-09 20:55:41
【问题描述】:

如果您希望 div 位于容器底部,如何让文本环绕 div

我可以弄清楚如何让文本环绕在 div 的顶部,但如果我尝试将其推到页面底部,文本要么不会继续穿过顶部的divdiv 被推到文本前面。

目前,我有一个容器 div,然后变暗的框是该 div 中的另一个 div。

我正在尝试创建这个:

【问题讨论】:

    标签: css html text


    【解决方案1】:

    您只需要使用float 属性。

    HTML:

    <div>
        <img src="http://www.igta5.com/images/trailer-2-gtav-logo.jpg" alt="GTA V" />
        <p>
            Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
            Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
            Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
        </p>
    </div>
    

    CSS:

    div img {
        width: 240px;
        float: right;
        padding: 25px;
    }
    

    Play with this on jsFiddle.


    更新

    使用纯 CSS,您将获得的最大好处是使用绝对定位手动分隔图像的两侧。

    HTML:

    <div class="left">
        Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    </div>
    <div class="right">
        Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    </div>
    <img src="http://www.igta5.com/images/trailer-2-gtav-logo.jpg" style="width: 240px; height: 140px;">
    

    CSS:

    img {
        position: absolute;
        top: 0;
        left: 50%;
        margin-left: -125px;
        margin-top: 60px;
    }
    
    .left, .right {
        width: 49%;
    }
    
    .left {
        float: left;
    }
    .right  {
        float: right;
    }
    
    .left:before, .right:before {
        content: "";
        width: 125px;
        height: 200px;
    }
    
    .left:before {
        float: right;
    }
    
    .right:before {
        float: left;
    } 
    

    Play with this on jsFiddle.

    更多信息

    您可以在this topic, on StackOverflow找到更多信息。

    【讨论】:

    • 这就是我目前拥有的。我遇到的问题是,如果我使用边距或填充将 div 向下推到容器的底部,文本不会环绕顶部,因为 div 上方仍有“空间”。
    • Gg 使用 GTA V 标志 :)
    • 对于那些对原始答案有疑问的人...确保浮动元素在前,包装元素紧随其后。我花了太多时间才弄清楚这一点。
    【解决方案2】:

    position: absolute;会摆脱鬼元素空间

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多