rulururu

post Priority When Multiple CSS Classes are Applied

November 3rd, 2006

Filed under: Code, HTML/CSS, Javascript — Brenton Alker @ 16:16

I’ve used multiple CSS classes applied to an element on many occasion, but never run into the problem I found today. It seems counter to the CSS system as I understand it, but I’ve checked it out and it works like this.

I had a page, who’s table cells all had a CSS class that applied a background colour, some font attributes and what have you.
The class (from an external stylesheet file):

td.listCell
{

color: black;
background-color: grey;

}

was applied individually to each cell like:

<td class="listCell"></td>

I needed to apply a second class on certain cells to change the background colour, this is part of an on-page Javascript search. This page has lots of content, a large form, most of which is hidden and only small parts are used at a time. The search is supposed to highlight the cells that contain the text in the search field.

So, I added a searchHighlight style to the head of the page, making it look like:


<head>

<style type="text/css">
.searchHighlight { background-color: red }
</style>
<link rel="stylesheet" type="text/css" href="stylesheet.css" />
</head>

On my way I went, coded the javascript to search the table and add the ’searchHighlight’ class to the cells that needed hightlighting. Easy. Except it didn’t work.

When the Javascript found it’s target, and changed the class (by appending searchHighlight to the className) nothing happened. I checked the Javascript had worked, using my trusty FireBug source inspector. It had. So why no change in the style?

I changed the Javascript to replace (instead of append) the searchHighlight class, that worked, except it lost all it’s normal formatting, which I was almost willing to put up with, but not quite. I tried pre-pending the searchHighlight class (hoping the styles were in priority order), but to no avail.

So I created a simple test page, to make sure I was wasn’t going (more) insane, and that multiple CSS styles ever worked.
The test page looked like this:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Multiple CSS Class Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta>
<style type="text/css">
.normal { font-weight: bold; background-color: red;}
.special { background-color: blue }
</style>
</head>
<body>
<div class="normal">class=&quot;normal&quot;</div>
<div class="special">class=&quot;special&quot;</div>
<div class="normal special">class=&quot;normal special&quot;</div>
<div class="special normal">class=&quot;special normal&quot;</div>
</body>
</html>

The results are sort of what I expected… the top div (normal) is red and bold, the second (special) is blue and not bold, the other two are applying both, but the order of the classes in the list doesn’t matter. So they are getting the bold from the normal style, and the background from the special style.

Great. So why didn’t it work in my application? I finally figured it out. If, in my test, I reversed the order of the declaration of the styles (so that ’special’ is declared first) and the results are very different, the ’special’ class is ignored completely.

That’s right, the styles are applied in the order they are declared in the document, the order they are listed in the element has no effect. That I now understand (although I didn’t know it previously). But what I find more suprising, is that the order of stylesheets files that are linked is also subjected to this hierachy.

For example, if (from my test page) I remove the special style, and put it in an external style sheet, and include it like so:


<style type="text/css">
.normal { font-weight: bold; background-color: red;}
</style>
<link rel="stylesheet" type="text/css" href="stylesheet.css" />

It works, but doing this doesn’t:


<link rel="stylesheet" type="text/css" href="stylesheet.css" />
<style type="text/css">
.normal { font-weight: bold; background-color: red;}
</style>

So the include is exactly the same as typing in the style in the file. Whereas I was under the impression that styles in the file took precedence over those in external (linked) stylesheets (where they overlap of course). But it seems I was wrong. Now I know.

post DNS (Bind9) Configuration

November 2nd, 2006

Filed under: Debian, Linux, Operating Systems — Brenton Alker @ 18:56

I have just set up a local DNS (bind9) server on my network, mainly because I got tired of forever editing my ‘hosts’ files, and just to see if I could… I have worked with DNS servers mainly through web-based front-ends, so I wanted to find out what the configuration really looked like. The most helpful and complete resource I came across was the BIND 9 Administrator Reference Manual (Good title). Here is the configuration I finally came up with (and some associated notes).

The Configuration Files

The ‘named.conf’ file that usually contains the main configuration information is split into 3 seperate files on the debian install.

named.conf

The ‘named.conf’ file is located in the ‘/etc/bind/’ directory, this is the main bind configuration directory on a debian install. The ‘named.conf’ file itself is written so there is probably no need to edit it. All personalisation of the service can be done using the ‘named.conf.options’ and ‘named.conf.local’ files that are referenced in the ‘named.conf’.

named.conf.options

‘named.conf.options’ pretty much contains the options block that is usually found in the top of the ‘named.conf’ file.

The directory parameter specifies the root directory where all relatively referenced files can be found (this is the default on debian)

The forwarders is a list of DNS servers that this server can ‘forward’ the query to if it doesn’t know the answer. This is pointed at my ISP’s normal DNS server (in this case, via the network router)

The auth-nxdomain directive instructs the server to answer as an authoritative source for non-existant (nx) records. It is generally a bad idea.

The allow-query directive is fairly self-explanatory, it provides a list of IP ranges that are permitted to query this server. In this case, I have limited access to the localhost and the private network.

The listen-on directive is similar, it provides a list of IPs that the server should listen on. In my case this is only the loopback and the private interface.


options {
directory "/etc/bind";
forwarders {
192.168.1.1;
};
auth-nxdomain no; # conform to RFC1035
allow-query {
192.168.1.0/24; # Only allow queries from the network and local machine
127.0.0.0/24;
};
listen-on {
192.168.1.100;
127.0.0.1;
};
};

On the debian package the file ‘named.conf.local’ is referenced by the ‘named.conf’ to provide information about the setup specific to this server. As such, there is little or no need to edit the ‘named.conf’ itself. My ‘named.conf.local’ defines 2 zones; ‘everyone-here.is-a-geek.com’, whichs maps the computers on the LAN, and the ‘1.168.192.in-addr.arpa’ zone, which provides the reverse dns information. While this is (especially on a LAN) pretty much un-used as far as I know, it’s still good practice to put it in, and it can be useful at times for resolving the "Which computer connected to my server?" question.

The type ‘master’ tells the server that it is the authority for this zone, and it should be able to answer definitively about requests for systems in it.

The file points to the ‘database’ file containing specific information about the contents of the zone. This file is relative to the path given earlier, but an absolute path can also be used.


//Add the zone for normal DNS lookup
zone "everyone-here.is-a-geek.com" {
type master;
file "db.everyone-here.is-a-geek.com";
};

The reverse zone is exactly the same as the forward zone. All reverse DNS zones end in ‘.in-addr.arpa’, the rest of the address is the IP in reverse (i.e 192.168.1. is my internal IP range, so to allow lookups I add entries for ‘1.168.192.in-addr.arpa’)


//Add the zone for reverse lookups
zone "1.168.192.in-addr.arpa" {
type master;
file "db.192";
};

The Database file(s)

db.everyone-here.is-a-geek.com

This one probably needs a bit more explanation, I think it’s easier if I comment it inline. Two important things to remember everything that doesn’t end in a "." will be prepended to the base domain, and the @ is substituted for the base domain.


$TTL 604800
$ORIGIN everyone-here.is-a-geek.com. ;The base domain name (From now on = @)
@ IN SOA gir webmaster (
1 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ NS gir ;This is the nameserver
@ MX 10 gir ;mail sent to @everyone-here.is-a-geek.com goes to this server
@ A 192.168.1.100 ;the "A" record specifies a direct pointer to the IP address
gir CNAME @ ;each "CNAME" points to another entry (or domain) in this case gir points to the base domain
* CNAME gir ;and everything (*) points to gir
ben A 192.168.1.69 ;My housemates desktop - an "A" record pointing to Ben's static IP
zyrtec A 192.168.1.150 ;My desktop machine - ditto for mine

And the reverse table works the same way as the forward ones, except with the special .in-addr.arpa postfix.

/etc/bind/db.192


$TTL 1D
$ORIGIN 1.168.192.in-addr.arpa.
@ IN SOA gir.everyone-here.is-a-geek.com. hostmaster.everyone-here.is-a-geek.com. (
1 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ NS gir.everyone-here.is-a-geek.com. ;Add entries for all known IP->hostname maps in the domain
100 PTR gir.everyone-here.is-a-geek.com.
150 PTR zyrtec.everyone-here.is-a-geek.com.
69 PTR ben.everyone-here.is-a-geek.com.

So there you have it, thats pretty much the guts of my DNS configuration. It took some tweaking to get it right (syslog is you best friend on this one) but it now works for my needs.

post Easy Deployment from Subversion

November 2nd, 2006

Filed under: Code, Linux, Subversion — Brenton Alker @ 00:11

After recently discovering the ways in which a version control server, combined with a sensible set of deployment scripts, can development easier (up until now the ones I have used have all been poorly configured and more of a hindrance then a help). I moved some of my personal projects onto my subversion server.

I have been using subversion for some years to manage the configuration files on my Linux boxen, on the suggestion of an article I read at one time but can’t now find a link for (there are some similar ones available), all those fiddly kernel configs and xorg.conf files that you tweak until they break, then can’t remember what you changed.

Being in charge of the version control systems at work, I am always looking for better and easier ways to keep the latest versions checked in and easily deploy to the live servers (and be able to roll it back if it all goes up in flames). So with the help of a few simple shell scripts, I finally have a system that allows my to edit and test locally before committing and deploying to the live sites.

The most basic of which sits in ~/bin/ and looks something like this:

deploy-project

svn export svn://svn.repository.server/project/trunk/ /tmp/project/
rsync -vrz --rhs=ssh --progress /tmp/project/public_html user@remote.live.site.com:~/public_html
rm -rf /tmp/project/

Of course this is only the basic form, with all values hard coded, there are more advanced scripts that take arguments, for example I use –live to deploy to the live server as opposed to the (default) staging/test server, or allow the the name of the branch/tag and revision to be specified.

This allows easy deployment of code bases in a fairly efficient manner. I am still struggling with control of database structures, I currently start with an SQL dump of the schema, and then incrementally store SQL scripts to update the database to newer versions to allow deployment on various sites. I am considering writing a tool to compare the schema of 2 databases and provide SQL code to transform one into the other… when I get time.

Now I just need to convince the developers to use it.

ruldrurd
« Previous Page
Powered by WordPress, Web Design by Laurentiu Piron Monitored by SiteUpTime
Entries (RSS) and Comments (RSS)