1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Override parent <div> width

Discussion in 'HTML & Website Design' started by ahdsan, Nov 15, 2010.

  1. #1
    I have a div with a width say '90px' and height say '50px'
    i have another div within this div, but i need this div to have 100% width but not relative to the parent div.

    <div class="fn-area" style="left: 288.594730238px; top: 176.61229611px; width: 222.045169385px; height: 104.943538269px; border-color: ;">

    <div class="fn-note">
    adfasdf
    </div>
    </div>

    I want the second div to take the width of the text inside it, sometimes it may be very long. right now it is wrapping the text on the basis of the width and height of the parent div. and also the width and height of the parent div cannot be removed.

    please help!
     
    ahdsan, Nov 15, 2010 IP
  2. GWiz

    GWiz Peon

    Messages:
    359
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try this: (bgcolor and width used for proof of concept)

    ...
    <div class="fn-note" style="position:absolute;width:100%;background:#CCC;">
    adfasdf
    </div>
    ...

    Applying the position:absolute; will essentially ignore the limitations of the parent element, however it may also ignore the position as well, in which case you will need to apply a position:relative to the parent block.
     
    GWiz, Nov 16, 2010 IP
  3. ahdsan

    ahdsan Member

    Messages:
    74
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    the class "fn-note" already has position: absolute and width:100%
     
    ahdsan, Nov 16, 2010 IP
  4. shahilroyhere

    shahilroyhere Well-Known Member

    Messages:
    189
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    130
    #4
    That's where you got the problem.
    Change to -
    width: auto;
    Code (markup):
    This should attain what you want.
     
    shahilroyhere, Nov 16, 2010 IP
  5. ahdsan

    ahdsan Member

    Messages:
    74
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #5
    i put there width:auto, still not working
    it takes the width of the parent div
    if i give some fixed width say 500px, it takes it.
    but i want that the child div take the width of the text within it
     
    ahdsan, Nov 16, 2010 IP
  6. ledison

    ledison Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    there are some difference from different browser.
     
    ledison, Nov 17, 2010 IP
  7. CSM

    CSM Active Member

    Messages:
    1,047
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    55
    #7
    That does not make any sense at all. Wrapping a div (auto width) into a div (fixed width)... You could give the "fixed width" div a min-width so it can "expand".

    Maybe you could show an online example...
     
    CSM, Nov 17, 2010 IP
  8. littlewing1977

    littlewing1977 Greenhorn

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #8
    I agree. Why would I try to place a refrigerator box inside a shoe box? It just doesn't make any sense.
     
    littlewing1977, Nov 19, 2010 IP
  9. larssonk22

    larssonk22 Well-Known Member

    Messages:
    236
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #9
    Agreed, I was going to suggest setting a min-width, there are some firefox only ones -moz-fit-content, -moz-max-content

    lol whats going on here with the decimals??
     
    larssonk22, Nov 19, 2010 IP
  10. kaboo

    kaboo Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #10
    im little late i know, but the question is still unaswered, so here it goes:

    position: absolute
    width: 100%
    left: 0
     
    kaboo, Mar 9, 2013 IP
  11. jamjar919

    jamjar919 Well-Known Member

    Messages:
    332
    Likes Received:
    7
    Best Answers:
    5
    Trophy Points:
    180
    #11
    If I had a pound for every decimal you used, I'd be a rich man. Why so much?​
     
    jamjar919, Mar 9, 2013 IP
  12. MaximusMcc

    MaximusMcc Greenhorn

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #12
    Use a z-index like z-index:100; and this will how that div on top of the other div with both having absolute positioning. Give them both a z-index number and the one that you want on top should have the greater number. ;-)

    Thanks
    Maximus McCullough
    Lead web developer at A1WebsitePro.com
     
    MaximusMcc, Mar 10, 2013 IP