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

如何僅使用 CSS(無 js)選擇所有其他 div 類元素

How do I select every other div class element using just CSS (no js)(如何僅使用 CSS(無 js)選擇所有其他 div 類元素)
本文介紹了如何僅使用 CSS(無 js)選擇所有其他 div 類元素的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我知道如何使用 javascript 和 php 來做到這一點,但我正在嘗試了解如何/是否可以僅使用 css 來做到這一點.

I know how to do this using javascript and php, but I am trying to learn how/if it is possible to do this using just css.

我有一個裝有許多物品的容器.每個項目都有一張圖片,在圖片下方是一個包含描述的 div.我希望每個其他項目的描述背景都不同.

I have a container which holds many items. Each item has a picture, and below it, a div containing a description. I want the background of the description to be different for every other item.

是否可以僅使用 css 來實現?如果是這樣,怎么做?我一直在玩弄選擇器

Is it possible to achieve this using just css? If so, how? I have been fooling around with using the selectors

.item:nth-child(odd){background-color:red}
.item .description:nth-of-type(odd){background-color:orange;}

我好像聽不懂.建議,評論,任何東西都值得贊賞.
下面是一些簡化的示例代碼,演示了我正在做的事情.

I can't seem to get it. Suggestions, comments, anything is appreciated.
Below is some simplified sample code that demonstrates what I have going on.

<style>
#container{width:100% height:100%;}
.item {float:left; width:250px; height:700px;}
.item img {width:250px; height:250px; float:left;}
.description {width:250px; height:450px; float:left; background-color:blue;}
.description:nth-of-type(even){background-color:red;}      // <- Here's the line!!
</style>

<html>
 <body>
  <div id="container">
   <div class="item">       //item 1
    <img src="image.jpg"/>
    <div class="description"> //This (and every odd number) I want to be blue 
     <h1>Title</h1>
     <h2>Sub Title</h2>
     <p>Lorem Ipsum dolor sit for Adun!</p>
     <a href="#">::LEARN MORE::</a>
    </div>
   </div>
   <div class="item">      //item 2 and so on...
    <img src="image.jpg"/>
    <div class="description"> //and this (and every even number, red)
     <h1>Title</h1>
     <h2>Sub Title</h2>
     <p>Lorem Ipsum dolor sit for Adun!</p>
     <a href="#">::LEARN MORE::</a>
    </div>
   </div>
  </div>
 <body>
</html>

推薦答案

你想要 .item 上的 nth-child().

.item:nth-child(odd) .description {
    background-color: red;
}

演示:

這篇關于如何僅使用 CSS(無 js)選擇所有其他 div 類元素的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Style every third element?(每隔三個元素設置樣式?)
Why shouldn#39;t I use ID selectors in CSS?(為什么我不應該在 CSS 中使用 ID 選擇器?)
What does img[class*=quot;alignquot;] mean in CSS?(CSS 中的 img[class*=“align] 是什么意思?)
CSS: Last element on line(CSS:最后一個元素)
Tool for checking unused CSS selectors?(檢查未使用的 CSS 選擇器的工具?)
How to show the first N elements of a block and hide the others in css?(如何在css中顯示塊的前N個元素并隱藏其他元素?)
主站蜘蛛池模板: 狠狠插狠狠操 | 久久99精品久久久 | 亚洲视频在线看 | 日韩无| av在线天堂 | 亚洲免费观看视频 | 国产成人影院 | 男女深夜网站 | 91精品国产综合久久婷婷香蕉 | 夜夜精品浪潮av一区二区三区 | 亚洲精品免费观看 | 99精品国产一区二区青青牛奶 | 亚洲精品www久久久久久广东 | 99热热精品 | 免费看一区二区三区 | 国产精品一区二区三区在线 | 欧美成人免费 | 国产在线中文字幕 | 国产欧美日韩一区 | 中文字幕在线一区二区三区 | 一区二区免费看 | 日韩中文字幕免费在线观看 | 日韩视频一区 | 成人毛片视频免费 | 天天干天天爽 | 在线免费激情视频 | 国产在线一区二区三区 | 成人免费视频在线观看 | 天天操欧美 | 毛片一级黄色 | 亚洲精品中文字幕 | 欧美a级成人淫片免费看 | 亚洲精品大全 | 精品91久久久| 九九精品视频在线 | 亚洲精品久久久9婷婷中文字幕 | 人人艹人人| 欧美黑人巨大videos精品 | 欧美一二区 | 99热精品在线 | 久久久久久91香蕉国产 |