CSS selector for a parent element that has no child elements

I'd like to create a selector that targets all <li> elements containing an empty <p> element:

li>p:empty {
  display: none;
}
<li>
  <p>Size</p>
  <p></p> <!-- empty -->
</li>

<li>
  <p>Color</p>
  <p>Blue</p> <!-- NOT empty -->
</li>

Can this be done?

Answer №1

Absolutely! Just to clarify- the correct pseudo class to use is :empty and not :blank:

li>p:empty {
  display: none;
}
<li>
  <p>Size</p>
  <p></p> <!-- blank -->
</li>

<li>
  <p>Color</p>
  <p>Blue</p> <!-- NOT blank -->
</li>

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: The term "Image" is unrecognizable

I'm in the process of creating a website where I want to display images via links. If the image is missing or only 1 pixel wide, I need the site to show an alternative image. My technology stack includes Jade/Pug and JS. Before rendering the links on ...

Using HTML within a JSON string in Java

I need to save the contents of a Java class called MyClass into a text file using JSON for encoding, instead of implementing the Serializable interface. I plan to utilize Google's Gson library, specifically the JsonWriter class. The structure of the M ...

Boost the scrolling velocity of my sidebar using Jquery

Hello there, I am completely new to the world of web development and particularly to using JavaScript and jQuery. I am interested in learning how to adjust the speed at which my Sidebar scrolls down as the user navigates through the page. Here is the jQue ...

String of text that appears differently in certain browsers

There seems to be a mysterious line appearing under the text inside a specific div. This issue is only noticeable on Firefox and IE browsers. Take a look at these screenshots; I am using the entire div as a link: Here is the structure of the divs and te ...

Is separating Jssor Slider CSS effective?

Having a bit of trouble with the Jssor slider here. I'm trying to separate the slider styles into an external CSS document and running into issues. For instance: <div id="slider1_container" style="position: relative; top: 0px; left: 0px; width: 11 ...

modifying the child divs contained in the main div

Hey there! I'm currently using Bootstrap to design an application and I've got the entire form inside a container. However, as I add more child elements within the container div, I would like the parent div to expand automatically to show all the ...

iOS 7 users experiencing webpage crashes

UPDATE: Success! After some trial and error, I discovered that iOS 7 is not compatible with vh units. I switched to using JavaScript for detecting the browser height, and now my website works flawlessly on iOS 7. I recently created a website that function ...

Is it Possible to Load Images Without Using Javascript?

When I hover over certain links on my HTML pages, large images are displayed but take a while to load. I prefer not to use JavaScript to preload the images. Are there any alternative solutions available? ...

What is the method to display my input value within my application interface rather than triggering an alert popup?

Hi there, I am seeking assistance with my GUI code. I want the input value to be displayed as text on the screen, or even better, to look like a chatroom so that I can integrate a simple chatbot later on. My main goal is to have the texts show up in the bl ...

Solving the Cross-Origin Resource Sharing problem in AngularJS

While using the http dependency in AngularJS and setting headers for CORS, I am encountering an error. Please check the console.log for more information on the error. The error message reads: "XMLHttpRequest cannot load . Response to preflight request doe ...

With FlexLayout, the content compresses rather than shrinking and taking up the entire width

When utilizing Angular and the flex Layout to develop a dashboard, I am encountering an issue where the items do not shrink as expected when opening the navigation. This results in the last item being pushed to the next line. Below is the HTML for the pare ...

Having trouble identifying the CSS style being applied to a specific element

In this image, a red border is seen on the input fields indicating an error with some CSS style being applied. Despite this, it is difficult to determine which CSS selector is causing this as Firebug does not reveal any applied styles. https://i.stack.img ...

Arrangements of lines in website design for various screen resolutions

I am having an issue with the layout I'm working on - specifically, there is a visible outline of the div boxes at certain resolutions or when zooming in. This is what it should look like: However, this is how it appears at some resolutions or when ...

Utilizing PHP to share content on Facebook

I am encountering an issue on a particular page of mine where there are multiple images. Each image has its own share and like button. When I click on the share button, I expect to share that specific image but it is not working as expected. Can someone pl ...

Refresh the page excluding any <script> elements

I am looking to display a page without actually running its JavaScript code, while also injecting my own script and providing the user with a perspective similar to that of a bot. One approach I have considered is loading the page via ajax, stripping out ...

Retrieve the current domain name (server name) within a Shiny application

I am managing 3 servers - alpha, beta, and gamma. The goal is to deploy my Shiny code from the alpha server to the gamma server. However, I encounter a challenge. In my ui.R file, I reference another site called start using href = 'https://alpha.com/ ...

Avoid abrupt image flickering when the source is being changed

I'm encountering an issue with image flickering when using large images. Within my body, I have a set of 5 images: <img id="img1" src="img1.png" width="250"> <img id="img2" src="img2.png" width="250"> <img id="img3" src="img3.png" widt ...

New space is formed as the input box gains focus on the signin field

I'm currently working on a sign-in page and implementing JQuery. Everything seems to be functioning properly except for a minor issue. The problem is that when the password field gains focus, it creates extra space in IE 8 and later versions only. Th ...

Using an External Stylesheet with Polymer 2.0: A Step-by-Step Guide

I am still learning the ropes, so please bear with me... Currently, I am attempting to customize a Polymer 2.0 custom element by utilizing an external stylesheet. However, for some reason, the styles from the external stylesheet are not being applied to t ...

Retrieving Data Attribute From Form Using Python Flask

Is there a way to retrieve data from a POST request in Flask that is not the standard text field value? I am looking for a solution that does not involve using JavaScript, but rather only Python. Let's consider a simplified example: I need to extrac ...