css - 环绕 div 的文本

标签 css html text

如果您想要容器底部的 div,如何让文本环绕 div

我可以弄清楚如何让文本环绕在 div 上,只要它在顶部,但如果我尝试将它推到页面底部,文本要么不会'不要继续跨越 div 的顶部,否则 div 会被推到文本前面。

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

我正在尝试创建这个:

最佳答案

您只需要使用 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 中找到更多信息.

关于css - 环绕 div 的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17558033/

相关文章:

html - 基于类将样式应用于标题属性

php - 如何按自定义字段日期订购 wordpress 帖子?

html - 文本超出父 div

python - 有没有办法在 Python 中找到句子中第二长的单词?

css - 如何相对于页面大小缩放一组文本标签?

javascript - 我需要使用 javascript 和 css 更改段落中的第一句粗体

CSS 选择器匹配样式属性中的特定值

javascript - 为下拉菜单应用背景图像在 IE 上不起作用

母版页中的 ASP.NET CSS 文件

javascript - 如何在 Javascript/Jquery 中以编程方式调用突出显示效果(类似于鼠标悬停)?