tags:

views:

115

answers:

1

I am working on a straight HTML 5 website for learning.

Before my CSS might look like:

div.BoxHouse {
  margin-left: 72px;
  margin-right: 20px;
}

div.FloatingBox {
  text-align: center;
  float: left;
  width: 32%;
  border: 1px solid #3F4933;
  padding: 0px;
  background-image: url(transwhite.png);
  margin-left: 0.5em;
}

#content {
  width: 90%;
  background: url(transwhite.png);
  border: 1px solid #3F4933;
  margin-left: 72px;
  margin-right: 20px;
  margin-top: 20px;
  padding: 5px;
  z-index: 1;
  margin-bottom: 40px;
  overflow:auto;
  top: 10em;
  padding-top: 10px;
  }

I thought that with HTML5 I could just do this in code:

<header>  
<hgroup>
    <content>
    <BoxHouse>
        <h1>HTML 5</h1>  
        <h2>The mark-up language for fun and profit</h2>
    </BoxHouse>
    </content>
</hgroup>  

Given this as new CSS:

BoxHouse {
  margin-left: 72px;
  margin-right: 20px;
}

FloatingBox {
  text-align: center;
  float: left;
  width: 32%;
  border: 1px solid #3F4933;
  padding: 0px;
  background-image: url('../transwhite.png');
  margin-left: 0.5em;
}

content {
  width: 90%;
  background-image: url('../transwhite.png');
  border: 1px solid #3F4933;
  margin-left: 72px;
  margin-right: 20px;
  margin-top: 20px;
  padding: 5px;
  z-index: 1;
  margin-bottom: 40px;
  overflow:auto;
  top: 10em;
  padding-top: 10px;
  }

But it clearly doesn't work. What am I doing wrong?

A: 

Hello,

You can't use custom tags in HTML5. You should be either selecting the h1, h2 etc directly in your CSS or using classes on them.

<header class="content">  
<hgroup class="BoxHouse">
    <h1>HTML 5</h1>  
    <h2>The mark-up language for fun and profit</h2>
</hgroup>

Also, is the background-image: url(transwhite.png); image a semi transparent white background? If so you can use RGBA colours in CSS3. The is for alpha. So you can use background-color: rgba(255,255,255,0.5); for a 50% transparent white box. The advantage of this over using opacity is the text isn't transparent, it's still clear and solid.

BWRic
I thought, like AXL, that we could use custom tags in HTML5. I forget where I heard this from. Are you sure you can't? How do you know?
MattDiPasquale
Hello, I think if you serve your HTML5 as XML (XHTML5) you could use custom tags but I think you then need to use a custom DTD. I can't remember the exact source as I looked at it a while ago. I wouldn't recommend it though, stick to the existing ones as they have an understood semantic meaning. A new tag wouldn't have any meaning such as a header, article, section - these create the document outline which is the structure of the document, but BoxHouse means nothing to the browser, search engines etc. The HTML5 tags should cover all your needs when combined with classes and IDs.
BWRic
You can use custom attributes on tags if you append then with data- i.e. <h1 data-myattr="value">Heading</h1>. See here for more: http://html5doctor.com/html5-custom-data-attributes/
BWRic
Looks like HTML5 Doctor answered the question here: http://html5doctor.com/your-questions-13/
BWRic