What is the preferred way to store styles very specific to one single dom element? In a separate css file, or inline in the style attribute in the html file?
I’ll give you an example. This is the css i currently have in a css file. Titlebar, product title, product description, and category image are elements which all need very specific styling and I will never reuse the styles anywhere else. I am very tempted to add them inline and only leave the more general styles in the css file. Should I do this? Why/why not?
#titlebar {
position: absolute;
top: 141px;
left: 80px;
width: 180px;
height: 38px;
line-height: 38px;
font-size: 18px;
font-weight: bold;
text-align: center;
color: white;
text-shadow: 0 -1px 0 #666;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
#product-title {
position: absolute;
top: 190px;
left: 110px;
width: 190px;
height: 18px;
line-height: 18px;
font-size: 16px;
font-family: 'Droid Serif', Georgia;
color: black;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
#product-description {
position: absolute;
top: 210px;
left: 110px;
width: 190px;
font-size: 10px;
height: 50px;
overflow: hidden;
text-overflow: ellipsis;
}
#category-image {
position: absolute;
top: 186px;
left: 43px;
width: 52px;
height: 60px;
}
Generally use an external stylesheet (or several) because they can be cached by the browser.
Using inline styles is a bad idea. It reduces maintainability and separation of code and presentation.