|
-
Mar 24th, 2013, 10:54 PM
#1
Thread Starter
PowerPoster
[RESOLVED] is inline styling considered a hack
i am new to css
i posted a css question on another site
move centered text 10px to the right that is inside a centered division
I did not get any answers, but found the solution myself eg;
<span class="sMedBoldBlue" style= "margin-left:10px">
this worked and validated
someone posted a comment that inline css is considerated a hack.
Is this true ?
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Mar 25th, 2013, 11:35 PM
#2
Re: is inline styling considered a hack
Depends entirely on the situation. Most of the time, you will want to add your styles to CSS classes so they are reusable in other sections of your website. If you're just applying a one-off style to a single element, then it might be ok. But even then, some people will still suggest to put it in a class.
Due to the "Cascading" part of CSS, inline styles will have higher precedence over styles defined in <style> tags or in .css files, so they can be used in effect to "overwrite" existing styles defined for an element, assuming there isn't any "!important" defined on the higher-up styles. You should try to avoid doing that if at all possible because you want each particular element type on your pages (p, h1, etc.) to have consistent styling.
A quick example:
HTML Code:
<p style="font-size:larger;">This text is larger than normal</p> <p style="font-size:larger;">This text is also larger than normal</p> <p style="font-size:larger;">This text is also larger than normal</p> <p style="font-size:larger;">This text is also larger than normal</p>
Supposing, I wanted to change the text inside each of the <p> elements to be smaller or bigger than what I've already defined, it would necessitate changing the inline styles on each <p> element. If I define that in a class, I have to only change it once to update the style across all <p> elements:
HTML Code:
<p class="larger">This text is larger than normal</p> <p class="larger">This text is also larger than normal</p> <p class="larger">This text is also larger than normal</p> <p class="larger">This text is also larger than normal</p>
CSS Code:
.larger { font-size: 5em; }
In reality, you would probably want each <p> element on your site to be styled identically, so you would apply the style directly to the <p> tag in CSS instead of using classes on each <p>:
Last edited by tr333; Mar 25th, 2013 at 11:44 PM.
-
Mar 25th, 2013, 11:48 PM
#3
Re: is inline styling considered a hack
I would also suggest checking out the HTML5 Boilerplate for some insight into best-practices with front-end web development.
-
Mar 25th, 2013, 11:59 PM
#4
Thread Starter
PowerPoster
Re: is inline styling considered a hack
thanks that clears things in my mind
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Mar 26th, 2013, 12:01 AM
#5
Thread Starter
PowerPoster
Re: is inline styling considered a hack
i have to spread some reputation around
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|