2016-05-20 3 views
0

У меня проблема с поплавком. Текст не передает изображение с правой стороны, кроме первой строки. Когда я создаю новый html-документ и вставляю картинку с описанием, все работает нормально. Я не знаю, где проблема.float свойство не работает

Вот 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; 
} 
+0

Вы должны использовать хром средства разработки, чтобы дать вам лучшее представление о том, что CSS стили применяются – Maxwelll

ответ

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/

+0

Ваше решение работает. Большое спасибо. Но вы знаете, что я еще раз пытался использовать свой код, и он работает ... Я не совсем понимаю, почему стиль «float: left' не был применен в первый раз. –

0

В файле CSS, вам нужно #shawshank {...} вместо просто shawshank{...}, так как вы ориентируетесь элемент по его идентификатору. Также я заметил, что в вашем коде свойство id на вашем изображении «shwashank» вместо «shawshank», так что это тоже может быть проблемой.

Кроме того, ваши поплавки могут не работать с вашей текущей вложенностью изображения внутри тега абзаца, так как они должны плавать рядом друг с другом. Попробуйте:

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

И в файле CSS добавить:

#shawshank_description { 
    float: right; 
} 
Смежные вопросы