久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

nth-child 中奇數/偶數子元素的問題

Problem with odd/even child elements in nth-child(nth-child 中奇數/偶數子元素的問題)
本文介紹了nth-child 中奇數/偶數子元素的問題的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個這樣的網站:

<html xmlns="http://www.w3.org/1999/xhtml"><頭><標題></標題><link rel="stylesheet" type="text/css" href="article_style.css"/></頭><身體><div 類="節"><!--<h1>標題</h1>-->

段落</div>

段落</div>

段落</div></div><div 類="節">

段落</div>

段落</div>

段落</div></div></身體></html>

這是 CSS:

div.section{邊框:1px純黑色;}div.section div:nth-child(偶數){顏色:綠色;}div.section div:nth-child(奇數){紅色;}

結果如下:

這沒關系,因為在 each 部分中,奇數 div 為紅色,偶數為綠色.但是當我在第一部分的開頭添加標題時(示例中的注釋代碼)我得到了這個:

我不想那樣.我希望像以前一樣,但只是在第一部分有一個標題.所以首先是標題,然后是紅色段落.

解決方案

使用 nth-of-type 改為:

現場演示

div.section{邊框:1px純黑色;}div.section div:nth-of-type(偶數){顏色:綠色;}div.section div:nth-of-type(奇數){紅色;}

I have a web site like this:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link rel="stylesheet" type="text/css" href="article_style.css" />
</head>
<body>
    <div class="section">
    <!--<h1>header</h1>-->
        <div>
            paragraph
        </div>
        <div>
            paragraph
        </div>
        <div>
            paragraph
        </div>
    </div>
    <div class="section">
        <div>
            paragraph
        </div>
        <div>
            paragraph
        </div>
        <div>
            paragraph
        </div>
    </div>
</body>
</html>

and this is CSS:

div.section
{
    border: 1px solid black;
}
div.section div:nth-child(even)
{
    color: Green;
}
div.section div:nth-child(odd)
{
    color: Red;
}

And this is the result:

This is OK because I get red for odd div and green for even in each section. But when I add header at the begginig of first section (commented code in sample) I get this:

I don't want that. I want the to have like before, but just with a header in first section. So at first header and then red paragraph.

解決方案

Use nth-of-type instead:

Live Demo

div.section
{
    border: 1px solid black;
}
div.section div:nth-of-type(even)
{
    color: Green;
}
div.section div:nth-of-type(odd)
{
    color: Red;
}

這篇關于nth-child 中奇數/偶數子元素的問題的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

CSS selector when :target empty(:target 為空時的 CSS 選擇器)
Does the CSS direct decendant (gt;) not have any value in selectivity?(CSS 直接后代 (gt;) 在選擇性方面沒有任何價值嗎?)
Using querySelectorAll(). Is the result returned by the method ordered?(使用 querySelectorAll().方法返回的結果是否有序?)
Safari bug :first-child doesn#39;t update display:block when items are removed with JS(Safari 錯誤:當使用 JS 刪除項目時,first-child 不更新 display:block)
nth-Child CSS selectors(nth-子 CSS 選擇器)
Using same ID for multiple HTML tags?(對多個 HTML 標簽使用相同的 ID?)
主站蜘蛛池模板: 国产成人精品免费视频 | 久久久久久久久国产成人免费 | 久久精品免费看 | 免费看一区二区三区 | 激情国产视频 | 视频二区国产 | 免费在线看黄视频 | 久草视频在线播放 | 精品国产视频 | 亚洲欧美一区二区三区情侣bbw | 国产精品一区二区三区四区 | 在线免费观看a级片 | 久热精品在线 | 中文字幕在线精品 | 超碰导航| 久久精品国产精品青草 | 日韩欧美在线观看 | 手机看片在线播放 | 国产精品美女 | 一级黄色影片在线观看 | 欧美一区2区三区4区公司 | 国产午夜三级一区二区三 | 久久成人一区 | 亚洲福利 | 欧美国产日韩精品 | 狠狠的日 | 欧美日韩视频在线 | 亚洲不卡在线视频 | 亚洲国产高清免费 | 日本在线一二 | 国产91久久久久久久免费 | 91精品国产乱码久久蜜臀 | 日韩欧美视频在线 | 一区二区高清 | 91视频正在播放 | 一级黄色录像毛片 | 欧美h视频| 亚洲欧美中文日韩在线v日本 | 欧美视频一区二区三区 | 最新国产视频 | 在线一区二区三区 |