Results 1 to 5 of 5

Thread: [RESOLVED] is inline styling considered a hack

  1. #1

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Resolved [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

  2. #2
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    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:
    1. <p style="font-size:larger;">This text is larger than normal</p>
    2. <p style="font-size:larger;">This text is also larger than normal</p>
    3. <p style="font-size:larger;">This text is also larger than normal</p>
    4. <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:
    1. <p class="larger">This text is larger than normal</p>
    2. <p class="larger">This text is also larger than normal</p>
    3. <p class="larger">This text is also larger than normal</p>
    4. <p class="larger">This text is also larger than normal</p>
    CSS Code:
    1. .larger {
    2.     font-size: 5em;
    3. }

    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>:
    CSS Code:
    1. p {
    2.     font-size: 5em;
    3. }
    Last edited by tr333; Mar 25th, 2013 at 11:44 PM.
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

  3. #3
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    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.
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

  4. #4

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    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

  5. #5

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    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
  •  



Click Here to Expand Forum to Full Width