473,785 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CSS formatting style

Yeah, that's right, this question is not about styling HTML with CSS,
but instead about how one should arrange his CSS code so that it is easy
to understand and modify.

The thing that I've got problems is that CSS does not seem to support
variables or conditionals (if/else). This makes it IMO difficult to
arrange the code, especially if several tags share one attribute (same
background for example). How do you organise your files?

1. Arrange everything according to HTML tags, e.g.
p { /* all settings for p go here */ }
h1 { /* all settings for h1 go here */ }

2. Arrange everything "logical", e.g.
h1, h2, h3, h4, h5 { font-weight:bold; }
h1, h2 { margin:0.5em; }
p, h4, h5 { padding:1.5em 0.5em 1.5em 0.5em; }

Or do you use a mixture of both? In the first version, it's easy to find
a style for a specific tag, but it's hard to change all those green
backgrounds to blue (and search&replace does not always do the job). The
second method makes that easy (because all elements which should have
the same background are grouped together). However the style
declarations get really messy, because every element is noted several
times in the whole file.

With variables it would be like (very simple example, of course)

$background:#FF F url(myimage.gif );
$border:1px solid #000;

p {
background:$bac kground;
/*other options*/
}

h1 {
border:$border;
}

h2 {
border:$border;
background:$bac kground;
}
Perhaps my opinion is based on my background of doing more programming
than markup, but that's why I ask you :)

I've also looked at some CSS files on the net, but I often found them
hard to understand, because I missed the logical grouping.

I'd be glad to hear some opinions on how this is done professionally.
Thanks,
Florian
--
Minimum Requirement #10: The mouse is there to rest your hand upon when
you're not typing (WEB.DE help-wanted ad: Linux Guru)
[------------ http://www.torfbold.com - POV-Ray gallery ------------]
Jul 20 '05 #1
2 1688
Florian Brucker wrote:
The thing that I've got problems is that CSS does not seem to support
variables or conditionals (if/else).
Correct. CSS is not a programming language.
How do you organise your files?
By site. Site wide styles (body, p, h1, h2, etc.). After that, I create
sections for different pages/sections of a site, along with a separate
section for form styling.

1. Arrange everything according to HTML tags, e.g.
p { /* all settings for p go here */ }
h1 { /* all settings for h1 go here */ }

2. Arrange everything "logical", e.g.
h1, h2, h3, h4, h5 { font-weight:bold; }
h1, h2 { margin:0.5em; }
p, h4, h5 { padding:1.5em 0.5em 1.5em 0.5em; }

Or do you use a mixture of both?
Use a mixture. There is no right and wrong. And only you know how your
css breaks down, and how you can best organize it to reduce the file
size and make it easier to change later.
I'd be glad to hear some opinions on how this is done professionally.


Oh, in that case, I should not have responded, since I'm a mere amateur.
;-)

--
Brian (remove "invalid" to email me)
http://www.tsmchughs.com/
Jul 20 '05 #2
On Sat, 09 Oct 2004 15:46:31 +0200, Florian Brucker <to**@torfbold. com>
wrote:
Yeah, that's right, this question is not about styling HTML with CSS,
but instead about how one should arrange his CSS code so that it is easy
to understand and modify.


More important - proper cascade. And you generally need to go general to
specific.

So, start with default body, heading, p, etc. styles that are mostly
applicable site-wide. Then styles for id- and class-contained versions of
elements. Then do the ones that change in a more random fashion. Remember,
a later rule overrides a previous rule with the same specificity, so watch
for that.
Jul 20 '05 #3

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

Similar topics

4
2406
by: Dan Weeb | last post by:
Hi All, I have struggled through this far with help from many of you so thanks. I am stuck again. I am really new to this so don't be harsh :-) There are a few problems. You can run the script here http://www.pbrown.com/research/test1.php to see the formatting issues Formatting Issues
6
8990
by: Kevin G. | last post by:
I'm not sure if this is possible, but if a page uses a CSS style sheet and you would still like to use good old <font> tags... is there a tag to tell the browser to ignore the CSS formatting just for that table cell? I work for a company that has their website built from a 3rd party. We're very restricted in how we can redesign the pages. The only "content" we're allowed to add come in after the <head> tags... so the CSS is already in...
2
1653
by: John Mason | last post by:
Hi, I have a Datagrid control with an edit command column, which has a PushButton ButtonType. I am trying to apply formatting to the plain grey button, to make it look more appealing on screen. I would like to change the font-size and the set the background color, the foreground color of the text, and also set a border color and width.
10
3164
by: Coleen | last post by:
Hi all :-) I have a weird formatting problem with an HTML table that I am populating using VB.Net and HTML. Here is the snippet of code for the cell I'm trying to format: Dim ld_tot_pet_clean_fee_calc As Double ld_tot_pet_clean_fee_calc = li_net_total_calc * 0.0075 ld_tot_pet_clean_fee = lo_misc_func.FormatMC(ld_tot_pet_clean_fee_calc, "D") Session("tot_pet_clean_fee") = lo_misc_func.FormatMC(ld_tot_pet_clean_fee, "D")...
4
1601
by: Arthur Dent | last post by:
Hello all, ive been programming with ASP.NET since it came out, but am just getting my feet with now with v.2. Ive noticed something strange in the way my HTML tables get rendered with 2. I use tables to layout my pages, doing three rows, a header, content and footer. When i do this, i make the tables height=100%, so the footer always shows up at the very bottom of the page. With 2.0/2005 though, when it renders the pages, it doesnt...
25
2711
by: mdh | last post by:
Hi Group, Not looking for an answer, but more of an explanation. Thinking back to those heady days when you had the time to do them, may I ask this. Exercise 1-22 asks for a program to "fold" long input lines into 2 or more shorter lines before the nth column... etc etc. Now, there are numerous anwers on the web and in the "C answer book", which includes a function to expand the tabs to blanks ( depending upon where the tab is in...
5
3041
by: mrid via DotNetMonster.com | last post by:
hi. im exporting data from a vb form to excel. i am able to create a new excel file, save and edit it without any trouble, but the formatting is giving me hell! i need to be able to show certain cells in bold, with underlining etc. i dont understand how, but in the following code, the instruction for bold gets picked up for all the cells (even when i specify font.bold = false), and the underlining is haphazardly used. the font colour...
1
3531
by: Sven Fischer | last post by:
After installation of Visual CSharp Studio the current settings of the source code editor are not suitable for me. The brackets are automaticlly set in front of the lines e.g. if (.......) { statement ... }
93
3904
by: Phlip | last post by:
C++ers: Feast your eyes: void Home:: inherits (IdentifierPtr const& id) { ... }
1
1388
by: Josiwe | last post by:
I have a search program that returns an HTML string which I display to the user. I want to highlight the search terms. However a simple search and replace on the HTML causes problems. If the user searches on Georgia and I get back this: <div style="font-name:Arial">Georgia, Alabama, and Louisiana</div> It works fine: <div style="font-name:Arial"><span style="background- color:yellow;">Georgia</span>, Alabama, and Louisiana</div>
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9489
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10162
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10100
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5396
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2893
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.