我正在努力工作first-child
li并将文字推得更多一点,但它不起作用。 last-child
有效,但第一个孩子没有。
.latest-posts li:first-child {
padding-top: -5px;
}
.latest-posts li:last-child {
margin-bottom: 0;
padding-bottom: 12px;
border: 0;
margin-left: 3px;
}
.recent-posts-box ul {
list-style: none;
margin: 0;
padding: 0;
}
.recent-posts-box .entry {
display: block;
width: 200px;
padding: 8px 0 0 0;
float:left;
}
.latest-posts li {
height:35px;
margin: 0;
padding: 0;
margin-bottom: 0;
padding-bottom: 12px;
border-bottom: 1px dotted;
display:block;
line-height: 1.2em;
clear:both;
}
.latest-posts .entry li:first-child {
background: blue;
}
.latest-posts li:last-child {
margin-bottom: 0;
padding-bottom: 12px;
border: 0;
margin-left: 3px;
}
.latest-posts li:last-child img {
margin-top: 3px;
}
.recent-posts-box img {
display: block;
float:left;
width: 40px;
height: 40px;
margin-right:10px;
}
.recent-posts-box .entry .date {
display: block;
line-height: 1.4em;
margin-top: 2px;
}
.latest-posts li:hover{
background-color: rgba(0, 0, 0, 0.1);
-moz-border-radius: 6px;
-webkit-border-radius: 6px;
border-radius: 6px;
}
.latest-posts a {
font-size: 14px;
color: #423338;
border-bottom: 1px solid transparent;
-webkit-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-ms-transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
transition: all 300ms ease-in-out;
text-decoration: none;
}
.latest-posts a:hover {
border-color: #423338;
}
.recent-posts-box .link {
text-align: right;
font-size: 14px;
}
.recent-posts-box .link a {
font-size: 14px;
color: #423338;
border-bottom: 1px solid transparent;
-webkit-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-ms-transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
transition: all 300ms ease-in-out;
text-decoration: none;
}
.recent-posts-box .link a:hover {
border-color: #423338;
}
<div class="recent-posts-box">
<h1>Recent Posts</h1>
<div class="latest-posts-container">
<ul class="latest-posts">
<li>
<img alt="img" />
<div class="entry">
Entry 1
<span class="date">Date 1</span>
</div>
</li>
<li>
<img alt="img" />
<div class="entry">
Entry 2
<span class="date">Date 2</span>
</div>
</li>
</ul>
</div>
<li class="link"><a href="/articles">More Articles..</a></li>
</div>
预览:
正如你在图片中看到的那样,第一个孩子的对齐关闭了(就像推了一下),我想稍微提起一点,但是我尝试了li:first-child
它只是没有似乎工作。有任何想法吗?
答案 0 :(得分:1)
您好我看到了您的代码,我认为您希望看到的结果是您在我修改的代码中看到的结果:
编辑这部分代码:
.recent-posts-box .entry {
display: block; /* here without padding:8px 0 0 0; */
width: 200px;
float:left;
}
答案 1 :(得分:0)
你的代码有img,其中float为left,类为.entry,也是float。在关闭div之前你没有申请清除。因此,它不适用。
解决方案1:
<li>
<img alt="img">
<div class="entry">
Entry 1
<span class="date">Date 1</span>
</div>
<div class="clear" style="clear:both;"></div>
</li>
解决方案2: .latest-posts li:在{content:“”之后;显示:块;明确:两者;高度:0像素;}
试试这个,如果没有解决,我会帮助你更多。