Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html can';t使用第一个子css设置显示_Html_Css - Fatal编程技术网

Html can';t使用第一个子css设置显示

Html can';t使用第一个子css设置显示,html,css,Html,Css,我正在使用wordpress及其生成的代码: <aside class="left-hand-column"> <div class="textwidget"> <p></p> ...1 <div class="pdf-download"> <p> ... 2 <a href="http://www.kusuma.ee-web.co.uk/wp-content/uploads/2016/0

我正在使用wordpress及其生成的代码:

<aside class="left-hand-column">
 <div class="textwidget">
  <p></p> ...1
   <div class="pdf-download">
    <p> ... 2
     <a href="http://www.kusuma.ee-web.co.uk/wp-content/uploads/2016/04/strategy2015-2018.pdf" target="_blank">download pdf</a>
    </p>
   </div>
  <p></p> ...3
 </div>
</aside>

但是它使1和2 p消失,留下3-我怎样才能让它做我需要的事情呢?

你可以删除
p
,它们是
的直接后代。textwidget

.textwidget > p {
    display:none;
}
您可以删除
:空的
段落标记:

.textwidget p:empty {
    display:none;
}

如果您熟悉jquery,可以使用

$('.textwidget p').each(function () {
    if ($(this).text().length === 0) {
        $(this).hide();
    }
});

因为
3
不是第一个孩子吗?它已经是基于HTML结构的第二个孩子,而不是把它扫到地毯上,考虑修复你造成这个问题的坏输入。是的,是小提琴。
$('.textwidget p').each(function () {
    if ($(this).text().length === 0) {
        $(this).hide();
    }
});