浮动属性不起作用

时间:2016-05-20 20:08:42

标签: css-float

我有漂浮的问题。除第一行外,文本不会从右侧流动图片。当我创建一个新的HTML文档并插入描述图片一切正常。我不知道问题出在哪里。

这是html:

<div id="container">

    <div id="logo">
        <h1>Best movies of all time!</h1>
    </div>

    <div id="nav">
        Shawshank Redemption <br />
        Forrest Gump <br />
        Seven <br />
        The Lord of the Rings <br />
        American Gangster  <br />
    </div>

    <div id="content">

        <h2>Shawshank Redemption</h2>

        <p id="shawshank_description">
        <img id="shwashank" src="img/shawshank.jpg" width="200" height="150" />
        The Shawshank Redemption is a 1994 American drama film written and directed by Frank Darabont, and starring Tim Robbins and Morgan Freeman. Adapted from the Stephen King novella   Rita Hayworth and Shawshank Redemption, the film tells the story of Andy Dufresne, a banker who is sentenced to life in Shawshank State Penitentiary for the murder of his wife and her lover, despite his claims of innocence.  During his time at the prison, he befriends a fellow inmate, Ellis Boyd "Red" Redding, and finds himself protected by the guards after the warden begins using  him in his money-laundering operation. Although it was a box office disappointment, the film received multiple award nominations (including seven Oscar nominations) and outstanding reviews from critics for its acting, story, and realism. It has since been successful on cable television, VHS, DVD, and Blu-ray. It was included in the American Film Institute's 100 Years...100 Movies 10th Anniversary Edition.[4] It is considered to be one of the greatest films of all time. The Shawshank Redemption is a 1994 American drama film written and directed by Frank Darabont, and starring Tim Robbins and Morgan Freeman. Adapted from the Stephen King novella    Rita Hayworth and Shawshank Redemption, the film tells the story of Andy Dufresne, a banker who is sentenced to life in Shawshank State Penitentiary for the murder of his wife and her lover, despite his claims of innocence.  
        </p>

    </div>

    <div id="ad">
        <img src="img/banner.gif" />
    </div>

    <div id="footer">
        Best movies of all time! &copy; All rights reserved
    </div>

</div>

这是css:

#shawshank {
  float: left;
}

2 个答案:

答案 0 :(得分:0)

在您的CSS文件中,您需要#shawshank {...}而不仅仅是shawshank{...},因为您要按其ID定位元素。另外我在你的代码中注意到你图像上的id属性是&#34; shwashank&#34;而不是&#34; shawshank&#34;,所以这也可能是一个问题。

此外,您的浮点数可能不适用于段落标记内图像的当前嵌套,因为它们应该彼此并排浮动。尝试:

<img id="shawshank" src="img/shawshank.jpg" width="200" height="150" />
<p id="shawshank_description">...</p>

在CSS文件中添加:

#shawshank_description {
    float: right;
}

答案 1 :(得分:0)

这里的问题是您的float: left样式没有被应用...试试这个:

HTML:

<p id="shawshank_description">
  <div class="shank_image">
    <img src="img/shawshank.jpg" width="200" height="150" />
  </div>
  It is considered to be one of the greatest films of all time... 
</p>

CSS:

.shank_image img{
  float: left;
}

https://jsfiddle.net/qbbbm514/