CSS and custom tags

doctorbill
doctorbill used Ask the Experts™
on
A CSS question:

Let's take the <td> tag as an example

Is it possible to make a custom css tag and use that to dictate the styling of any <td> tags inside it
ie
css page:
customtag > td
{
some condition
}
php page:
<customtag><td> text </td></customtag>

The reason for this is that I want to add a specific condition to a set of <td> tag's which already have defined css conditions defined for that particular tag in the css page in the rest of the php page
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Terry WoodsIT Guru
Most Valuable Expert 2011

Commented:
Why a custom tag and not just a <div> tag with a particular class, or for that matter, why not just add a class or id to an element on the page?
Terry WoodsIT Guru
Most Valuable Expert 2011

Commented:
This may be of interest: https://stackoverflow.com/questions/5970093/using-custom-html-tags

The top 2 answers are worth a read. Long story short, if you create a custom tag, it should probably work, but it sounds like it's a good idea to ensure you put a hyphen character in the tag name (eg <my-tag>) to avoid the risk of the tag become a standard one in future.
David FavorFractional CTO
Distinguished Expert 2018

Commented:
You can add anything you like to your CSS.

However, for your custom tag to be processed, you'd somehow have to convince every visitor to your site to download some sort of hacked version of their browser, which you coded to process your custom CSS tag.

Highly unlikely approach to whatever you're trying to solve.

Just use CSS classes or style by element ID.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
A <tr> is the only permitted parent of a <td> so custom tags (or any other) would not be valid. You can add selectors (such as a class or ID) to either the <td> elements themselves or to any parent element and then use that to limit the CSS applied.

<table class="custom">
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
</tr>
</table>

.custom td { color: red; }

Author

Commented:
Thanks all
Brandon LyonWeb Developer/Designer

Commented:
Just to clarify a bit of misinformation earlier in the thread, custom elements are possible. That said I wouldn't suggest using them in situations where a classname, id, or attribute would work just as well.

Here is a tutorial about custom elements https://blog.teamtreehouse.com/create-custom-html-elements-2

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial