左边是图片,右边是个div,这样的css怎么写。我的div总是在图片下方。

如题所述

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>左边是图片,右边是个div</title>
<style>
body { margin:0px;
}
.all{ width:1000px;
height:700px;
}
.right { width:300px;
height:400px;
margin-top:10px;
float:left;
margin-left:10px;
padding-left:10px;
padding-right:10px;
}
</style>
</head>

<body>
<div class="all">
<img src="java达人2.JPG" style="float:left;"/>
<div class="right">
左边是图片,右边是个div,图片换成你自己的
<br />
<br />
你留意你的最外面的div宽度有没有小于你图片的宽度加上右边div的宽度,如果超过了,肯定是会跑去另一行
<br />
<br />
还有就是你有没有在图片上加上style="float:left;"的css样式?
<br />
<br />
为了测试,你可以把我的.all的width改成小于你图片的宽度加上右边div的宽度,你就看到效果了
</div>
</div>
</body>
</html>

拿这个代码去试试 有不明白问我 我在线
温馨提示:内容为网友见解,仅供参考
第1个回答  2011-07-21
用一个div作为主框架,嵌套图片和文字内容两个div,同时使用浮动功能。

图片向左浮动,文字内容向右浮动,这就形成了两栏。
右边的文字内容又分为两个div,不需要浮动,它会自动上下排列的。

代码如下:

<div id="container">
<div id="photo"><img src="图片地址" /></div>
<div id="content">
<div id="text">文字介绍</div>
<div id="news">新闻内容</div>
</div>
</div>

CSS:
#container
#photo
#content
第2个回答  2011-07-20
<div style="width:100px;float:right">fasfsa</div><img ...
第3个回答  2011-07-20
<img src="xxx.gif" style="float:left;">
<div style="float:left; width: 100px; height: 100px; border-style: solid; border-width: 1px;">文字</div>
是要这个效果吗?
第4个回答  2011-07-20
float: left

<img src="image.jpg" style="float: left;" />
<div style="width: 100px; height: 100px; background: #aaa; float: left;">DIV</div>本回答被提问者采纳
相似回答