www.webdeveloper.com
Results 1 to 6 of 6

Thread: Question about best practice CSS styling controls

  1. #1
    Join Date
    Jul 2003
    Location
    UK
    Posts
    391

    Question about best practice CSS styling controls

    Hi,

    in .net controls tend to be styled using in-line styling. You can set styling in the properties section of the Visual Studio IDE as opposed to adding a class id to it. But doesn't this go against best practice for CSS. CSS should normally all be in a separate stylesheet shouldn't it?

    So what do the pros do about this? Or would it simply be too time consuming to create separate styling for the controls in a separate stylesheet?

    Thanks!

  2. #2
    Join Date
    Jun 2012
    Location
    Dark Side of the Moon
    Posts
    70
    Don't know where you got that VS likes in-lines, it gives you the option, but if you are doing more than one or two properties, or reusing them at any time, it always pays to put them in a css file and linking to the page. In-lines take up space, kill reuse, and makes it infinitely harder to maintain. Even when you create a new project, the template usually creates a styles folder, best practice is to use it.
    I love how people get an attitude when THEY asked for help.

  3. #3
    Join Date
    Jul 2003
    Location
    UK
    Posts
    391

    Hi

    Thanks.

    When I say VS styles it in-line. If you have a control and then change its style properties through the IDE it always add the styles in-line doesn't it? You cannot say make a label bold and tell it to add the style to an external style sheet.

  4. #4
    Join Date
    Jun 2012
    Location
    Dark Side of the Moon
    Posts
    70
    No you should be adding that style to the css instead of using inline, you would tell it to use a the class="mystyle", that way you can reuse it without having to retype/copy it to the label, you never know how many labels you will have that need to look like that. You have to maintain the css, but all you have to do is put in there, and then indicate the class to use it, far easier then anything else.
    I love how people get an attitude when THEY asked for help.

  5. #5
    Join Date
    Oct 2009
    Posts
    658
    Quote Originally Posted by damon2003 View Post
    But doesn't this go against best practice for CSS.
    Yes it is against it.

    Quote Originally Posted by burnme View Post
    Even when you create a new project, the template usually creates a styles folder, best practice is to use it.
    Though best practice a distinct guideline, this is arguably one of the arbitrary ones. I don't use the styles folder as I'm sure with lot's .NET developers do ... I use App_Themes.

    I assume you are doing programmatic changes to the control. Doing so either call a separate Skin or attach a different CssClass. I prefer Skins as the skin can have multiple classes already attached to it and other settable properties. As much as possible my DOM Elements only contains class attributes. I do this using App_Themes. As much as possible I don't use the toolbox in the IDE and if I do I try not to forget to change the attributes.
    Good Luck

    Santos Systems

  6. #6
    Join Date
    Jul 2003
    Location
    UK
    Posts
    391
    Thanks a lot for your replies , going to have a go at it. Wanted to have a better understanding of best practice.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles