473,396 Members | 1,997 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.

CSS margin overriding problem

xen
Hey there,

In my html file I use a <div class="quote">.
In my css file I define .quote
I need to specify the margins for <pinside the <div>
Today I learned that I can do this using

..quote p {
margin-top: 5px;
margin-bottom: 5px;
}

All is well. Now inside this <div class="quote"I want to be able to
have a couple of <pblocks use different, bigger margins. So I define
a new class

..quote-walsch {
margin-top: 15px;
margin-bottom: 15px;
color: red;
}

and hope to use it using <p class="quote-walsch">

However, this doesn't work.
The <pas redefined for class "quote" overrides the margins for class
"quote-walsch", effectively disabling those margin settings. The color
"red" does apply so the class is in effect, but he margins get
overridden. If I apply the new margins using an inline style attribute

<p style="margin-top: 15px; margin-bottom: 15px;">

then it does work.

So as far as I can see, I can do one of two things.

1) do not use classes for the bigger-margin <pblocks but use inline
style attributes
2) do not define ".quote p" but instead define ".quote-p" and apply
this class to every regular p block using <p class="quote-p">.

I would like to use ".quote p" AND apply bigger margins to several <p>
blocks using classes. Is this possible? All browsers I use (IE4,
Opera7, FF2) behave the same.

Feb 27 '07 #1
3 3894
In article
<11**********************@s48g2000cws.googlegroups .com>,
"xen" <xe*@rotmail.nlwrote:
Hey there,

In my html file I use a <div class="quote">.
In my css file I define .quote
I need to specify the margins for <pinside the <div>
Today I learned that I can do this using

.quote p {
margin-top: 5px;
margin-bottom: 5px;
}

All is well. Now inside this <div class="quote"I want to be able to
have a couple of <pblocks use different, bigger margins. So I define
a new class

.quote-walsch {
margin-top: 15px;
margin-bottom: 15px;
color: red;
}

and hope to use it using <p class="quote-walsch">

However, this doesn't work.
The <pas redefined for class "quote" overrides the margins for class
"quote-walsch", effectively disabling those margin settings. The color
"red" does apply so the class is in effect, but he margins get
overridden. If I apply the new margins using an inline style attribute

<p style="margin-top: 15px; margin-bottom: 15px;">

then it does work.

So as far as I can see, I can do one of two things.

1) do not use classes for the bigger-margin <pblocks but use inline
style attributes
2) do not define ".quote p" but instead define ".quote-p" and apply
this class to every regular p block using <p class="quote-p">.

I would like to use ".quote p" AND apply bigger margins to several <p>
blocks using classes. Is this possible? All browsers I use (IE4,
Opera7, FF2) behave the same.

It is unclear if you have also used .quote-walsch p {...} to
mirror your "successful" use of .quote p {...}.

By the way, look up "blockquote". it might be more appropriate
for your use. You can style these too... If you are going to need
different margins and colors etc, probably safest to set all
explicitly for each class in your case.

Why don't you post a url so we can see what you are doing. Vot
you are really doing!

--
dorayme
Feb 27 '07 #2
On 2007-02-26, xen <xe*@rotmail.nlwrote:
Hey there,

In my html file I use a <div class="quote">.
In my css file I define .quote
I need to specify the margins for <pinside the <div>
Today I learned that I can do this using

.quote p {
margin-top: 5px;
margin-bottom: 5px;
}

All is well. Now inside this <div class="quote"I want to be able to
have a couple of <pblocks use different, bigger margins. So I define
a new class

.quote-walsch {
margin-top: 15px;
margin-bottom: 15px;
color: red;
}

and hope to use it using <p class="quote-walsch">

However, this doesn't work.
The <pas redefined for class "quote" overrides the margins for class
"quote-walsch", effectively disabling those margin settings. The color
"red" does apply so the class is in effect, but he margins get
overridden. If I apply the new margins using an inline style attribute
This sounds like a "specificity" problem. Try ".quote .quote-walsch" for
the second selector, or ".quote p.quote-walsch" to be sure and see

http://www.w3.org/TR/CSS21/cascade.html#specificity
><p style="margin-top: 15px; margin-bottom: 15px;">

then it does work.

So as far as I can see, I can do one of two things.

1) do not use classes for the bigger-margin <pblocks but use inline
style attributes
2) do not define ".quote p" but instead define ".quote-p" and apply
this class to every regular p block using <p class="quote-p">.
Those solutions would work too.
I would like to use ".quote p" AND apply bigger margins to several <p>
blocks using classes. Is this possible? All browsers I use (IE4,
Opera7, FF2) behave the same.
Should be fine, just provide specific-enough selectors to get the
margins all the way to where you want them to go.

If .quote .quote-walsch doesn't match quote-walsches outside .quotes,
elsewhere in the document, and that's what you want, you can just write
it a bit tautologically like this:

..quote-walsch, .quote .quote-walsch { ... };

which means "anything with class quote-walsch or that has class
quote-walsch and is a descendent of a .quote". I suppose you could read
it as "anything that's .quote-walsch even if it's inside a .quote".
Feb 27 '07 #3
xen
Thanks for the replies.

I changed my <div class="quote"to <blockquoteand styled the
blockquote element instead.
This sounds like a "specificity" problem. Try ".quote .quote-walsch" for
the second selector, or ".quote p.quote-walsch" to be sure and see
It worked! :). I now use "blockquote p.quote-walsch" and so on.

You can see the page at:
http://www.xen.dds.nl/geefhandel/geefhandel.html

It's a Dutch page, but do read the English quotes ;).

Feb 27 '07 #4

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

Similar topics

9
by: James Marshall | last post by:
I'm writing a library where I want to override document.write(), but for all document objects; thus, I want to put it in the prototype. I tried Document.prototype.write= my_doc_write ; but it...
3
by: Brian | last post by:
I have a page with content, navigation, and footer divs, in that order. The nav div has position: absolute, width 8em, on green background. The other divs have an 8em green left border, such that...
22
by: moocow | last post by:
Hi. I am using a background image in a form button. The problem I am having is that there is a 1 pixel margin inside the button on all sides. I would like my background image to fill the...
19
by: Thomas Mlynarczyk | last post by:
Hello, The following gives different results in IE and "Non-IE" browsers: <div style="background-color: green; width: 200px"> <div style="margin-top: 20px; background-color: red"> Hello...
3
by: Amin Sobati | last post by:
Hi, I have two classes. Class2 inhertis Class1: ----------------------------- Public Class Class1 Public Overridable Sub MySub() End Sub End Class Public Class Class2
6
by: boclair | last post by:
I have been approached over a page that has a horizontal menubar displaying over a banner. The problem advised that the menubar is not displayed and the banner moves up to the position the menubar...
10
by: Alan Silver | last post by:
Hello, In my (seemingly) endless quest to understand CSS, I have yet another problem. Please look at http://www.kidsinaction.org.uk/ph/x.html in Opera, where you will see it how I expected. If...
1
by: Dave Siegel | last post by:
Hi, I've made a container div and put 2 div's inside of that for easy positioning.. The problem is that the container div has a standard 10px or so top margin which makes it go down too much.....
1
by: innivive | last post by:
I am having a problem with having margins display correctly in IE7, Firefox and Safari. I am not sure if it is the "double margin error" or something else. Any help would be appreciated. The file...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.