Home > Article > Web Front-end > CSS sub-selector (6)_html/css_WEB-ITnose
The front and back parts of the sub-selector are separated by a greater than sign. The two parts of the selector are structurally a parent-child relationship.
The child selector is based on the parent element specified by the left selector, and then looks for child elements matching the right selector under the parent element.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>子选择器</title><link type="text/css" rel="stylesheet" href="css/demo5.css"/></head><body><div> <p>这是个段落 <a href="#">这是超连接</a> </p></div></body></html>
@charset "utf-8";/* CSS Document *//*设置div下的p元素的样式*/div>p{ font-size:14px; color:#0000FF; }/*设置p元素下的a元素的样式*/p>a{ font-size:16px; color:#FF0000; text-decoration:none;}/*错误的写法 div 与a不是父子关系时,是取不到的*/div>a{ font-size:20px; color:#FF0000; text-decoration:none;}
The sub-selector is very Rarely used, generally use containing selections that are not affected by the parent-child relationship
The following writing contains the selector
div a{ font-size:20px; color:#FFFF00; text-decoration:none;}