View Full Version : CSS element not to take style from tag - please help
me_myself
06-30-2010, 08:35 PM
I was thinking for 10mins on how to title this post !!??!!
Here's my issue - for a reason i had to give a base style for div
div {padding:0; margin:0; border:0;}
this applies to all the div element in the page. Now i need to have one single div inside an ID with padding, margin and border. I tried
#idname div{margin:10px; padding-left:5px; border:1px solid #ccc;} This does not seem to work. How do i make this div inside the id alone to have a different style than the rest - please let me know how to make this to work?
Thanks a million.
auntnini
07-01-2010, 12:37 AM
Why do you "have to give a base style to DIV"?
You can create an ID (should be one, unique to page) with # or class with . (period). Then in your HTML markup
<div id="idname"> ...</div>
or
<div class="classname"> ... </div>
DIVs can be nested.
It would be helpful to see your page online and your total markup.
me_myself
07-01-2010, 07:06 PM
For some strange and unkown reason the guy who worked on this before had done it. The website is pretty big and i dont want to mess around with all the div tags. Any idea how to make just one element inside an id a little different from the rest (not to take the global style)?
My finger burns googling for answers :eek:
Thanks for the reply.
azoomer
07-01-2010, 07:30 PM
To me it looks like you are very close to the solution. If you have given the insider div an id="idname" , then you probably just need to change the css to this:
#idname {margin:10px; padding-left:5px; border:1px solid #ccc;}
and it should work. You may have to place it below the other css.
On the other hand, if the div inside does not have its one id or class you might want to target it with something like this
#outside div:first-child {
margin:10px;
padding-left:5px;
border:1px solid #ccc;
}
me_myself
07-01-2010, 07:53 PM
Is "first-child" name of the class for the div?
azoomer
07-01-2010, 09:11 PM
:first-child is not really a class name, it is a pseudo class or pseudo selector that selects the first descendant element inside a parent. In this case if you have a div with the id="outside" the div:first-child will select the first div element inside of this div. I can't really explain it better ( English is not my language) but you can google it. Maybe you can use it to get the style you need.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.