Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How semantic is your XHTML/CSS markup?

Tags:

css

xhtml

I think I'm pretty good at using semantic markup on my pages but I still have a handful of classes like this:

/**** Aligns ****/
.right_align  { text-align: right; }
.left_align   { text-align: left; }
.center_align { text-align: center; }

Which, technically, is a no-no. But when you just want to position some text in a table, how crazy am I supposed to get with the semantic markup?

like image 752
Kyle West Avatar asked Nov 15 '08 21:11

Kyle West


People also ask

What is a semantic markup?

Semantic Markup refers to marking up documents in ways that provide information about the content itself rather than information about the visual styling of the content. It is critical to ensure that assistive technology users can understand your document.

Why semantic markup is important in HTML?

Semantic HTML refers to syntax that makes the HTML more comprehensible by better defining the different sections and layout of web pages. It makes web pages more informative and adaptable, allowing browsers and search engines to better interpret content.

What is the purpose of the semantic elements mark?

A semantic element clearly describes its meaning to both the browser and the developer. Examples of non-semantic elements: <div> and <span> - Tells nothing about its content. Examples of semantic elements: <form> , <table> , and <article> - Clearly defines its content.

What is the difference between structured content and semantic HTML?

The main difference between these types of elements is that semantic elements explain the purpose of an element, while structural elements explain the relation of its content to the content of other elements within a document. For example, you can create two layouts.


2 Answers

Why do you want to align the text?

The answer to the question is the name of the id or class you need to have for your selector. Do you want to align it right because it's a price?

table .price {
  text-align: right
}

Just ask yourself why do you want to apply a particular style, and all will become clear.

I probably overdid it, but my last work project was pretty close 100% semantic- anything I needed which was not semantic (say, a filler div which I could not do without for a layout requirement), I added dynamically using jQuery.

like image 172
alex Avatar answered Sep 29 '22 19:09

alex


If you want tight coupling between the table cells and the alignment, you could just assign the attribute style="text-align:right" directly on the tag. There is no reason to go the extra level of indirection through a class if you dont use it for a level of abstraction anyway.

like image 24
JacquesB Avatar answered Sep 29 '22 18:09

JacquesB