Remove padding for an empty element

前端 未结 8 504
灰色年华
灰色年华 2021-02-02 05:32

I\'m generating a page for an upcoming portal site, and I\'ve got an HTML element with some optional content. I\'d like the element to not render if it is empty, but adding some

8条回答
  •  旧巷少年郎
    2021-02-02 06:13

    If it's necessary to have the div.someElement in the HTML, the best CSS/HTML way to do that would be to add an extra div around the added content that has the padding property

    .someElement > div{padding-top:5px;}
    
    
    Content

    Otherwise, do as Pekka says, or take a look at having javascript do it for you.

提交回复
热议问题