HTML/CSS debugging on Codecademy

Can someone help me out with this issue I'm facing? I'm struggling with an nth-child statement in my code. Below is the HTML and CSS I'm working with. This problem has been holding me up in the "CSS Selectors 23/23" lesson on Codecademy:

HTML:
<body>
<h3 class="fancy">Blah Blah Blah </h>
 <p class="fancy">Blabbidy Blah</p>
 <p id="serious">Bling Bling</p>
 <p> problem child</p>
</body>

CSS:
body :nth-child(4) {
font-size: 26px;
}

Answer №1

When using the p:nth-child(4) selector, you are actually trying to select the fourth paragraph element on the page, not the fourth sibling of the body. It's important to note that there should be no space between the element-selector and the pseudo-selector. Additionally, ensure that your h3 element is closed correctly.

If you intended to style the fourth paragraph element, your code should look something like this:

p:nth-child(4) {
  font-size: 26px;
}
<body>
  <h3 class="fancy">Blah Blah Blah </h3>
  <p class="fancy">Blabbidy Blah</p>
  <p id="serious">Bling Bling</p>
  <p>problem child</p>
</body>

Answer №2

Remember, choose the p element

p:nth-child(4) {
  font-size: 26px;
}
<body>
  <h3 class="fancy">Blah Blah Blah </h3>
 <p class="fancy">Blabbidy Blah</p>
 <p id="serious">Bling Bling</p>
 <p> problem child</p>
</body>

Answer №3

The issue you are experiencing is a result of not properly closing the h3 tag.

To resolve this, simply fix the closing tag and the current selector will function correctly.

body :nth-child(4) {
  font-size: 26px;
  color: red;
}
<h3 class="fancy">Blah Blah Blah </h3>
<p class="fancy">Blabbidy Blah</p>
<p id="serious">Bling Bling</p>
<p>problem child</p>

If the tag is left unclosed, the browser will automatically close it for you after processing other elements, resulting in issues with selecting the 4th child of the body. You can see an example of this behavior in this JSFIDDLE.

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

Do not include screen-lg in Bootstrap 3

Hey there! I'm looking to exclude the large breakpoint from Bootstrap 3 but I'm not sure how to begin. Any suggestions? ...

What could be causing this code to malfunction in Internet Explorer 7?

Code: Demo: In the majority of modern browsers such as Safari, Chrome, Firefox, and IE8/9, the code works perfectly fine. However, there seems to be an issue with IE7, causing it not to work. Any idea why this might be happening? My goal is for the conte ...

Modify the information within several div sections

Is there a way to update the content inside two divs simultaneously when a button is clicked? Specifically, I want to change the bio in one div and the picture in another based on the selected player. Currently, when the button is pressed, it only loads th ...

Expanding Your Django Template Abilities

Dealing with a fairly simple issue here. I've got a web page template that includes some common CSS styles at the top. <html> {% load static %} <link rel="stylesheet" type="text/css" href="{% static 'css/index.css' %}"> .... *n ...

Guide to adjusting column size across various screen resolutions using Vuetify grid

For my Vue and Vuetify dashboard, I have opted to use the grid system in Vuetify's library to structure the layout. However, I am encountering an issue where the appearance varies depending on the screen resolution. Is there a way to keep the left con ...

Changing the background color within an *ngFor loop using Angular 2's ng-style

Looking to add unique background colors using ng-style. Each row in the list is created with ngFor, giving each item its own distinct background color. <ion-item class="category-list" *ngFor="let item of character['items']"> <ion-ava ...

Manipulate text within a text area using jQuery

Good afternoon. How can I use JavaScript to update the text in a textarea input? I currently have some content in my textarea that includes a PublisherImprintName tag, and I want to remove it using jQuery. <PublisherInfo> <PublisherName>A ...

Missing 'id' property in ngFor loop for object type

I'm currently learning Angular and I've been following a code tutorial. However, despite matching the instructor's code, it doesn't seem to be working for me. When I try to compile the following code, I receive an error message stating ...

Difficulties with vertical scrolling on mobile devices due to the use of "-webkit-overflow-scrolling: touch"

In the midst of creating a new mobile website design that is responsive, an issue arose during testing on my phone. It seemed impossible to scroll vertically past a certain point if there was horizontal scrolling involved. To better illustrate this proble ...

CSS - Combining Selectors and Pseudo Classes to Boost Styling

When it comes to grouping selectors in CSS, there is an easy way to do it like this: .class1 #id1, .class2 #id2, .class3 #id3 { } Applying pseudo classes on these grouped selectors can be a bit repetitive. Is there a method to group multiple selectors a ...

Display a message indicating unavailability when no events are scheduled and adjust the background color in FullCalendar

In one of my projects, I am utilizing jQuery FullCalendar to schedule appointments for doctors. The doctors should be able to specify their availability between 9 AM - 5 PM on weekdays. If this is not set, the background color of the spans of time not boo ...

How can we start redirecting to the 'middle of the page' using php?

After successfully registering a user, I want to redirect them to a 'success' page. The issue is that headers have already been sent at this point, so calling header() directly won't work. My workaround was to create an included file (let&a ...

How can you create an accordion menu that expands when a button is clicked?

Is there a way to make an accordion menu open when the 'More' button is clicked? I've tried, but it always starts in its expanded state and collapses when the button is clicked. What I really want is for the accordion to be closed initially ...

Give a class to the element contained within an anchor tag

One way to add a class to the <a>-tag is through this line of code. $("a[href*='" + location.pathname + "']").addClass("active"); However, I am looking to add the class to an li element inside the <a>-tag. What would be the best ap ...

What is the best way to apply a background color to text seamlessly? (Using HTML5 and CSS3)

<!-- 6장 연습문제 4 --> <html lang = "ko"> <head> <meta charset = "UTF-8"> <style> img{margin-left: auto; margin-right: auto; display: block;} .hyper{ text-decoration-line: ...

Filtering stop words in Python through HTML parsing using Beautiful Soup

I have developed a program that extracts specific information from a website and stores it in a file. Currently, the program scans a webpage, identifies the correct HTML tag, and extracts the relevant content. Now, I aim to refine these "results." For ins ...

Can I use Javascript to access a span element by its class name?

Similar Question: How to Retrieve Element By Class in JavaScript? I am looking to extract the text content from a span element that does not have an ID but only a specific class. There will be only one span with this particular class. Can anyone guide ...

Ensuring that your content spans the entire viewport is crucial for optimizing

https://gyazo.com/1440b13007c6e011ec46218ceecabb6a Upon examining the screenshot, it is evident that there is a white border surrounding the main content of the page. Despite my attempts to adjust everything to 100% width, I have not been success ...

Can the text inside a div be styled to resemble h1 without using an actual h1 tag?

Is it feasible to apply the h1 style to all text within a div without utilizing tags? For instance: <div id="title-div" style="h1">My Title</div> Or a potential solution could be: #title-div { style: h1; //Imports all s ...

"Vanishing Act: Bootstrap menu vanishes after a click

Having difficulties with the menu on my website wrapster.sebastianbialek.pl. Whenever I resize the browser to mobile version and click on the collapse button, the menu shows up briefly and then disappears. Any assistance in resolving this issue would be gr ...