Results 1 to 6 of 6

Thread: CSS element not to take style from tag - please help

  1. #1
    Join Date
    Aug 2007
    Location
    MO USA
    Posts
    106
    Thanks
    37
    Thanked 0 Times in 0 Posts

    Default CSS element not to take style from tag - please help

    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
    Code:
     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
    Code:
    #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.

  2. #2
    Join Date
    Oct 2006
    Location
    New York, NY, USA
    Posts
    245
    Thanks
    39
    Thanked 24 Times in 24 Posts

    Default Why?

    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

    Code:
     <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.

  3. The Following User Says Thank You to auntnini For This Useful Post:

    me_myself (07-01-2010)

  4. #3
    Join Date
    Aug 2007
    Location
    MO USA
    Posts
    106
    Thanks
    37
    Thanked 0 Times in 0 Posts

    Default

    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

    Thanks for the reply.

  5. #4
    Join Date
    Oct 2009
    Posts
    845
    Thanks
    14
    Thanked 189 Times in 188 Posts

    Default

    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

    Code:
    #outside div:first-child {
    	margin:10px;
    	padding-left:5px;
    	border:1px solid #ccc;
    }
    Last edited by azoomer; 07-01-2010 at 08:39 PM.

  6. The Following User Says Thank You to azoomer For This Useful Post:

    me_myself (07-01-2010)

  7. #5
    Join Date
    Aug 2007
    Location
    MO USA
    Posts
    106
    Thanks
    37
    Thanked 0 Times in 0 Posts

    Default

    Is "first-child" name of the class for the div?

  8. #6
    Join Date
    Oct 2009
    Posts
    845
    Thanks
    14
    Thanked 189 Times in 188 Posts

    Default

    :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.

  9. The Following User Says Thank You to azoomer For This Useful Post:

    me_myself (07-01-2010)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •