Parent selector does not exist in CSS3. For this, it is recommended to use the CSS4 selector $, which might look like this (selecting the li element) -
ul $li ul.sub { ... }
As an alternative, using jQuery, you can achieve this functionality with a single line of code. The :has() selector selects all elements that contain one or more elements that match the specified selector.
$('ul li:has(ul.sub)').addClass('has_sub');
You can add styles to li.has_sub in CSS.
The above is the detailed content of If the parent has a child with CSS and HTML, apply styles to the parent. For more information, please follow other related articles on the PHP Chinese website!