img浮动到文本的左侧

时间:2012-04-17 17:42:58

标签: html css css-float

我无法将图像浮动到文本的左侧。能否请你帮忙?还可以在CSS中写宽度=“200”高度=“200”吗?如果有可能,怎么样?谢谢你的帮助。

Html code

        <div class="content">
        <img src="img1.jpg" class="bw" width="200" height="200" alt="king">
        Content is very important bla bla bla....Content is very important bla bla bla....Content is very important bla bla bla....Content is very important bla bla bla....Content is very important bla bla bla....Content is very important bla bla bla....Content is very important bla bla bla....Content is very important bla bla bla....Content is very important bla bla bla....Content is very important bla bla bla....
        </div>


CSS
     div.content {
         width:80%;
         padding-top: 2pc;
         padding-left: 5pc;
         text-align:left;
         font: 10pt Helvetica,"Helvetica neue", Arial, sans-serif;
         margin-left: 100px;
         margin-right: 300px;
         color: #000000 }

     div.img.bw {
         float:left;
         margin:4px; }

2 个答案:

答案 0 :(得分:2)

最大的问题是您的选择器图像错误。

应该是:

div img.bw {
float: left;
margin: 4px; 
}

现在css正在寻找一个带有“img”类的div。

答案 1 :(得分:2)

div.img.bw不正确。您应该将其定义为div img.bw。您需要在image元素内的bw目标和元素div。这是div img.bw目标的内容。另外要定义高度和宽度使用:

 div img.bw {
  float:left;
  margin:4px; 
  width:200px;
  height:200px;
}