24

I use 'class' when I need CSS function. For example, when I want to use clear: left; I make a class .clear {clear: left;} and use it in HTML file.

But there is always the warning

should trim empty

Luckily, it's not error so I don't care greatly. But it bother me sometimes.

Is there any solution sticking my habit?

Boaz
  • 19,892
  • 8
  • 62
  • 70
Joanne Gil
  • 251
  • 1
  • 2
  • 7

6 Answers6

39

For Aptana Studio users:

Windows: go to Window > Preferences > Aptana Studio > Validation

(Mac: go to Aptana Studio > Preferences > Aptana Studio > Validation)

Select HTML Tidy Validator then some collapse-able options will appear. Select Elements, it will show a list of options. Now go to the bottom of the list and you'll see "Trim Empty Elements": change it from warning to ignore.

Paranoid Android
  • 4,672
  • 11
  • 54
  • 73
16

I'm assuming your talking about Aptana Studio maybe some other IDE's do the same thing, I dont know? Any how you can simply add a space between the div tags like so:

<div id="someDiv" class="clearLeft"> </div>

or add a comment between the tags like this:

<div id="someDiv" class="clearLeft"><!----></div>

This should remove the warning message and wont cause any issue with your html.

enter image description here

Kyle Coots
  • 2,041
  • 1
  • 18
  • 24
  • I upvoted you just now because this is a valid solution for Aptana. Sure, it doesn't look good in the code, and I'd imagine that OP was looking for a fix in the code parser itself, but this works in the meantime. – jsanc623 Jun 21 '13 at 16:47
  • Thank you! Yea, it's not very pretty. If he is looking for a fix to the parser, all or most validations can be modified. I posted an answer to a similar validation issue here that should do the trick: http://stackoverflow.com/questions/10169630/what-is-the-red-x-on-my-css-file-icon-in-aptana-studio-3/14413053#14413053 – Kyle Coots Jun 22 '13 at 19:22
2

If you are using Aptana Studio :

Go to Window > Preferences > Aptana Studio > Validation > HTML.

Change the two checks by "HTML Tidy Validator" into "X". Alternatively, you could click "+" to add a regular expression to filter out the error.

Jackal
  • 2,591
  • 3
  • 25
  • 29
0

This is a fairly old question, but I feel obliged to point a few things out:

  • Empty elements are acceptable if used correctly. E.g. the javascript templating engine pure.js relies completely on them.
  • In your case ideally you should add the clear:left to element after the floated element, rather than using utility elements. DOM classes should have nothing to do with the css itself (e.g. clear), but rather should describe the document structure (which in turn allows you to clear the logical elements). Either way, that's the ideal world and it's fairly common to use css the way you are using it and there isn't too much wrong with it (the only disadvantage being that you need to change the DOM if you want to change the look of your site).
  • The worst thing to do is adding &nbsp; as that ignores the reason behind the warning entirely and just 'bypasses' it.
David Mulder
  • 26,123
  • 9
  • 51
  • 114
  • I am getting the same "warning". Everyone was asking where the warning was appearing. I specifically use Aptana Studio 3, but it is appearing in this program. This warning appears in the left margin by the line numbers in the "compiler" (I'm not sure if aptana is actually qualified as a compiler). – Mike Kellogg Sep 04 '12 at 17:09
  • So, if "empty elements are acceptable", what is "the reason behind the warning"? – Jānis Elmeris May 07 '19 at 13:59
  • 1
    @JānisElmeris The second point I bring up is probably the main thing. An empty element tends to be a code smell. It doesn't mean it's always bad, but in most cases you're doing something you shouldn't be doing (e.g. using html elements as styling tools). If however an empty element is just waiting around to get filled through some Javascript then there is nothing wrong with it at all. – David Mulder May 07 '19 at 14:18
-1

Try doing this:

    .clear {
        clear: left;
    }

Happend to me with empty divs written in the same line.

leandronn
  • 173
  • 1
  • 17
-2

Another solution is giving your empty div an id

<div id="myEmptyDiv"></div>