CSS formula to target each 5th and every 7th element using the nth-child selector

Currently working on a CSS3 hexagon pattern and aiming for a specific look;

The hexagons are set to float:left within a fixed width body. To achieve the design in the link above, I need to target the first element in every other row. What would be the formula using nth-child for that?

Essentially, looking to select the 5th element, followed by every 7th element after that?

Answer №1

The CSS rule to select every 7th element starting from the 5th element is written as :nth-child(7n+5). The selector 7n specifies "every 7th element", while +5 indicates "starting from the 5th element".

For more information, refer to the Selectors specification on :nth-child().

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

Changing the color of the selected item in a Jquery Mobile ListView

I have a dynamic list that triggers a JavaScript function using the onclick event. However, I am struggling to change the color of the selected item in the list. Here is an example of the code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional ...

When state updates in React, the component will rerender without affecting its style

There seems to be a minor oversight on my part. The issue arises in the parent component where I maintain a state of selected items, which are added from the child component. The background color of the child component changes when an item is selected. Ad ...

Is there a way to ensure that the size of the second div box can adjust dynamically in CSS?

Is there a way to make multiple boxes expand dynamically in size when one of them contains more words? Currently, the problem is that only the box with more text expands while the others remain unchanged. I want all the boxes to follow the same size dynami ...

Tips for modifying the height of a div using cssText with a JavaScript variable

let height = Math.floor((Math.random()*100)+50); document.getElementById("child").style.cssText="background-color: red; height: " + height + "px; width: 100px;"; ...

The voting system will increase or decrease by 1 to 5 during each round

Recently, I added a voting system to my website inspired by this source. It's functioning well, but there is an issue where each vote can sometimes count for more than one. You can view the source code on the original website and test it out live here ...

Selenium is having trouble extracting the text through By.CLASS_NAME

Every time I attempt to scrape the HTML of a webpage, I encounter the same issue: selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: An invalid or illegal selector was specified I am aware that selenium has changed the method ...

Develop a custom WordPress meta box for managing the color scheme of individual posts and pages

Currently, I am in the process of learning how to create a custom WordPress meta box with a select tag for controlling the color scheme of individual posts/pages. My goal is to implement a system where I can use if statements to load an additional CSS file ...

Utilize Bootstrap for EF Core pages with pre-designed scaffolds - text will remain neatly displayed within textbox without the need for inline CSS word-wrap styling

After generating CRUD pages using EF core, I am now attempting to make edits to one of the cshtml files. The default Bootstrap CSS file that I am using includes various CSS class definitions: .row { display: -ms-flexbox; display: flex; -ms-flex-wrap: ...

Modify the select input's border color when it is in focus

My select input's focus color is not changing, and I'm struggling to figure out the proper override. .form-control:focus { border-color: inherit; -webkit-box-shadow: none; box-shadow: none; } .forma #kome { border-color: #8e8e8e; -w ...

HTML5 input placeholder adapts its size and position dynamically as data is being

During my interaction with the input fields on my bank's website, I noticed that the placeholder text undergoes a unique transformation. It shrinks in size and moves to the upper-left corner of the input field while I am entering information. Unlike t ...

Enhance drop-down menus in Bootstrap 4 by making the entire li area clickable

Currently working on a complex bootstrap 4 menu button with multiple levels and encountering an issue with the selectable area. To demonstrate the problem, I have marked the current clickable area with black borders and highlighted the desired clickable a ...

"Customize the appearance of your theme by adjusting the background and text colors when making a

Is there a way to dynamically change the style of a webpage based on user selection using CSS in AngularJS? I've searched online, but haven't found a solution that works for me. I have a CSS file with different styles and I want to apply these ...

How to Style Your ASP.NET Website: Utilizing a Stylesheet with Visual Studio 2010

I am having trouble adding a stylesheet to the master page of my asp.net web form. I want to create an inline navigation menu at the top of the page, but I can't seem to get it working. I have created the stylesheet in the same way I would for an HTML ...

Arranging mat-checkboxes in a vertical stack inside a mat-grid-tile component of a mat-grid-list

I'm looking to create a grid list with 2 columns, each containing 2 checkboxes stacked vertically. While I found this helpful question, it still involves a lot of nested divs. Is there a cleaner way to achieve this layout? Here's how I currentl ...

Automatically populate login credentials on a webpage using Javascript scripting

Can anyone provide insights on why the input credentials on a webpage cannot be autofilled with this code? Is there a solution to make it functional? Trying to automate login process using JavaScript: function Test() { var name = document.getElementBy ...

Using compound class selectors in RobotFramework with Selenium to target specific elements

Attempting to monitor the on-screen status of an element that transitions from : class="slide-out-div contrastBoxDark closed" to class="slide-out-div contrastBoxDark" however, when using Page Should Contain Element class:slide-out-div.contrastBoxDa ...

Do you know of a solution to fix the Stylelint error regarding semicolons when using CSS variables?

React.js Css in JS(Emotion) The components above are part of this setup. Here is the configuration for Stylelint: module.exports = { extends: [ "stylelint-config-standard", "./node_modules/prettier-stylelint/config.js", ], ...

The CSS styling fails to load for the second container on NextJS

I am facing a problem with styling two div containers using CSS imported from a separate file. The first style is applied successfully using the className property, but the second one is not working as expected. Despite having defined the 'sales' ...

displaying a new image in a separate window while remaining in the current container

I am attempting to find a solution to create a page where the user can click on an image to open it while still keeping the other images available as options. I hope my explanation is clear enough for you to understand. The code might look something like ...

`Ineffectiveness of CSS media query for font-size adjustment in HTML selector`

I recently implemented the 62.5% trick to adjust my font-size for various screen sizes. However, I noticed that on larger screens, the text appears too small. To address this, I tried increasing the font-size to 80% using a min-width media query. Unfortuna ...