blogsmith Posted May 25, 2006 Share Posted May 25, 2006 <center> is depracated. So what is the replacement for it? Link to comment Share on other sites More sharing options...
aspnetguy Posted May 25, 2006 Share Posted May 25, 2006 <div style="text-align:center"></div> Link to comment Share on other sites More sharing options...
blogsmith Posted May 26, 2006 Author Share Posted May 26, 2006 <div style="text-align:center"></div><{POST_SNAPBACK}> But what if whatever that should be centered is not text, for example, an image or an ad.? Link to comment Share on other sites More sharing options...
Jack McKalling Posted May 26, 2006 Share Posted May 26, 2006 Doesn't matter, text-align means the inner HTML of the element, regardless of what the content is Link to comment Share on other sites More sharing options...
blogsmith Posted May 26, 2006 Author Share Posted May 26, 2006 Will <span style="text-align:center"></span> do as well?What is the difference between <span> and <div> anyway? Link to comment Share on other sites More sharing options...
snowboard01 Posted May 26, 2006 Share Posted May 26, 2006 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 More sharing options...
boen_robot Posted May 26, 2006 Share Posted May 26, 2006 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 More sharing options...
Jack McKalling Posted May 28, 2006 Share Posted May 28, 2006 (edited) 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.<{POST_SNAPBACK}> 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 May 28, 2006 by Dan The Prof Link to comment Share on other sites More sharing options...
boen_robot Posted May 28, 2006 Share Posted May 28, 2006 (edited) 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 May 29, 2006 by Jonas Link to comment Share on other sites More sharing options...
zachary Posted May 29, 2006 Share Posted May 29, 2006 Why not, <div id="" align="center"></div> . Link to comment Share on other sites More sharing options...
reportingsjr Posted May 29, 2006 Share Posted May 29, 2006 you can do that zachary... Link to comment Share on other sites More sharing options...
Jack McKalling Posted May 29, 2006 Share Posted May 29, 2006 Why not, <div id="" align="center"></div> .<{POST_SNAPBACK}> The align attribute for div is depreciated in html 4, as in xhtml strict.And W3Schools had never said Style is depreciated, can't be. You're probably confused with something else, Link to comment Share on other sites More sharing options...
yoshida Posted May 29, 2006 Share Posted May 29, 2006 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 More sharing options...
boen_robot Posted May 29, 2006 Share Posted May 29, 2006 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 More sharing options...
justsomeguy Posted May 29, 2006 Share Posted May 29, 2006 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 More sharing options...
SFB Posted May 29, 2006 Share Posted May 29, 2006 Even though it may be depreciated all the browsers i tested it in still support it Link to comment Share on other sites More sharing options...
yoshida Posted May 29, 2006 Share Posted May 29, 2006 Even though it may be depreciated all the browsers i tested it in still support it<{POST_SNAPBACK}> 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 More sharing options...
boen_robot Posted May 29, 2006 Share Posted May 29, 2006 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 More sharing options...
Jack McKalling Posted May 29, 2006 Share Posted May 29, 2006 The fact is, not every filesystem supports file extensions longer than three characters, so using *.htm (or even still *.html in newer versions) would do the trick. Link to comment Share on other sites More sharing options...
snowboard01 Posted May 29, 2006 Share Posted May 29, 2006 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 htmlI think the html extention might be the way to go for now. Link to comment Share on other sites More sharing options...
scott100 Posted May 30, 2006 Share Posted May 30, 2006 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.<{POST_SNAPBACK}> 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 More sharing options...
asylum Posted May 30, 2006 Share Posted May 30, 2006 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 More sharing options...
yoshida Posted May 30, 2006 Share Posted May 30, 2006 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 More sharing options...
boen_robot Posted May 30, 2006 Share Posted May 30, 2006 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 htmlI 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 More sharing options...
Jack McKalling Posted May 30, 2006 Share Posted May 30, 2006 I still don't understand why the style attribute would be depreciated, any way. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now