March 24, 2012

Are custom elements valid HTML5?

Question by user1282216

I’ve been unable to find a definitive answer to whether custom tags are valid in HTML5, like this:

<greeting>Hello!</greeting>

I’ve found nothing in the spec one way or the other:

http://dev.w3.org/html5/spec/single-page.html

Douglas Crockford claims:

Custom HTML tags have always been allowed in HTML. In HTML 5 they
become first class

… but he offers no proof.

http://www.crockford.com/html/

And custom tags don’t seem to validate with the W3C validator.

So if anyone can help me definitely answer this, please do!

Thanks!

Answer by Starx

Its not

XML

Creating your own elements in HTML is possible but not valid[Spec]. That’s what XML, SGML and other are for. HTML has a set of rules, which browsers, search engine understand and perform. Why do you want to mess around with that?There is a always a better way

There is a javascript technique that is used to enable HTML5 in IE browsers.

document.createElement(elementName)

You can use this to create any element and have CSS style it as well.

March 20, 2012

multiple "HTML" tags in HTML file: how to separate CSS rules when classes and id's can be the same?

Question by P5music

I see that multiple HTML tag file is correctly rendered by the browser. I mean like two html files merged and concatenated. But if I put a STYLE region into each of the HTML parts and the classes or id’s are the same I get the last css rules applied also to the first part. I ask how to make css rules acting just on the part they are inserted, even the classes and ids are the same. I need this special thing, so I am looking for a solution or a trick.

Answer by stefan bachert

I think multiple html-Tags in one document are not allowed.
I do not see any advantages for doing so.

When you have multiple documents, consider to use the frame or better iframe-tag

Answer by Starx

Having multiple elements with same id is very error prone. Breaks on more than one occasion like

On javascript: document.getElementById('idname');

March 12, 2012

Is there a way to change the width of the <code> HTML tag?

Question by Yeseanul

I’ve noticed that any modification of the <code>‘s style with respect to its width doesn’t have any effect. It’s seems to always be set to “auto”.

I’m just trying to have some code written inside a <code> tag (this tag is mandatory due to some known iBooks bugs) that has 100% width. One workaround is to put the <code> inside a <div> which has a 100% background style. This works OK but I’ll have to deal with a couple of hundred <code> tags… This is the reason I would prefer just to be able to modify the <code>‘s width.

Any thoughts?
Thanks.

Answer by Rob W

<code> elements are inline elements. Setting a height or width on these do not have any effect on their size.

Use display:inline-block::

code {
    display: inline-block; 
    width: 100px; /* Whatever. The <code>'s width will change */
}

Answer by Starx

Add a display: block or inline-block as per you requirement to the code element. Rest should work as planned

See an example

...

Please fill the form - I will response as fast as I can!