我有一些問題,通過在左邊放置3個div ...和右邊的1個... 它的作品完美,如果每邊只有1格...Div並排
我有一個新聞欄目...爲每個新聞都創建一個新的div。
我會得到這些每頁5 ...(超過1 ...右邊...那麼div會被推下來....)
所有代碼:
<div id="boxes">
<?php foreach ($news as $news_item): ?>
<div id="NewsPageContent">
THIS STUFF
</div><!--End NewsPageContent-->
<?php endforeach ?>
<div id="PlayersOnline">
<h2>Players Online</h2><hr />
<div id="heads">
This is the div to the right
</div><!--End heads-->
</div><!--End PlayerOnline-->
<div id="clear"></div>
</div><!--End boxes-->
CSS:
#boxes{
width: 100%;
overflow: hidden;
clear:both;
margin-top: 10px;
}
#NewsPageContent {
margin-top:10px;
float:left;
width: 63%;
background: #fefefe;
border-radius: 5px 5px 5px 5px;
-moz-border-radius: 5px 5px 5px 5px;
-webkit-border-radius: 5px 5px 5px 5px;
min-height: 100px;
color: #7c7c7c;
font-family: Helvetica, Arial, Verdana, sans-serif;
font-size: 15px;
padding-top: 1px;
padding-left: 10px;
padding-right: 10px;
padding-bottom: 10px;
border: 1px solid #a7a6a6;
}
#PlayersOnline{
float:right;
width: 32%;
background: #fefefe;
border-radius: 5px 5px 5px 5px;
-moz-border-radius: 5px 5px 5px 5px;
-webkit-border-radius: 5px 5px 5px 5px;
min-height: 350px;
color: #7c7c7c;
font-family: Helvetica, Arial, Verdana, sans-serif;
font-size: 15px;
padding-top: 1px;
padding-left: 10px;
padding-right: 10px;
padding-bottom: 10px;
border: 1px solid #a7a6a6;
}
編輯: 從我的瀏覽器的HTML:
<div id="boxes">
<div class="NewsPageContent">
<div id="news_title">
<h3>HomieCraft</h3><hr />
<div id="newsbuttons" style="float: right; font-weight: normal;"><a href="http://10.0.0.88/news/article/15">Read</a> | <a href="#">Comment(6)</a></div>
<p style="font-weight: normal; font-size: 9px; margin-top: 1px; margin-bottom: 0px;margin-left: 2px; padding-bottom: 2px;">Published 26-04-2013 23:39 by GudfareN </p>
</div>
<div style="padding-bottom: 6px;" id="news_text">
<p> HomieCraft awwwwyeeeee</p>
</div>
</div><!--End NewsPageContent-->
<div class="NewsPageContent">
<div id="news_title">
<h3>HomieCraft</h3><hr />
<div id="newsbuttons" style="float: right; font-weight: normal;"><a href="http://10.0.0.88/news/article/14">Read</a> | <a href="#">Comment(6)</a></div>
<p style="font-weight: normal; font-size: 9px; margin-top: 1px; margin-bottom: 0px;margin-left: 2px; padding-bottom: 2px;">Published 26-04-2013 23:39 by GudfareN </p>
</div>
<div style="padding-bottom: 6px;" id="news_text">
<p> HomieCraft awwwwyeeeee</p>
</div>
</div><!--End NewsPageContent-->
<div class="NewsPageContent">
<div id="news_title">
<h3>HomieCraft</h3><hr />
<div id="newsbuttons" style="float: right; font-weight: normal;"><a href="http://10.0.0.88/news/article/13">Read</a> | <a href="#">Comment(6)</a></div>
<p style="font-weight: normal; font-size: 9px; margin-top: 1px; margin-bottom: 0px;margin-left: 2px; padding-bottom: 2px;">Published 26-04-2013 23:39 by GudfareN </p>
</div>
<div style="padding-bottom: 6px;" id="news_text">
<p> HomieCraft awwwwyeeeee</p>
</div>
</div><!--End NewsPageContent-->
<div class="NewsPageContent">
<div id="news_title">
<h3>HomieCraft</h3><hr />
<div id="newsbuttons" style="float: right; font-weight: normal;"><a href="http://10.0.0.88/news/article/12">Read</a> | <a href="#">Comment(6)</a></div>
<p style="font-weight: normal; font-size: 9px; margin-top: 1px; margin-bottom: 0px;margin-left: 2px; padding-bottom: 2px;">Published 26-04-2013 23:39 by GudfareN </p>
</div>
<div style="padding-bottom: 6px;" id="news_text">
<p> HomieCraft awwwwyeeeee</p>
</div>
</div><!--End NewsPageContent-->
<div class="NewsPageContent">
<div id="news_title">
<h3>HomieCraft</h3><hr />
<div id="newsbuttons" style="float: right; font-weight: normal;"><a href="http://10.0.0.88/news/article/11">Read</a> | <a href="#">Comment(6)</a></div>
<p style="font-weight: normal; font-size: 9px; margin-top: 1px; margin-bottom: 0px;margin-left: 2px; padding-bottom: 2px;">Published 26-04-2013 23:39 by GudfareN </p>
</div>
<div style="padding-bottom: 6px;" id="news_text">
<p> HomieCraft awwwwyeeeee</p>
</div>
</div><!--End NewsPageContent-->
<div id="PlayersOnline" style="margin-top: 10px;">
<h2>Players Online</h2><hr />
<div id="heads">
</div><!--End heads-->
</div><!--End PlayerOnline-->
<div id="clear"></div>
</div><!--End boxes-->
內部有一個「類」的'foreach'要創建若干的div一樣'id'。用'class'代替 – fcalderan 2013-04-29 11:16:01
你在foreach循環中用id創建div。這會給你驗證錯誤... – 2013-04-29 11:16:41
嗨,Stian,也許因爲這是一個HTML問題,它可能會幫助你,如果你複製它在你的瀏覽器中產生的HTML,並告訴我們,而不是向我們顯示創建html的邏輯,因爲我們沒有其他的邏輯來看看它產生了什麼。 – Nnoel 2013-04-29 11:17:43