473,320 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

The preferred method of style definitions

Hi all,

If I want to have many divs with different padding, border, and colour
properties, should I just set those styles in line, ie:
<DIV style"...">
</DIV>

or should I define all the divs in a separate style sheet and link to it in the
header of my doc, ie:
<!--
#box1 {
border: 1px solid black;
background: white;
padding: 1em;
margin: 1em;
}

#box2 {
border: 1px dashed black;
background: red;
padding: 3em;
margin: 1em;
}

#box3 {
border: 2px solid yellow;
background: black;
padding: 0.5em;
margin: 0.5em;
}

..
..
..

#box99 {
....
}

It seems pointless to define the style of each box in the style sheet when each
is only used once, but is unique. I think it's appropriate to define major boxes
in the separate stylesheet if they are fundamental parts of your overall layout,
but not if they are just a little box you decide you need on-the-fly.

Sorry if this has been done to death.
--
Ben Thomas
Opinions, conclusions, and other information in this message that do not
relate to the official business of my firm shall be understood as neither
given nor endorsed by it.

Jul 20 '05 #1
5 1912
Hi Ben,

BenOne© wrote:
It seems pointless to define the style of each box in the style sheet
when each is only used once, but is unique. I think it's appropriate
to define major boxes in the separate stylesheet if they are
fundamental parts of your overall layout, but not if they are just a
little box you decide you need on-the-fly.


you need to understand the reasoning behind "separate structure from
content" first, then the answer will come automatically.

You use CSS not only and not primarily because of the many features it gives
you, but because it enables you to separate structure from content. This
means, that your (X)HTML should contain structural markup only, and no
presentational elements. If you have a formatting that should appear only
once, ask yourself why this is the case. What is so special about this one
line/paragraph that you want to emphasize it in this way? When you answered
this question, you need to *structure* your markup accordingly. As a last
step, you create a stylesheet that will assign a special layout to your
structural markup.

I'm not sure whether the above makes sense, maybe someone can explain this
in a clearer way.
Short answer: Academically, you should define everything in your external
stylesheet and not use inline styles. If you choose to sometimes use an
inline style, you will need to live with the disadvantages this brings you
(higher inflexibility when changing layout, etc.).

Alex

Final comment: actually, I think it is highly unlikely that in a whole
*site* you will need any layout only one single time. What is the example
you had in mind?

Jul 20 '05 #2
Tim
On Mon, 28 Jun 2004 23:40:03 GMT,
BenOne© <no**@m.thanks.mate> posted:
If I want to have many divs with different padding, border, and colour
properties, should I just set those styles in line, ie:
<DIV style"...">
</DIV>

or should I define all the divs in a separate style sheet and link to it in the
header of my doc


If it's truly unique, I've put mine in the head section on the page
(although that can cause problems for some very old browsers), but I've
usually found that I've created some styles that are rare but unique. I
put those either into the main style sheet in a "specials" area (if the
style file is long, it helps to find the bits I might tweak later), or
added a second style sheet to the main one with the special extras (could
be an import, or two style links in the HTML head section).

--
If you insist on e-mailing me, use the reply-to address (it's real but
temporary). But please reply to the group, like you're supposed to.

This message was sent without a virus, please delete some files yourself.
Jul 20 '05 #3
Alexander Fischer wrote:
Hi Ben,

BenOne© wrote:
It seems pointless to define the style of each box in the style sheet
when each is only used once, but is unique. I think it's appropriate
to define major boxes in the separate stylesheet if they are
fundamental parts of your overall layout, but not if they are just a
little box you decide you need on-the-fly.

you need to understand the reasoning behind "separate structure from
content" first, then the answer will come automatically.

You use CSS not only and not primarily because of the many features it gives
you, but because it enables you to separate structure from content. This
means, that your (X)HTML should contain structural markup only, and no
presentational elements. If you have a formatting that should appear only
once, ask yourself why this is the case. What is so special about this one
line/paragraph that you want to emphasize it in this way? When you answered
this question, you need to *structure* your markup accordingly. As a last
step, you create a stylesheet that will assign a special layout to your
structural markup.

I'm not sure whether the above makes sense, maybe someone can explain this
in a clearer way.
Short answer: Academically, you should define everything in your external
stylesheet and not use inline styles. If you choose to sometimes use an
inline style, you will need to live with the disadvantages this brings you
(higher inflexibility when changing layout, etc.).

Alex


Thanks Alex. I think I understand what you are saying, and I think the most
important issue is maintainability. Although it may be tedious for someone else
to understand how I've formatted every element of my page if all the style is in
a separate file. They'd have to keep referring back to it to see what style each
div has. Perhaps I'm overusing divs.
Final comment: actually, I think it is highly unlikely that in a whole
*site* you will need any layout only one single time. What is the example
you had in mind?


On the front page of my site I want to put a border around the brief description
I have of my site. This description obviously only appears once and the easiest
way to do it seems to be to put the description in:
<DIV style="border: 1px solid red; padding: 1em; margin: 2em;">
A fancy slogan to promote my site
</DIV>

--
Ben Thomas
Opinions, conclusions, and other information in this message that do not
relate to the official business of my firm shall be understood as neither
given nor endorsed by it.

Jul 20 '05 #4
Hi Ben,

BenOne© wrote:
On the front page of my site I want to put a border around the brief
description I have of my site. This description obviously only
appears once and the easiest way to do it seems to be to put the
description in: <DIV style="border: 1px solid red; padding: 1em;
margin: 2em;">
A fancy slogan to promote my site
</DIV>


If it's 100% certain you won't need this formatting again (so no more
slogans e.g. on subpages), then use something like id="promotion_slogan". In
addition, I have the feeling that instead of a div, some heading might be
appropriate. So use

<h1 id="promotion_slogan">A fancy slogan</h1>

and

h1#promotion_slogan{
border/padding/margin here
}

Alex
Jul 20 '05 #5
Alexander Fischer wrote:

If it's 100% certain you won't need this formatting again (so no more
slogans e.g. on subpages), then use something like id="promotion_slogan". In
addition, I have the feeling that instead of a div, some heading might be
appropriate. So use

<h1 id="promotion_slogan">A fancy slogan</h1>

and

h1#promotion_slogan{
border/padding/margin here
}

Alex


That is SO much better. Thank you very much for the suggestion.

--
Ben Thomas
Opinions, conclusions, and other information in this message that do not
relate to the official business of my firm shall be understood as neither
given nor endorsed by it.

Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Michele Locati | last post by:
Hi to everybody I've a little problem that I can't solve. An hour of Google search didn't help. I should set dinamically via JavaScript the height of an object when I print the HTML page. ...
18
by: craig | last post by:
I am curious about how many of you prefer style 1 vs. style 2, and why. Are there names for these style? style 1: method { }
5
by: Kobu | last post by:
Does anyone know how old style function definitions differ in "behaviour" to new style function definitions? I heard the old style function definitions caused integeral promotion and floating...
0
by: Cleo | last post by:
Hi, I am trying to call a WebService Method written in Weblogic from VB.NET and I am getting the following error. I am using SOAP Caal s from VB.NET. Please find the wsdl file and my code. ...
6
by: dndfan | last post by:
Hello, In the short time I have spent reading this newsgroup, I have seen this sort of declaration a few times: > int > func (string, number, structure) > char* string > int number >...
2
by: OzzyC | last post by:
I have creating a web page at http://www.interface-web.co.uk/atyc/cssproblem.htm which is supposed to use a preferred stylesheet to style the page on the first visit and then allows the user to...
4
by: Michael | last post by:
Hi, I'm having difficulty finding any previous discussion on this -- I keep finding people either having problems calling os.exec(lepev), or with using python's exec statement. Neither of...
19
by: zzw8206262001 | last post by:
Hi,I find a way to make javescript more like c++ or pyhon There is the sample code: function Father(self) //every contructor may have "self" argument { self=self?self:this; ...
3
by: moondaddy | last post by:
What's the preferred (best) way to start a website project in VS 2005? I know of 2 ways and each creates a site differently and has different behavior. Open VS 2005 1) from the start page...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.