[英]css news article layout problems
I am doing css/html for a school assignment, but I got stuck.我正在为学校作业做 css/html,但我被卡住了。 I am trying to build a newsoverview but I don't know how to build this in the good/qualitative way.
我正在尝试构建新闻概览,但我不知道如何以良好/定性的方式构建它。
Problems:问题:
I need: http://i.imgur.com/vz51zyA.png我需要: http : //i.imgur.com/vz51zyA.png
I have: http://i.imgur.com/4wTmtXu.png我有: http : //i.imgur.com/4wTmtXu.png
<div id="newsListContainer">
<div id="newsListHeader"><h1>Laatste nieuws</h1></div>
<div class="newsListItem">
<img src="img/item3.jpg" width="100" height="75">
<h2> Lorem Ipsum is simply dummy text of the printing and typesetting industry. </h2>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
</div>
</div>
CSS: CSS:
#newsListContainer {
float:left;
width:100%;
background: url("img/body_bg.png") repeat-y;
}
#newsListHeader{
float:left;
width:690px;
height:40px;
margin-top:10px;
margin-bottom:10px;
border-bottom:1px solid #d6d6d6;
margin-left:133px;
}
.newsListItem {
margin-left:150px;
}
.newsListItem img{
float:left;
}
HTML UPDATED: HTML 更新:
<div id="newsListContainer">
<div id="newsListHeader"><h1>Laatste nieuws</h1></div>
<ul><li class="newsListItem">
<img src="img/item3.jpg">
<h2> Lorem Ipsum is simply dummy text of </h2>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry</p>
</li></ul>
<ul><li class="newsListItem">
<img src="img/item3.jpg">
<h2> Lorem Ipsum is simply dummy text of </h2>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry</p>
</li></ul>
</div>
CSS UPDATED: CSS 更新:
#newsListContainer {
float:left;
width:100%;
background: url("img/body_bg.png") repeat-y;
}
#newsListHeader{
float:left;
width:690px;
height:40px;
margin-top:10px;
margin-bottom:10px;
border-bottom:1px solid #d6d6d6;
margin-left:133px;
}
.newsListItem {
/*margin-left:150px;*/
padding-left: 115px;
}
.newsListItem img{
float:left;
width: 100px;
margin-left: -115px; /* SAME AS PADDING ABOVE */
In answer to your questions, and trying not to do your assignment for you:回答您的问题,并尽量不为您完成任务:
<div id="newsListHeader">
container though?<div id="newsListHeader">
容器吗?<ul><li class="newsListItem">News item here</li></ul>
).<ul><li class="newsListItem">News item here</li></ul>
)。.newsItemContainer
and then negatively margin back the image by the same width..newsItemContainer
添加填充,然后将图像负边距相同的宽度。 That means that the text will always line up along that padding line. Code snippet:代码片段:
.newsListItem { padding-left: 115px; } .newsListItem img { float: left; width: 100px; /* Added */ margin-left: -115px; /* SAME AS PADDING ABOVE */ }
<!DOCTYPE html> <html> <head> <meta charset=utf-8 /> <title>JS Bin</title> </head> <body> <div class="newsListItem"> <img src="http://placehold.it/100x75" width="100" height="75"> <h2> Lorem Ipsum is simply dummy text of the printing and typesetting industry. </h2> <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p> </div> <div class="newsListItem"> <img src="http://placehold.it/100x75" width="100" height="75"> <h2> Lorem Ipsum is simply dummy text of the printing and typesetting industry. </h2> <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p> </div> </body> </html>
.newsListItem img{
float:left;
margin-right:16px;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.