Remove padding for an empty element

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

    Don't use padding on container, use margin on content. Than when there is no content, container remains invisible.

    0 讨论(0)
  • 2021-02-02 06:28

    Give the element an id attribute. You can then use Javascript to check it's innerHTML property once the page has loaded. If innerHTML has a length of zero, then you can set it's display property to none. This page might help if you don't know your javascript.

    This is still a mucky way to play. If you know the element shouldn't be rendered before you serve the page it would be better to omit it altogether. If you don't want to omit the element, just hide it, then force it into hiding; style="display: none"

    0 讨论(0)
提交回复
热议问题