473,396 Members | 1,797 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,396 software developers and data experts.

Why is the same property defined twice here?!

Hi i'm exploring a tutorial stylesheet which uses the following code

#header ul li a {

....
line-height: 0.8em !important;
line-height: 1em;
....
}

Can someone tell me why there are two entries for the same property
(line-height) please?

Thankyou

Gary

Feb 8 '07 #1
7 2848
Scripsit Gary:
Hi i'm exploring a tutorial stylesheet
Which one? Does it have a URL, or an ISBN?
which uses the following code

#header ul li a {

...
line-height: 0.8em !important;
line-height: 1em;
...
}
Rather strange. Even the first setting is odd - making line height smaller
than font size, and with !important at that. Setting it to the font size, as
in the second declaration, is generally a bad idea, too.
Can someone tell me why there are two entries for the same property
(line-height) please?
What did the author of the tutorial answer when you asked him?

My guess would be that the declarations are as such irrelevant, just
examples (but shouldn't you avoid _idiotic_ examples when writing a
tutorial?), and you, the reader, are supposed to figure out which
declaration "wins" by the cascade rules.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

Feb 8 '07 #2
On Feb 8, 12:58 pm, "Jukka K. Korpela" <jkorp...@cs.tut.fiwrote:
Scripsit Gary:
Hi i'm exploring a tutorial stylesheet

Which one? Does it have a URL, or an ISBN?
which uses the following code
#header ul li a {
...
line-height: 0.8em !important;
line-height: 1em;
...
}

Rather strange. Even the first setting is odd - making line height smaller
than font size, and with !important at that. Setting it to the font size, as
in the second declaration, is generally a bad idea, too.
Hi it's an open source tutorial style sheet called Nautica05, but has
little commentary... I've used the css tutorial on html.net and am now
exploring live designs that I like to get a feel for them. Perhaps if
you can spare 5 minutes you would take a look at it for me and tell me
if you are any wiser about why he's done that?

Here is the link to it...http://www.opensourcetemplates.org/templates/
nautica05/Nautica05.zip

Thanks very much,

Gary
Can someone tell me why there are two entries for the same property
(line-height) please?

What did the author of the tutorial answer when you asked him?

My guess would be that the declarations are as such irrelevant, just
examples (but shouldn't you avoid _idiotic_ examples when writing a
tutorial?), and you, the reader, are supposed to figure out which
declaration "wins" by the cascade rules.

--
Jukka K. Korpela ("Yucca")http://www.cs.tut.fi/~jkorpela/

Feb 8 '07 #3
On 8 Feb, 12:41, "Gary" <garyuse...@myway.comwrote:
line-height: 0.8em !important;
line-height: 1em;
Can someone tell me why there are two entries for the same property
(line-height) please?
They're different rules. Same property, same block (which obviously
implies the same selector). However they have two differences: firstly
one has the "important" keyword added to it, secondly one comes after
the other.

In general, CSS has complicated rules for the cascade and the
"specificity" of the various selectors.
You need to read (and carefully!) the CSS spec for this
http://www.w3.org/TR/CSS21/cascade.html

This case is a bit simpler though, because specificity and origin is
identical for these two rule as they're the same selector in the same
stylesheet. That just leaves the importance and the order to worry
about.

Usually the last rule specified (by order) wins and duplicate rules
simply over-write their predecessors. However this is the very last
CSS ordering step and is of low priority. The important declaration is
of much higher priority (even beating selector specificity) and is of
comparable priority to its origin from either the user or author
stylesheets (the relative prioritisation of these has varied over the
history of CSS). In this case, the first rule simply trumps the later
rule in all cases.

So the 2nd rule is demonstrably superfluous. Hopefully the purpose of
the "tutorial" was to encourage you to spot this, otherwise it's not a
good tutorial to be leaving such dross lying around in it. I _hope_
that the author didn't misunderstand things and thought that the 2nd
rule could _ever_ win, just because it came later?
Line-height should have an initial default of about 1.2. Setting it to
less than 1 is certainly perverse. Although some logos do it
justifiably, I can't imagine it being a good idea in a list of links.
In practice, just leave the damned thing alone, you'll only break
stuff!

It's also a good idea to set line-height as a number (e.g. 1.2) rather
than in a length unit such as ems. This avoids some problems that
might arise if the now-fixed line-height gets inherited by an element
with a different.font size.



Feb 8 '07 #4
Thankyou im just starting out with css and it's a steep learning
curve. I will re read the advice and digest it slowly.

One question however is your comment relating to ems - i have read on
this (as i hadn't encountered them before this stylesheet) and wrongly
or rightly concluded that they were very powerful for just the fact
you mentioned as being there weakness - i.e. their inheritance of
parant element font size.

I thought that by using ems the designer had ensured a 'fluid' design,
is this a bad practice? or have i mis understood this?

Thanks,

Gary.

On Feb 8, 3:25 pm, "Andy Dingley" <ding...@codesmiths.comwrote:
On 8 Feb, 12:41, "Gary" <garyuse...@myway.comwrote:
line-height: 0.8em !important;
line-height: 1em;
Can someone tell me why there are two entries for the same property
(line-height) please?

They're different rules. Same property, same block (which obviously
implies the same selector). However they have two differences: firstly
one has the "important" keyword added to it, secondly one comes after
the other.

In general, CSS has complicated rules for the cascade and the
"specificity" of the various selectors.
You need to read (and carefully!) the CSS spec for thishttp://www.w3.org/TR/CSS21/cascade.html

This case is a bit simpler though, because specificity and origin is
identical for these two rule as they're the same selector in the same
stylesheet. That just leaves the importance and the order to worry
about.

Usually the last rule specified (by order) wins and duplicate rules
simply over-write their predecessors. However this is the very last
CSS ordering step and is of low priority. The important declaration is
of much higher priority (even beating selector specificity) and is of
comparable priority to its origin from either the user or author
stylesheets (the relative prioritisation of these has varied over the
history of CSS). In this case, the first rule simply trumps the later
rule in all cases.

So the 2nd rule is demonstrably superfluous. Hopefully the purpose of
the "tutorial" was to encourage you to spot this, otherwise it's not a
good tutorial to be leaving such dross lying around in it. I _hope_
that the author didn't misunderstand things and thought that the 2nd
rule could _ever_ win, just because it came later?

Line-height should have an initial default of about 1.2. Setting it to
less than 1 is certainly perverse. Although some logos do it
justifiably, I can't imagine it being a good idea in a list of links.
In practice, just leave the damned thing alone, you'll only break
stuff!

It's also a good idea to set line-height as a number (e.g. 1.2) rather
than in a length unit such as ems. This avoids some problems that
might arise if the now-fixed line-height gets inherited by an element
with a different.font size.

Feb 8 '07 #5
Scripsit Gary:
Thankyou im just starting out with css and it's a steep learning
curve. I will re read the advice and digest it slowly.
Please google for "how do I quote correctly in Usenet" and fix your posting
habits accordingly.
One question however is your comment relating to ems -
Which comment? You should have quoted that very comment, and only it, to
establish context for what you are writing about.
i have read on
this (as i hadn't encountered them before this stylesheet) and wrongly
or rightly concluded that they were very powerful for just the fact
you mentioned as being there weakness - i.e. their inheritance of
parant element font size.
You're wrong. Inheritance is not the issue in using em. As a rule of thumb,
_everyone_ gets inheritance all wrong when starting to learn CSS and gets
more and more confused with it. The only cure is to get a decent textbook
and read it.

The reason for using line-height: 1.2 rather than line-height: 1.2em is that
for this specific property, 1.2 _means_ by definition the same as 1.2em
_but_ so that if the value is inherited, it is the declared value and not
the computed value that gets inherited. This matters if inner elements have
a different font size.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

Feb 8 '07 #6
On 8 Feb, 15:37, "Gary" <garyuse...@myway.comwrote:
I thought that by using ems the designer had ensured a 'fluid' design,
It's a good and fluid practice on almost everything except line-
height !

If you set line-height to ems (maybe 1.2em), then it works fine for
the element where you set it and has the same effect as using 1.2
However on a child element with a different font size (and line-height
not set again) then it will keep the same computed value as before --
which is now inappropriate for the new font-size. Setting it with a
number ratio causes it to be re-calculated from the box's height (i.e.
font size) each time, so it stays in proportion.

http://www.w3.org/TR/CSS21/visudet.h...ef-line-height
As to ems in general though, then yes, it's a good practice to use
them. The only thing better is to not have to set a size (or
especially a position at all) and simply let the renderer work it
out. Give two things a margin if needs be and let them flow, don't
try to set absolute positions on everything through some wrong-headed
notion of "control".

There are also good reasons why you'd use horizontal sizes in pixels
(to work with fixed image sizes) or in percentages (to apportion
columns). In general though, vetical dimensions are better in ems.
Even around images, you can usually work by not setting the height at
all and just letting the renderer work it out. Mixing two length
units for the same direction amongst sibling elemnts can be powerful,
but gets very hard to debug.

Feb 8 '07 #7
Scripsit Gary:
Hi it's an open source tutorial style sheet called Nautica05,
Sounds confusing - tutorial or template?
Here is the link to it...http://www.opensourcetemplates.org/templates/
nautica05/Nautica05.zip
I'm not that interested in opening zip packages to access something as
simple as a web page template, but this time I did. Their visual design has
nice ideas, but their CSS implementation for them is rather awkward. The
following should ring some bells:

body {
- -
font: 400 0.7em verdana, arial, sans-serif;
line-height: 170%;
- -
}

Just stay away from them, especially if you are a novice in CSS matters. At
least don't copy their CSS code, even if you decide to try some ideas of
theirs.

The issue with setting the same property twice that you noticed was probably
_unintentional_ mess, caused by sloppy CSS coding (not removing an old
setting when adding a new one to override it) or mixing different people's
CSS code.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

Feb 8 '07 #8

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

Similar topics

27
by: skeeterbug | last post by:
please see http://www.geocities.com/operationsengineer1/test.htm for an idea of how i want my logo header div to be layed out. when i went to resize "Test" to 2em (from 1em), this is what...
16
by: sneill | last post by:
How is it possible to take the value of a variable (in this case, MODE_CREATE, MODE_UPDATE, etc) and use that as an object property name? In the following example I want 'oIcon' object to have...
18
by: Robin Becker | last post by:
Is there a way to override a data property in the instance? Do I need to create another class with the property changed? -- Robin Becker
17
by: Steve R. Hastings | last post by:
I have been studying Python recently, and I read a comment on one web page that said something like "the people using Python for heavy math really wish they could define their own operators". The...
1
by: Rob Meade | last post by:
Hi all, At work one of my colleagues wrote a set of classes that we use in a common class library within our applications. Although I use this on a daily basis I haven't actually looked at his...
6
by: wenmang | last post by:
Here is the code which causes core dump when is built differently, 1 for regular dev built, the other for packaging build. class my_class{ public: my_class(){}; ~my_class(){}; private:...
8
by: Dean Slindee | last post by:
I have a form whose Property value I need to get at from a class (contained in another project, same solution). Here is the form's property: Private booIsInsert As Boolean = False Public...
2
by: parvtb | last post by:
Thanks for your patience to read the entire post to understand my confusion I have the user-defined class "tools": class tools{ public: tools( ......) {} friend bool operator<...
4
by: FullBandwidth | last post by:
I have been perusing various blogs and MSDN pages discussing the use of event properties and the EventHandlerList class. I don't believe there's anything special about the EventHandlerList class in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.