+ Reply to Thread
Page 1 of 2
1 2 LastLast
Results 1 to 10 of 15

Thread: Inheritance + CSS

  1. #1
    fobby is offline Coder fobby will become famous soon enough
    Join Date
    Dec 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Inheritance + CSS

    I'm learning about Inheritance in CSS and have found out that the all tags take the properties (well not all) of the tag they are inside.


    I realized my problem when I tried to add a border to a div tag that was nested in another div tag. It was pointless because it just took the value of the outside div tag ? So how do I change the values of a nested div tag independently of the outer tag ?

    thanks ..

  2. #2
    louie's Avatar
    louie is offline Senior Member louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough
    Join Date
    Jan 2006
    Location
    Dublin, Ireland
    Posts
    2,328
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    did you try giving the nested div a class?

    Code:
    <style type="text/css">
    .main{border:1px solid #cccccc; width:500px; padding:5px;}
    .sec{border:1px dashed #000000;}
    </style>
     
    <div class="main"> main div
     <div class="sec">
     nested div
     </div>
    </div>
    
    :. Web Design & Development Web Design Ireland
    :. Search Engines Optimization Search Engines Optimization
    :. Car Parts & Accessories Car Parts
    :. Cars Ireland Cars Ireland
    :. I Have 2 Find It Directory SEF Directory

  3. #3
    fobby is offline Coder fobby will become famous soon enough
    Join Date
    Dec 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Yes, thats how I tried it, then linked to an external style sheet. Maybe I should post some code to see clearer, will post tonight, thanks

  4. #4
    uncleseanie is offline Frontpage User uncleseanie will become famous soon enough
    Join Date
    Dec 2006
    Location
    dublin, ireland
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by louie View Post
    did you try giving the nested div a class?

    Code:
    <style type="text/css">
    .main{border:1px solid #cccccc; width:500px; padding:5px;}
    .sec{border:1px dashed #000000;}
    </style>
     
    <div class="main"> main div
     <div class="sec">
     nested div
     </div>
    </div>
    
    in the above example "sec" will inherit the width and padding properties.
    so if you want to change the width then you will to explicitly state it
    in .sec

  5. #5
    daviddoran's Avatar
    daviddoran is offline Wannabe Geek daviddoran will become famous soon enough
    Join Date
    Aug 2006
    Location
    Meath, Ireland
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I'm not sure what you mean by inherit in this situation.
    When displayed, the "sec" box will have a black dashed border and will not have any padding or set width (it stretched to be the size of the parent minus padding). So it has not inherited any of the properties of the parent box.

  6. #6
    fobby is offline Coder fobby will become famous soon enough
    Join Date
    Dec 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    take a particular example,

    I want to put a left margin in the div class "links". I think the code in the .links css is pointless because the links div tag is inside the container div id and therfore will take the css values of the parent tag ? Is this the case, seems to be what is happening.

    So then how do I apply values to the nested <div> (class links in this case) ?

    edit > ... having more issues with this, using dreamweaver (find it handy for learning the tags before you give out to me ), if I change any font in the div container, every font inside the container changes too ! missing something fundamental here !


    <div id="container">

    <div class="links">
    <p>About</p>
    <p>Services</p>
    <p>Portfolio</p>
    </div>
    </div>

    #container {
    position: absolute;
    left: 43px;
    top: 29px;
    width: 689px;
    height: 503px;
    background-color: #FFFFFF;

    }

    .links {
    position: absolute;
    left: -1px;
    top: 113px;
    height: 168px;
    width: 161px;
    background-color: #CCCCCC;
    font-size: 24px;
    color: #FFFFFF;
    border-left-color: #00FF00;
    border-left-width: thick;
    }
    Last edited by fobby; 20-01-2007 at 01:05 AM.

  7. #7
    gary.b is offline insert-witty-remark-here gary.b will become famous soon enough
    Join Date
    Oct 2006
    Location
    Dundalk
    Posts
    167
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Eh? err.. sorry - CSS at 1am doesn't go down well.

    I'm not exactly sure what you want.

    Just post a gif image of what you want the thing to look like - i'll try to give you the CSS (or at least explain it :P)

  8. #8
    daviddoran's Avatar
    daviddoran is offline Wannabe Geek daviddoran will become famous soon enough
    Join Date
    Aug 2006
    Location
    Meath, Ireland
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    This will only happen with text because when you set the text color of the parent tag you are setting the style of the text, not the container per-se. (Yes guys, let's ignore whether this is technically correct)

  9. #9
    louie's Avatar
    louie is offline Senior Member louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough
    Join Date
    Jan 2006
    Location
    Dublin, Ireland
    Posts
    2,328
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Did you try adding margin-left:5px; to the links class?

    can you make a draw of what you want to achieve?
    :. Web Design & Development Web Design Ireland
    :. Search Engines Optimization Search Engines Optimization
    :. Car Parts & Accessories Car Parts
    :. Cars Ireland Cars Ireland
    :. I Have 2 Find It Directory SEF Directory

  10. #10
    fobby is offline Coder fobby will become famous soon enough
    Join Date
    Dec 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Here is a screen shot of what I want to do. I want to put a margin and or border on the left of the inside box (div links). My code is below. From the screen shot it looks like the border is there, but the colour (bright green just to see better) is not.

    See the warning message on the left in Dreamweaver also.

    "border-left-color does not apply to your selection because it is not inherited . It is applied to an enclosed tag."

    I also get a similar message relating to the background of the enclosed tag.

    background-colour does not apply to your selection because it is not inherited. It is applied to an enclosing tag. However, page elements are transparent by default, so this colour may show through."



    <body>
    <div id="container">
    <div class="links">
    <p>About</p>
    <p>Services</p>
    <p>Portfolio</p>
    </div>
    </div>
    </body>
    </html>


    /* CSS Document */

    #container {
    position: absolute;
    left: 43px;
    top: 29px;
    width: 689px;
    height: 503px;
    background-color: #FFFFFF;
    font-style: normal;
    font-family: "Times New Roman", Times, serif;

    }


    .links {
    position: absolute;
    left: -1px;
    top: 113px;
    height: 168px;
    width: 161px;
    background-color: #CCCCCC;
    font-size: 24px;
    color: #FFFFFF;
    border-left-color: #00FF00;
    border-left-width: thick;
    margin-left:5px;
    }
    Attached Images

+ Reply to Thread
Page 1 of 2
1 2 LastLast

Similar Threads

  1. CSS Issue for Wordpress Menu..
    By Cormac in forum Coding Help
    Replies: 4
    Last Post: 03-12-2006, 03:12 PM
  2. some simple store with css based layout
    By kuba77 in forum Site Reviews / Announcements
    Replies: 1
    Last Post: 30-11-2006, 03:07 PM
  3. How to make a H1 tag in CSS into a link
    By shanediffily in forum Coding Help
    Replies: 4
    Last Post: 10-10-2006, 04:54 PM
  4. dynamic css
    By 7aken in forum Coding Help
    Replies: 6
    Last Post: 10-10-2006, 08:13 AM

Visitors found this page by searching for:

Nobody landed on this page from a search engine, yet!
SEO Blog

Tags for this Thread

Posting Permissions

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

Search Engine Optimization by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64