CSS: advice{councils} and receptions, a part 2
In this part I shall give you some advice which maintenance{contents} includes grouping selectors, horizontal alignment of the text, importation CSS and more some problem questions. If you here have not found something, try to esteem the first part.
Grouping of selectors
When at several types, classes or identifiers of an element the same properties are registered, you can group selectors to not specify identical properties some times. It will save a place - potentially much. You can register all selectors on one line or divide{share} their carry for other line.
For example, that for all elements of headings to specify family of fonts (font family), color and spaces, you can write CSS as follows:
h1, H3, h3, h4, h5, h6 {
font-family: " Lucida Grande ", Lucida, Arial, Helvetica, sans-serif;
color: * 333;
margin:1em 0;
}
If to compare to a situation when all properties register separately for each element the grouping saves decent volume of an empty seat. If it is a lot of identical properties, the economy of a place grows.
Then you can separately specify any properties, incoincident with other elements, for example the size of a font (font-size):
h1 {font-size:2em;}
H3 {font-size:1.6em;}
Specify styles of links in the correct order
When you apply CSS for different statuses of links, it is necessary to think of the order of an arrangement of rules. Basically, it is the best way to specify them in the following order::link:visited:hover:active. If to allocate the first letter of each of statuses the abbreviation "LVHA" will turn out then it is possible to transform this abbreviation in " LoVe HAte " (" Love Hatred " alt = src = " http: // www.umade.ru/images/smilies/smiley002.gif " border=0> or other easily remembered word-combination. About the order of statuses of links Erik Mayer in clause{article} Link Specificity (b¡``½) has well written..
To facilitate understanding that who moves under links with the help of the keyboard, it is possible to think of a status:focus. Thanking:focus it is possible to distinguish the selected link and the usual link. The choice of a serial place for:focus depends on desirable result. If you want, that the focused elements showed:hover effect it is necessary to specify:focus before:hover. If you want, that:focus rewrote effect:hover specify:focus the ambassador:hover.
Alignment on the center
It is rather simple way of alignment of elements on the center, but he deserves repeated attention as I see, that many newbies have with it problems. That the element was leveled is horizontal on the center, it is necessary to specify width and horizontal spaces of this element. If all marking of your page is made in the container as follows:
<div id = "wrap">
<! - Your layout goes here->
</div>
That you can make horizontal alignment on the center, using following CSS:
*wrap {
width:760px;/* Value of width should correspond{meet} to width of your marking */
margin:0 auto;
}
The width *wrap is subtracted from accessible width of a window, and the difference is in regular intervals distributed{allocated} between right and left spaces. The width not necessarily should be fixed - you can use any unit of measurements.
Internet Explorer 5-th version for Windows cannot process these values, but this browser has useful mistake in parsere which can be used to appropriate{give} property text-align for elements of a block level. If it is necessary for you, that the marking of page was displayed in this browser on the center instead of previous use following CSS:
body {
text-align:center;
}
*wrap {
width:760px;/* Value of width should correspond{meet} to width of your marking */
margin:0 auto;
text-align:left;
}
The first rule forces IE5/Win to level everything on the center, that is inside an element body. Other browsers level on the middle only the text. And as property text-align is inherited, the text in the document will be leveled on the center. Alignment of the text of all page on the center is necessary in the rare cases, therefore the following rule (text-align:left) rewrites this effect and levels the text which is taking place in the container *wrap, by a left edge.
Accordingly this reception can be used, that is horizontal to level elements of a block level be relative each other.
Importation and concealment CSS
The standard method of concealment of CSS-files from old browsers is use of reception @import. But, as far as I see, this reception often is used in such a manner that CSS does not disappear from Internet Explorer 4:
@import url ("main.css");
I for a long time thought of the possible{probable} decision of this problem. Somewhere I read, that the method @import hides CSS from out-of-date browsers but when I checked results of this reception in IE4 has found out, that this browser strongly deforms imported CSS. Instead of it I use the following syntax for @import:
@import "main.css";
Due to this, Internet Explorer 4 any more does not import a CSS-file. As an additional bonus, this reception saves a pair bajtov. To see, what browsers are involved by this syntax, look the table of filters.
Only and specially for Internet Explorer
Sometimes (more often), to solve a problem of incorrect processing CSS, browser Internet Explorer needs to send distinguished from usual CSS-rule.
Exists much CSS-khakov (roundabout ways), but I prefer to use a little from them, and only in that case, when I cannot find the best way (without use khakov) to reach{achieve} the necessary result. Will soon appear Internet Explorer 7 in which support CSS will be improved. Also developers recommend to not use roundabout ways (CSS-khaki) in general. Therefore the most safe will be use of special comments for IE (conditional comments) - full details below.
To hide a rule from IE, you can use child selector (b¡``½).:
html> body p {
/* declarations */
}
The asterisk and html will hide a rule from all browsers, except for IE:
* html p {
/* declarations */
}
You can sometimes be necessary to give out certain{determined} CSS for IE/Win, but not for IE/Mac. For this purpose you need to use zakommentirovannyj detour with the opposite slehshom:
/* \*/
* html p {
declarations
}
/* */
One more decision - I use it in increasing frequency as I think, that the next way is steadiest against the future changes, rather than CSS-khaki. I speak about special comments (conditional comments). You can use these comments to give out for IE/Win absolutely other CSS-file containing all necessary rules, intended for correct job of this browser. I think, what is it the best way preventing use of a deceit and a dirty in CSS-files. Also, you avoid an opportunity to spoil the "present"{"true"} CSS-file own expansions IE, such as expression (expressions) which are sometimes necessary.
<! - [if IE]>
<link rel = "stylesheet" type = "text/css" href = "ie.css"/>
<! [endif]->
Such comments give one more benefit preventing " flash of not stylized maintenance{contents} " (Flash of Unstyled Content) which appears in IE/Win in the event that in an element head there are no elements link or script.
What size of this square?
If something went not so, begin check of the CSS. Any can make a mistake.
If there are no mistakes in CSS it is necessary to start to analyze an event. To me to like to register colors of a back background to those elements, with which I have problems distinctly{clearly} to see space which is borrowed{occupied} with these elements. The some people suggest to use borders (borders), that works in many situations. A problem in this reception is that borders increase the sizes of an element, thus the top and bottom borders prevent connection of vertical spaces. It is much more safe than color of a back background.
One more potential property for a presence{finding} of a problem - property outline. An outline of a contour very similar on borders, but do not influence volumes or positioning of elements. A unique minus - absence of support of property outline in many browsers. As far as I know, at present this property support Safari, OmniWeb, and Opera.
Style CSS of a code
At spelling CSS, there are many various approaches to use of spaces, carries for other line and empty space. For all time I used various methods, but have stopped on the following style (at present):
selector1,
selector2 {
property:value;
}
When I gruppiruju selectors, I usually put each of them for a new line. I think what to search thus for elements in CSS much more easy. Further I put a blank between last selector and an opening bracket. Each announcement is on a separate line, without any blanks around of a colon dividing{sharing} properties (property) from values (value).
I finish each announcement a semicolon. It is possible to not finish after the latest announcement, but thus it is very easy to forget about addition of a semicolon before adding the new announcement that results in occurrence in CSS difficultly nakhodimykh mistakes.
At last, the closing bracket to be put for a separate line.
Yes, the empty space can be the good factor for udobochitaemosti a code, but it is pleasant to me, when all as is possible easier, without special negative influence on udobochitaemost`.

|