Can someone please clarify how the nth-of-type selector functions?

I can't understand why the nth-of-type selector needs to be set to 2 instead of 1 for the first sibling of this type in the code.

To see the code in action, check out this jsfiddle: https://jsfiddle.net/xj5hvn16/

If anyone could kindly provide an explanation, I would greatly appreciate it.

.flowbox .utm_registrars_code:nth-of-type(2) {
  background-color: red;
}
<div class="flowbox freebox">
  <div class="pholdcard18"></div>
  <div class="flowcard14 utm_registrars_code">
    <div class="content">
      Content 1
    </div>
  </div>
  <div class="flowcard14 utm_registrars_code">
    <div class="content">
      Content 2
    </div>
  </div>
  <div class="flowcard14 utm_registrars_code">
    <div class="content">
      Content 3
    </div>
  </div>
</div>

Answer №1

It's important to note that the nth-of-type selector targets the first element of a specific type, such as a div, rather than the first element with a particular class.

The :nth-of-type() pseudo-class applies to an element that is part of a group of elements with the same parent and element name, based on a specific mathematical formula.

For more information, check out these resources:

Answer №2

nth-of-type should not be confused with nth-of-class!

The initial occurrence of div is

<div class="pholdcard18"></div>   

As a result, your Content 1 element is considered the second and emphasized.

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

Error: Codeigniter AJAX endpoint cannot be located

While working on an ajax call in CodeIgniter using the .ajax function, I encountered a problem. My controller is named Control and it has a function called Login. When I try to execute this code: $.ajax({ url: "Connection/Login", type: " ...

Generate an image, PDF, or screenshot of a webpage with the click of a button

I've been searching for a solution that would enable users to click a button and save an image or PDF of the current page. The content on the page is dynamic and dependent on user input, resulting in sequences displayed in various colors. I'm loo ...

Discovering the center of an element and implementing a left float

I'm looking for a way to dynamically position the element #ucp_arrow in the middle of a div using float: left. Here is an illustration: https://i.stack.imgur.com/nzvgb.png Currently, I have hard-coded it like this: JAVASCRIPT: $("#a_account").cli ...

Ways to apply CSS styles dynamically within a v-for loop

Despite searching through the VUE official website and various other sources, I have not been able to find a satisfactory solution. I am reaching out for assistance, thank you in advance. <div class="tag-item" :ref="`tagItem_ ...

JavaScript detecting improper XHTML syntax

Is there an effective method to detect malformed XHTML within a string using JavaScript? Given that my page allows user-generated XHTML (from trusted users) to be inserted into the DOM, I aim to identify unclosed or overly closed tags. If found, I intend ...

What are the best techniques for resizing a Text Field with media queries?

The contact form is responsive and functioning correctly for the textarea field, but there are issues with the input type=text fields on smaller screens. I attempted to address this by incorporating media queries. Below is my code: <!doctype html> ...

Python Flask login application failing to redirect to login page

Currently, I'm building a login application with Python Flask and MongoDB integration at the backend. While everything else seems to be running smoothly, there's an issue with redirecting to the login page upon login. # See below for my code @ap ...

the neighboring div sliding to the left causing the div not to expand with its content

I am trying to create a website similar to this one. When I click on the arrow, the left div collapses and the right one expands. However, the content of the right div does not expand as expected! Below is my HTML code: <div class="tools-bg"> & ...

Utilize drag and drop functionality to interact with an HTML object element

I am struggling with a div that contains a PDF object and draggable text: <html> <head> <script> function allowDrop(ev) { ev.preventDefault(); } function drop(ev) { alert("DROP"); } </script> </head> <body> <di ...

I updated the color of my a:link using jQuery, but now my a:hover is not functioning as expected

Due to the readability issues of the navigation color against a specific image, I am looking to modify it for a particular page. Below is the HTML code: <div id='nav'> <ul> <li id='navBiog'> ...

There are three checkboxes, one of which is independent of the others and requires jQuery to not consider it part of the collection

Initially, I crafted a query that perfectly met the business requirement until there was a change of heart. Uncheck checkbox if checked with jquery The implementation of this code was flawless $('input[type="checkbox"]').on('change' ...

Differences between Animation Easing in iOS and CSS3 Cubic Bezier Functions

I am currently working on an iOS app and I am trying to improve the animations within it. Having a lot of experience with CSS3 animation and transitions, I want to be able to define my animations in iOS with the same precision that is possible with CSS3 ( ...

The default setting for my bootstrap modal is displayed, not hidden

Is there a way to make my bootstrap model hidden by default and only visible when I click on a link? I'm new to web development and would appreciate any help. tst.html <!DOCTYPE html> <html lang="english"> <head> < ...

Using JQuery Mobile to Incorporate Links into List Elements

Creating a mobile webpage tailored for college students involves assigning each student a unique id and an additional field. Both fields can be treated as strings, with the unique id being guaranteed to be unique, while the second field may or may not be u ...

Retrieve the value of a dynamically added or removed input field in JQuery using Javascript

Check out this informative article here I'm looking for a way to gather the values from all the text boxes and store them in an array within my JavaScript form. I attempted to enclose it in a form, but I'm struggling to retrieve the HTML ID beca ...

Adding Tooltips to Your Bootstrap 5 Floating Labels Form: A Step-by-Step Guide

Can you include tooltips or popovers in Bootstrap 5 floating labels text? I've set up a form with floating form fields and I'd like to provide instructions for certain fields using tooltips or popovers. I can make it work with the standard form ...

Making a CSS table fit perfectly inside a container

After reading numerous recommendations on the subject, none of them seem to be effective in my particular situation. The issue lies with a table that is nested within a container ('div' element) as shown below: <div class="container"> ...

When hovering over slick text, it becomes hidden because of non-responsive CSS. Are there any solutions to make it responsive?

I can't seem to get the on-hover dates to appear, even though they are rendered when inspecting the page. I suspect it could be related to a responsive CSS issue or class breaking. How can I resolve this? https://i.stack.imgur.com/jyEJb.png https:// ...

Height of the image is being boosted while the width remains consistent

When working on a responsive page layout, I encountered an issue with increasing the height of an image while keeping the width constant. Modifying the width of the image reflects changes, but adjusting the height does not seem to make any difference. I t ...

`Is it possible to modify the background color of InputAdornment in Material-UI TextField?`

For the first 10% of the text field, one background color is used, while for the remaining 90%, another background color is applied. <TextField className={classes.root} type="text" placeholder="username" var ...