Remove padding for an empty element

前端 未结 8 469
灰色年华
灰色年华 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:09

    At the point where you populate the optional div, if there is no text to put in it, try changing the CSS display property to none. According to this source (and others), display: none removes the element completely from the document. It does not take up any space, even though the HTML for it is still in the source code.

提交回复
热议问题