我的代码在这里:http://jsfiddle.net/u9BsD/2/
您将看到第二部分#indoorRange正在应用最后一个子项,将最后一个框向右推,并将宽度增加1%。 #membership的第一部分是完全相同的,但是有三个块但是last-child类没有影响它应该的元素。是否有一些关于我不知道的最后一个孩子规则的规则?
感谢您的帮助。
<div id="memberships">
<div class="greyHeading">
<header>
<h3>Individual Membership:</h3>
</header>
<p>$175.00</p>
</div>
<div class="greyHeading">
<header>
<h3>Family Membership:</h3>
</header>
<p>$200.00 (Includes spouse and children under 21)</p>
</div>
<div class="greyHeading">
<header>
<h3>Red, White and Blue Discounts:</h3>
</header>
<p>Active LE, military, and 1st responders: 1/2 price membership discount!</p>
<p>Retired LE, military and 1st responders 25% discount on membership!</p>
</div>
<div class="cl"></div>
</div>
<div id="indoorRange">
<div class="greyHeading">
<header>
<h3>Range Fees</h3>
</header>
<p>The range fees are per session. A "session" is defined as a visit to Allen
Arms Indoor Shooting Range. We reserve the right to limit sessions to one
hour if other customers are waiting for lanes.</p>
<p>All lanes limited to two shooters unless special permission is obtained
in advance.</p>
</div>
<div class="greyHeading">
<header>
<h3>Single Session</h3>
</header>
<ul>
<li>One Adult Shooter: $10.00</li>
<li>Two Adult Shooters on Same Lane: $7.50 Each</li>
<li>Children under 18 with paying adult guardian: Free</li>
</ul>
</div>
<div class="greyHeading">
<header>
<h3>Ladies Day</h3>
</header>
<p>Every Wednesday is Ladies Day! Women shoot for $5.00. Additionally, women
receive 20% off range memberships.</p>
</div>
<div class="greyHeading">
<header>
<h3>Red White and Blue Discounts</h3>
</header>
<p>Law Enforcement, Active Duty Military, First Responders, and Security
personnel pay only $5.00 per session any time, and receive 50% discount
on memberships!</p>
</div>
</div>
#memberships .greyHeading {
float: left;
width: 32%;
margin: 0 1% 0 0;
}
#memberships .greyHeading:last-child {
float: right;
margin: 0;
width: 33%;
}
#memberships .greyHeading header {
background: #666;
margin: 0 0 10px 0;
}
#memberships .greyHeading header h3 {
color: #fff;
text-shadow: 0px 1px 1px rgba(0, 0, 0, 1);
line-height: 25px;
margin: 0;
padding: 5px 0 1px 5px;
}
#indoorRange .greyHeading {
float: left;
width: 24%;
margin: 0 1% 0 0;
}
#indoorRange .greyHeading:last-child {
float: right;
margin: 0;
width: 25%;
}
#indoorRange .greyHeading header {
background: #666;
margin: 0 0 10px 0;
height: 55px;
}
#indoorRange .greyHeading header h3 {
color: #fff;
text-shadow: 0px 1px 1px rgba(0, 0, 0, 1);
line-height: 25px;
margin: 0;
padding: 5px 0 1px 5px;
}
答案 0 :(得分:2)
从HTML中移除<div class="cl"></div>
并将#indoorRange { clear: both; }
添加到css中,我相信这会修复它。
样式未应用于最后一个成员资格greyHeading,因为<div class="cl">
元素实际上并不是最后一个成员。
EDIT2:我对应用了样式的cl div是正确的,你也许可以使用last-of-type
伪选择器来实现你想要的东西,不幸的是我不知道什么是浏览器支持。
有关更多信息,请参阅此SO问题:
CSS last-child selector: select last-element of specific class, not last child inside of parent?
答案 1 :(得分:0)
这不是最理想的答案,因为它无法解决原因:最后一个孩子不能正常工作。但是,这对我有用,可能是一个合适的解决方案。
我所做的只是从使用最后一个孩子切换到n-child。所以这两个特定的类是变化...我还添加了背景颜色,使它更明显地表现在它们在这里的jsfiddle中工作:http://jsfiddle.net/u9BsD/3/
#memberships .greyHeading:nth-child(3) {
float: right;
margin: 0;
width: 33%;
background: red;
}
#indoorRange .greyHeading:nth-child(4) {
float: right;
margin: 0;
width: 25%;
background: blue;
}