views:

91

answers:

2

If this a situation.

p{margin-bottom:5px}
#top-textContainer p {margin-bottom:10px}

Is there a way to write this in a shorter way , or no other option

#board-committees #top-textContainer p, 
#corporate-governance #top-textContainer p,
#corporate #top-textContainer p,
#about-us #top-textContainer p,
#contact us #top-textContainer p{margin-bottom:15px}

Can anyone suggest me better question heading and improve my question?

A: 

Set the margin-bottom of every element (p, #top-textContainer, etc.) you mentioned to 5px? So the margins accumulates to the value you need.

KennyTM
A: 

What you failed to mention in your initial post is that since you are using a CMS, you don't have control over your HTML source files, only over your CSS.

You were also unclear about your aim, which is that from the 150 pages you have, you want some of them to have a paragraph with margin-bottom of 15px, but all the other pages to have 10px.

The answer under the abovementioned conditions:

No, there is no way to shorten the CSS code. Without adding specific class tags to your HTML, which you cannot do, there is no other way to distinguish the pages where you want 15px, from the pages where you want 10px, then what you have already done.

Exceptions to this rule:

  1. If the pages where you want the different margin, have some other specific characteristic, that could be selectable in CSS, you could base your selection on that and shorten the CSS code. For example, if your P would always be followed by a BR, or be part of an UL. But since I do not have your source, I don't know if it is possible.
  2. If your CMS offers the possibility to add custom class tags to pages or elements of your choice, you can refine your CSS based on the occurence of that particular class tag. But since I do not know your CMS, I also don't know if it is possible.
littlegreen
you are right but can't we use same id in css like html? i'm not having more than one id on any page . this is just in css
metal-gear-solid
i think u r getting my question wrong
metal-gear-solid
Maybe I am getting your question wrong, so can you please explain, why do you feel the need to specify the topTextContainer 5 times in your CSS, if there is only one of them in your page? I see no reason at all to include the board-directors, about-us etc id's in your CSS?
littlegreen
i have 150 pages on site but only for these pages if content is in #top-textContainer > p then i want to style differently. see my question , i've mentioned condition. and why i'm using #id than .class because it's CMS generated
metal-gear-solid
Edited my answer to reflect ur situation, sorry fore the styleup, im currently on mobile os
littlegreen
still getting wrong, all pages of site are having #top-textContainer p {margin-bottom:10px} but i want to apply {margin-bottom:15px} to some needed pages
metal-gear-solid
#topTextContainer p { margin ... } is already applied by default in at tp of the css file
metal-gear-solid
I indeed misunderstood your question, edited the answer to match.
littlegreen