在<h1>之后将填充应用于具有某些类的元素

Abr*_*iel 3 css internet-explorer css-selectors css3 internet-explorer-8

我想要做的是在header1 元素之后的最后一个元素(例如段落<p>或无序列表<ul>),该<h1>元素具有一个被调用的类specialInstructionsNotes,用于将额外填充(30px)应用于仅具有类specialInstructionsNotes 的最后一个元素.

我试图结合使用:first-of-type:nth-of-type(1)CSS3选择器,但这些选择器不会转移到IE8(这是我将要去的最低的IE兼容浏览器).我的目标是能够在所有最新的浏览器和IE8 +中显示CSS设置(将填充应用于类的最后一个元素specialInstructionsNotes).

注意:可以有3个或更多元素应用此类,只要具有类的最后一个元素.specialInstructionNotes在最底部具有填充.对不起任何困惑.

这是我到目前为止的完整CSS:

.specialInstructionsNotes {
    color: #004abc;
    font-size: 1.1em;
    line-height: 26px;
    padding: 0 3%;
}    

h1 + p.specialInstructionsNotes + *, 
    h1 + ul.specialInstructionsNotes + *, 
    h1 + p.specialInstructionsNotes:nth-of-type(1), 
    h1 + ul.specialInstructionsNotes:nth-of-type(1) { 
        padding: 0 0 30px; 
    }

h1 + p.specialInstructionsNotes:first-of-type, 
h1 + ul.specialInstructionsNotes:first-of-type { 
    padding: 0; 
}
Run Code Online (Sandbox Code Playgroud)

对于HTML,元素位于一个div中,并且是div中包含的最顶层元素.对于我遇到的一些页面/场景,这是我目前拥有的HTML.

第1页:

<div class="span12 main">
<h1><small>Proposal Narrative</small></h1>
            <p class="specialInstructionsNotes">A narrative proposal sufficient for peer review is required. Narratives can be up to <strong>5 single-spaced (12 pt. font) pages</strong>. Please note: the bibliography does <em>not</em> count towards the 5-page limit). The narrative should include:</p>
            <ul class="specialInstructionsNotes">
                <li>A statement of the objectives and significance of the proposed research/creative activity.</li>
                <li>A summary of relevant previous work by the applicant and/or others in the field.</li>
                <li>A description of the plan for accomplishing the objectives - include methodology, the roles of all personnel involved, and plans for access to any special resources.</li>
                <li>Although budget details and justification for personnel and non-personnel costs are required in the budget section, the narrative should make reference to all items, activities, and services of the requested funding.</li>
            </ul>
.
.
.
other elements added to the page
.
.
.
</div>
Run Code Online (Sandbox Code Playgroud)

第2页:

<div class="span12 main">
<h1><small>Brief Summary of Current Research/Creative Activities</small></h1>
            <p class="specialInstructionsNotes">A brief summary of the investigator’s research/creative activities, whether or not they are related to the activities proposed in this application.</p>
.
.
.
other elements added to the page
.
.
.
</div>
Run Code Online (Sandbox Code Playgroud)

第3页:

<div class="span12 main">
<h1><small>Supplemental Information</small></h1>
            <ul class="specialInstructionsNotes">
                <li>Supplemental information is not required. </li>
                <li>Please do not upload article reprints or book chapters. </li>
                <li>Uploaded files must be less than 1 megabyte in size. If you are attempting to upload scanned documents please use the OCR function to convert them to text before uploading. </li>
            </ul>
.
.
.
other elements added to the page
.
.
.
</div>
Run Code Online (Sandbox Code Playgroud)

第4页:

<div class="span12 main">
<h1><small>Publication List</small></h1>
            <ul class="specialInstructionsNotes">
                <li>A listing of publications and/or performances/creative activities for the last three years of the investigator(s)</li>
                <li>Vitae are not requested</li>
            </ul>
            <p class="specialInstructionsNotes">Each applicant on the proposal should upload a separate list. This list will be stored in the system and you may retrieve it in the future. If you or any other CoPI had previously uploaded a publication list, it will be shown below.<br /><br />
                <strong>Please upload your own publication list only.</strong>
            </p>
.
.
.
other elements added to the page
.
.
.
</div>
Run Code Online (Sandbox Code Playgroud)

如果我需要进一步解释,请告诉我.

Ily*_*syn 5

这样的解决方法怎么样?

.specialInstructionsNotes {
   padding-bottom: 30px; /* set padding for all special elements */
}
.specialInstructionsNotes + .specialInstructionsNotes {
   margin-top: -30px; /* but make the next element hide the bottom padding
                         of its preceding siblings of the same class */
}
Run Code Online (Sandbox Code Playgroud)