Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove padding for an empty element

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 padding to it causes it to render. How do I add padding to the content, but only if content is present?

.someElement{padding-top: 5px;} 

HTML in question:

<div class="someElement">With padded content</div> <div class="someElement"><!-- shouldn't render since it has no content --></div> 

Basically, I'd like the second element, above, to not take up any space. I'm testing in all major browsers, using XHTML 1.1 doctype.

like image 599
Eric Falsken Avatar asked Jan 02 '10 20:01

Eric Falsken


People also ask

How do I get rid of body padding in HTML?

Adjusting the Margin Size of an HTML Element With CSS You can remove this margin by setting the top and left margin to zero. Like the padding and border, the sizes of specific sides of the margin can be set using margin-left , margin-right , margin-top , and margin-bottom .

How do I remove default margin and padding in HTML?

The right answer for this question is "css reset". It removes all default margin and padding for every object on the page, no holds barred, regardless of browser.


1 Answers

You can do the trick with the CSS3 pseudo-class :empty

.someElement {     // your standard style } .someElement:empty {     display:none; } 

Sadly Internet explorer doesn't support that feauture yet. For all the other browsers it shall do just fine...

like image 172
MindTailor Avatar answered Oct 14 '22 12:10

MindTailor