Jump to content

what is the replacement for <center>


blogsmith

Recommended Posts

Span is a line div is a box. you would use spans if you wanted to change text style like:

<html><head><title>somthing</title </head><body>This is the default color!<span style="color:red">This is red</span>This is black again.<span style="color:green"> this is green</span>ect.</body></html>

A div is for layouts like this.

<html><head><style type="text/css">.div{position:absolute;top:100px;left:100px;}</style><body><div class="div>this text is 100px from the top&bottom</body></html>

Link to comment
Share on other sites

I think I should add a small correction to some of the posts above. To center an element you would use margin: 0 auto; while text-align: center; is used for whatever the content of an element (or at least the text).Also, it is said that the style attribute is deprecated too, so you shold declare your per-page styles in a <style> element the way snowboard01 showed in his second example.

Link to comment
Share on other sites

I think I should add a small correction to some of the posts above. To center an element you would use margin: 0 auto; while text-align: center; is used for whatever the content of an element (or at least the text).Also, it is said that the style attribute is deprecated too, so you shold declare your per-page styles in a <style> element the way snowboard01 showed in his second example.

And I think those additions are not entirely true :)You are right, text-align is about the content and not the element itself. But you may apply it to the parent of what element you are centering, that will work :)Next, the style attribute cannot be depreciated at all, there will always remain the possibility to apply inline style in the html document, use style-attribute to do so :) (Even still you may extract them if they come with many, to an internal stylesheet as you say) Edited by Dan The Prof
Link to comment
Share on other sites

I'm not entirely sure about the centering, but I think it's that inline elements are aligned with text-align: center; and block elements with margin: 0 auto;. I don't know for sure. Most of the times I use them both anyway.As for the style attribute, I'm absolutely sure. It's this forum where I learned that. There was a link to the place in the specification it was said that the style attribute is deprecated, but I can't find it. If I do find it, I'll show you the link.

Edited by Jonas
Link to comment
Share on other sites

Why do you think it's called CASCADING style sheets? The way I understand it, inline styles have priority over an onpage-stylesheet (<head><style etc>stylesheet goes here</style></head><body>), which has priority over an external stylesheet. Thus cascading the priority of the sheet.So if the inline style attribute has top priority, why abandon that concept?Just my $0.02 anyway...

Link to comment
Share on other sites

Here's the post containing the link to the spot where W3C says the style attribute is deprecated. I don't blame you for not believing me though. As you can see in that topic, I didn't believed it myself, until I saw it with my own eyes. Oh, and don't shoot me. I'm just a messanger :) .

Link to comment
Share on other sites

Why do you think it's called CASCADING style sheets? The way I understand it, inline styles have priority over an onpage-stylesheet (<head><style etc>stylesheet goes here</style></head><body>), which has priority over an external stylesheet. Thus cascading the priority of the sheet.So if the inline style attribute has top priority, why abandon that concept?Just my $0.02 anyway...

I agree, I thought that decision was crap. They remove an entire level of the cascade, and there's not even an apparently good reason for doing it.
Link to comment
Share on other sites

Even though it may be depreciated all the browsers i tested it in still support it

Yeah, but how about IE 7.21 or Firefox 1.8 when those versions are going to go 'live'? I agree browsers should primarily support webprogrammer's best practices and an 'easy way out' for the regular n00b for it all to make sense, but I believe the gap between the technology and the user will be a serious infringement on freedom of netspeech.Yet again, the web is too crowded to contain a bilion crappy sites. Isn't it?
Link to comment
Share on other sites

The reason browsers "support" it is that as far as I know, you're using the text/html MIME type, which allows for all XHTML transitional features, but uses HTML rules. True XHTML like behaviour can be achieved only through the *.xhtml extension and/or the application/xhtml+xml MIME type applyed to another extension.

Link to comment
Share on other sites

The .xhtml extension?

True XHTML like behaviour can be achieved only through the *.xhtml extension and/or the application/xhtml+xml MIME type applyed to another extension.
I saved a file as .xhtml once my system didn't even recagnize it as somthing to be opened in a browser. When I opened ie it said:
file type unknown but has html doctype would you like to render this page as html
I think the html extention might be the way to go for now.
Link to comment
Share on other sites

Also, it is said that the style attribute is deprecated too, so you shold declare your per-page styles in a <style> element the way snowboard01 showed in his second example.

Inline styles are depricated??? Ok so we should now use #id instead?Take this piece of code, i have set it's width through it's id and try to access it properties with javascript, but this will not work, what should i do?
<head><script>function change(){val=document.getElementById('mydiv').style.width;alert("My width is: "+val);}</script><style>#mydiv{width:100px;border:1px solid black;}</style></head><body><html><body><div id="mydiv" onclick="change()">click me</div></body></html></body>

:) hmmm i wonder what's next to go...

Link to comment
Share on other sites

You do it the long way...unfortunately..

function getStyle(obj,stylename){     return document.defaultView.getComputedStyle(obj,"").getPropertyValue(stylename);}

and use the appropriate setProperty() function to set the value. It really isn't that annoying from a javascript perspective but more from an xsl point of view. When you have to dynamically generate styles IN stylesheets and maybe even dynamic class names, well that's just asking for errors.

Link to comment
Share on other sites

OK I can see why people want one standard... so you don't have to be creative anymore and everyone will make the same kind of pages. :)

Link to comment
Share on other sites

The .xhtml extension? I saved a file as .xhtml once my system didn't even recagnize it as somthing to be opened in a browser. When I opened ie it said:
file type unknown but has html doctype would you like to render this page as html
I think the html extention might be the way to go for now.

That is true. IE doesn't support the application/xhtml+xml MIME type which as mentioned is applyed by default on every *.xhtml file. That is infact the reason why people still use the html extension. I am talking for the future anyway. If you want to see XHTML behaviour with *.xhtml files, you'll have to use FF or other browser that supports that MIME type.And scott100, yes. The reason for the style attribute's deprecation is exactly the existance of IDs.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...