У меня проблема с выравниванием элементов.
У меня есть элементы, которые появляются внутри других, например, мой абзац с красным фоном выше моего изображения, а моя вторая статья выше моей первой статьи.
Я уже пробовал много тестов с поплавками, но он не работает.
Вы видите, где проблема?
Вот пример, показывающий мою проблему: http://jsfiddle.net/2tsmX/3/
Мой html:
<div id="body_news">
<div id="body-news1">
<h1>News</h1>
<article id="news">
<div class="img_container">
<img src="../image.jpg"/>
</div>
<h2><a href="#" >Títule Of the News</a></h2>
<span>Date of the news</span>
<p>text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here
</p>
</article>
<article id="news">
<div class="img_container">
<img src="../image.jpg"/>
</div>
<h2><a href="#" >Títule Of the News</a></h2>
<span>Date of the news</span>
<p>text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here
</p>
</article>
</div>
</div>
Мой css:
#body_news1
{
float:left;
width:480px;
}
#body_news1 h1
{
font-size:25px;
font-weight:100;
margin-bottom:10px;
}
.img_container
{
width: 160px;
height: 165px;
float: left;
overflow: hidden;
position: relative;
text-align: center;
box-shadow: 0px 0px 5px #aaa;
cursor: default;
margin-right:20px;
border:3px solid #f3f3f3;
margin-top:4px;
}
#body_news
{
width:480px;
height:auto;
margin:0 auto 0 auto;
}
#news
{
margin-bottom:5px;
position:relative;
background:yellow;
width:480px;
text-align:left;
}
#news h2 a
{
font-size:20px;
color:#000;
text-decoration:none;
margin-left:0;
}
#news span
{
font-size:14px;
}
#news p
{
margin-top:5px;
margin-bottom:5px;
background:red;
}
Вы пытаетесь сделать что-то подобное?
HTML
<div id="body_news">
<div id="body-news1">
<h1>News</h1>
<article class="news">
<div class="img_container">
<img src="../image.jpg"/>
</div>
<h2><a href="#" >Title Of the News</a></h2>
<span>Date of the news</span>
<p>
text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here
</p>
</article>
<article class="news">
<div class="img_container">
<img src="../image.jpg"/>
</div>
<h2><a href="#" >Title Of the News</a></h2>
<span>Date of the news</span>
<p>
text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here
</p>
</article>
</div>
</div>
CSS
#body_news1
{
width:480px;
}
#body_news1 h1
{
font-size:25px;
font-weight:100;
margin-bottom:10px;
}
.img_container
{
width: 160px;
height: 165px;
float: left;
text-align: center;
box-shadow: 0px 0px 5px #aaa;
cursor: default;
margin-right:20px;
border:3px solid #f3f3f3;
margin-top:4px;
}
#body_news
{
width:480px;
margin:0 auto 0 auto;
}
.news
{
margin-bottom:5px;
background:yellow;
min-height:185px;
}
.news h2 a
{
font-size:20px;
color:#000;
text-decoration:none;
margin-left:0;
}
.news span
{
font-size:14px;
}
.news p
{
margin-top:5px;
margin-bottom:5px;
background:red;
}
min-height
предотвращает .news
размера .img_container
по .img_container
с .img_container
и позволяет изображению появляться за пределами границ .news
.
Простое исправление - добавьте <div style="clear:both;"></div>
после <span>Date of the news</span>
каждого div
Пример:
<div id="body_news">
<div id="body-news1">
<h1>News</h1>
<article id="news">
<div class="img_container">
<img src="../image.jpg"/>
</div>
<h2><a href="#" >Títule Of the News</a></h2>
<span>Date of the news</span>
<div style="clear:both;"></div> <!--HERE-->
<p>
text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here
</p>
</article>
<article id="news">
<div class="img_container">
<img src="../image.jpg"/>
</div>
<h2><a href="#" >Títule Of the News</a></h2>
<span>Date of the news</span>
<div style="clear:both;"></div> <!--HERE-->
<p>
text here text here text here text here text here text here text here text here text here text here text here text here text here text here text here
</p>
</article>
</div>
</div>
id="news"
наclass="news"
так как и ID должен быть уникальным