Html 如何在div周围环绕文本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13296762/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to wrap text around a div?
提问by Szuturon
I have a container div around my coinslider. I would like to wrap text around this container div. How does one go about achieving this?
我的硬币滑块周围有一个容器 div。我想在这个容器 div 周围环绕文本。如何实现这一目标?
Right now the my HTML is setup like this:
现在我的 HTML 设置如下:
<p> <!-- LOTS OF TEXT --> </p>
<div id="mycontainer"> <!-- coinslider inside --></div>
My CSS is setup like this:
我的 CSS 设置如下:
#mycontainer {
position: relative;
float: right;
width: 500;
height: 334;
}
回答by TechFreak
<div>
<div style="float:left; width: 150px; height: 150px; margin: 10px; background-color: #ff0000;">
<!--your image or text-->
</div>
<p>But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?</p>
<p>But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?</p>
</div>
回答by Sushanth --
Encase you Div in another div and Give the float property to it ...
将你的 Div 包裹在另一个 div 中,并赋予它 float 属性......
<div id="main">
<div id="mycontainer"> <!-- coinslider inside --></div>
</div>
<p> <!-- LOTS OF TEXT --> </p>
#main
{
float:right;
}
#mycontainer
{
width: 500px;
height: 334px;
background-color: gold;
}
OR
或者
P should come after Div
P 应该在 Div 之后
<div id="mycontainer"> <!-- coinslider inside --></div>
<p> <!-- LOTS OF TEXT --> </p>
#mycontainer
{
float:right;
width: 500px;
height: 334px;
background-color: gold;
}
**
**
**
**
回答by Alex Kittavong
<div id="mycontainer"> <!-- coinslider inside --><p> <!-- LOTS OF TEXT --> </p></div>
Your text needs to go inside the div container. Hope that works.
您的文本需要进入 div 容器。希望有效。
回答by platforms
Add this to your CSS and you should be good:
将此添加到您的 CSS 中,您应该会很好:
display: block;