Is it always a bad idea to use inline css for the used-once property?

I have a table with 10 columns. I want to control the width of each column. Each column is unique, now I am creating an external CSS style for each column:

div#my-page table#members th.name-col { width: 40px; } 

I know it's best to avoid inline style. I approve of using external CSS for something related to look'n'feel: fonts, colors, images. But is it really better to use external CSS in this case?

This does not require additional maintenance costs.
It is easier to produce.

Cons that I can think of:
If you have separate designers and a development team, using built-in styles will force designers to modify the content file (aspx in my case). It can use large bandwidth.

Anything else I missed?

IMPORTANT: I ask about only one specific case when the used style will be applied to only one element and is not part of the global theme, for example, the width of one specific column.

+4
source share
2 answers

There are many reasons why style="" is bad. I believe that this is a mistake that I encounter in my code base. Here are a few reasons:

  • style= has a higher priority than other CSS selectors, making it difficult to make changes to the stylesheet; a stylesheet needs to work harder to override them.
  • style= rules are hard to find in code when you need to make global changes.
  • You load this CSS code with every pageview.
  • If you have multiple style sheets for the same HTML code base, your style = rules are not part of the style sheet and therefore are immutable.

However, if you are creating content and it is difficult to describe this content in a static CSS file, you may also need to create CSS to match that content. It's often easier to just generate style= rules, despite the flaws. If, however, your generated content can be easily described in a CSS file, because the generated structure does not change often, or because you can easily generate HTML and a CSS file at the same time, then it is probably best not to use style= .

Some suggestions for style= alternatives that might be appropriate:

  • Instead of inline styles, use class names. Works well if you have many columns in a table that have the same properties and which you will always have the same properties. Then your stylesheet can stay fixed as long as your HTML is fluid, as CSS only refers to classes. This is probably the approach I would use.
  • Use jQuery or some other javascript library to program program objects after the page loads.
+2
source

It’s easier to actually create an invalid argument - people like to split huge chunks of code into smaller chunks - the same goes for code and markup.

However: + There is no additional HTTP connection (if you are not already loading the .css file) - Each time the page is sent, this CSS is sent with => more bandwidth - Designers should change the CSS in the application code (bad practice)

Normally you should not - unless it's a very well-thought-out performance tuning like google does .

+1
source

Source: https://habr.com/ru/post/1311232/


All Articles