What methods can be used to choose specific rows while styling columns with CSS?

As an exercise in CSS styling, I have successfully transformed an unordered list into columns. But now, I am curious if it is possible to target and style the "rows" within these columns.

This is the CSS code currently in use:

ul.popular{
    margin:15px 0 30px;
    padding:0;
    list-style:none;
    -moz-columns:3;
    -webkit-columns:3;
    columns:3;
    -moz-column-gap:0;
    -webkit-column-gap:0;
    column-gap:0;
    list-style-position:inside;
    -moz-column-fill:balance;
    column-fill:balance;
    -webkit-column-break-inside:avoid;
    page-break-inside:avoid;
    break-inside:avoid;
    border-top:solid 1px #d2d3d4;
    border-left:solid 1px #d2d3d4
}
 ul.popular li{
    padding:10px 15px;
    border-bottom:solid 1px #d2d3d4;
    border-right:solid 1px #d2d3d4;
    display:block
}
 ul.popular li a{
    display:block
}

Associated HTML markup:

<ul class="popular">
    <li>Australia to Fiji</li>
    <li>Australia to Papua New Guinea</li>
    <li>Australia to Solomon Islands</li>
    <li>Australia to Tonga</li>
    <li>Australia to Vanuatu</li>
    <li>New Zealand to Fiji</li>
    <li>New Zealand to Papua New Guinea</li>
    <li>New Zealand to Solomon Islands</li>
    <li>New Zealand to Tonga</li>
    <li>New Zealand to Vanuatu</li>
    <li>United States of America to Fiji</li>
    <li>United States of America to Samoa</li>
    <li>United States of America to Tonga</li>
</ul>

Link to Fiddle demonstration:

https://jsfiddle.net/cbkx1hLm/

My query lies in figuring out how to apply different background colors to every second "row." Essentially, trying to target every second item within each column.

I've experimented with nth-child(2n), variables, odd/even selectors, among others, but haven't achieved the desired outcome yet.

Answer №1

UPDATE: The question has been revised, now focusing on the selection of "rows", and includes a functional demo.

However, upon reviewing the provided sample:

https://i.stack.imgur.com/J62bU.png

It is not clear where the rows are located, and the "US to Fiji" entry is divided between two columns, making it challenging to apply distinct colors to each part.

Moreover, the layout may vary significantly based on window width, font size, etc.

It appears that utilizing a table structure might better meet your requirements.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips on updating the color of the drawer component's background in Material-UI using React

I have been attempting to change the background color of a drawer component in React, but I have only been successful in changing the background behind the drawer or the field with the items. Here is the code I am using: const useStyles = makeStyles({ ...

Attempting to trigger the timer to begin counting down upon accessing the webpage

Take a look at this example I put together in a fiddle: https://jsfiddle.net/r5yj99bs/1/ I'm aiming to kickstart as soon as the page loads, while still providing the option to pause/resume. Is there a way to show the remaining time as '5 minute ...

"Step-by-step guide on creating a dynamic clipping mask animation triggered by mouse wheel

I have developed a sample that functions just as I envision my final outcome to function, with the exception of triggering on mouse-over. Instead, I would like it to activate as a page transition when scrolling with the mouse. (move your cursor over the i ...

Issue with the JQuery FadeIn effect on my website when a div is repositioned for visibility

I have been working on revamping an existing website at www.gjelavoie.com. To enhance the user experience, I decided to use jquery fadein() and fadeout() functions for displaying my Contact form without visitors having to temporarily access the main page. ...

Exploring ways to validate the existence of a class in HTML table elements

If I want to verify if each element has a specific class when creating tables and clicking on the corresponding cells above them, This is what I have tried. However, it did not work as expected. How can I make this work correctly? What am I missing her ...

Creating a row with 5 columns in Bootstrap 4 dynamically is a handy trick for enhancing the layout of your website

Struggling to find the right layout for displaying products on my store's home page. <div class="row"> @foreach($produts as $product) //this is the syntax of my templating engine <div class="col-md-3"> </div> @endf ...

What is the best way for me to make sure the element overflows properly?

How can I make the contents of the <div class="tags> element cause overflow so that one can scroll its contents instead of the element simply extending in height? I've experimented with different combinations of overflow-y: scroll and min- ...

Ways to utilize the ::after pseudo class with ElementRef within Angular

Is it possible to manipulate the background-color of the ::after pseudo selector for the specified element using Angular? @ViewChild('infobubble', { read: ElementRef }) infoBubbleElement: ElementRef; ngAfterViewInit(): void { const el ...

Adding a gap between the Bootstrap navbar and jumbotron for better spacing

Upon examining the Bootstrap example provided at: http://getbootstrap.com/examples/navbar/ I noticed there is a gap between the jumbotron and the navbar. After delving into the example's CSS, I found that disabling this rule (twice): .navbar { ...

The fundamental principle of starting with mobile design in Bootstrap

I'm struggling to understand the concept of "mobile first default behavior" in Bootstrap 3. If there is no breakpoint at 480px, how can Extra small devices be the default? I get that it applies to font sizes, but what about the grid system? How can I ...

How to position a div in the center of another div using HTML

I'm struggling to center the bottom div within a container that includes 3 other divs. Despite trying multiple solutions found online, nothing seems to work. This task should be simple, but for some reason, I can't get it right. .container { po ...

Incorporating an iframe seamlessly into a div element with scroll functionality

To start off, you can find the code in this JSFiddle link I am attempting to include an iframe as if it were a div. I understand how to do this with a regular iframe, but the one I am using contains a slider, resulting in two vertical scroll bars appearin ...

Can anyone suggest a method to customize the appearance of select options in Vue.js?

https://i.sstatic.net/qNov8.png Is there a way to customize the color and font of select options? I'm referencing this link for an example: . I attempted CSS modifications but they don't seem to be taking effect. ...

Upgrading Bootstrap from version 3.4 to 5.3 in a .NET project

I have a website project created using .Net Framework 4.7.2. Currently, I am utilizing Bootstrap version 3.4.1 from here. Since Bootstrap 3.4 is now in an end-of-life phase, I need to upgrade to the latest version, 5.3. Upon replacing the old version fil ...

Twice the clicking actions triggered by the event

Whenever I try to trigger a function by clicking on the label text, the click event seems to be firing twice. HTML <label class="label_one"> Label One <input type="checkbox"/> </label> However, if I modify the HTML code as f ...

For Flexbox front end design, the left side should be contained within a container while the right side should seamlessly stretch across the

I'm facing a challenge in designing a website with a unique layout that has left me puzzled. I've created a codepen example to showcase what I'm trying to achieve. Specifically, I need to implement a Hero Banner on top of a standard 1200px ...

Content sliding to the left due to modal prompt

I've searched through various questions and answers but haven't been able to resolve this issue. There's a modal on my page that is causing the content to shift slightly to the left. I've created a sample fiddle, although it doesn&apo ...

Navigate the div with arrow keys

Looking for an answer similar to this SO post on moving a div with arrow keys, could a simple and clear 'no' be sufficient: Is it possible to turn an overflowing div into a "default scroll target" that responds to arrow-up/down/page-down/space k ...

What is the best way to set up a side-opening feature in the UI design?

I am having trouble with the Amoclan shape transitioning to the next side. I need the transition to occur exactly as specified in the documentation, but for some reason it is still moving on to the next side. <html> <head> <script src=" ...

Blurring the background creates an "inset shadow" problem when transitioning

Problem: Strangely, when using Backdrop-filter: blur(Xpx); during a transition as shown below, unexpected "inset Shadows" mysteriously appear until the end of the transition. https://i.stack.imgur.com/uij7F.gif Illustration of the Issue Using jsfiddle Sp ...