Results 1 to 8 of 8

Thread: [RESOLVED] <div> in <td> element

  1. #1
    Addicted Member
    Join Date
    Dec 09
    Location
    sydney
    Posts
    175

    Resolved [RESOLVED] <div> in <td> element

    This should be a very simple css, yet cant get my head around it.
    All i need is to create DataBars representing percentages inside <td> elements.
    here is what i did. and this is fine except that the databar <div> size and position properties corresponding to the <table> parent rather then <td> parent

    HTML Code:
    <table style='position:absolute;width:10&#37;;top:150px;  height:20px;table-layout:fixed; left: 85px;border:1px solid black;'>
    <tr style="border:1px solid black;"> 
         <td></td>
             <td></td>
            <td >  </td>
            </tr>
       <tr style="border:1px solid black;"> 
         <td></td>
             <td></td>
            <td >   
                    <div class="databar" style="position: absolute; height: 90%; width: 60%; border: thin solid aqua;background:yellow; left: 2px;top:0px;"></div>  <!-- this is a visual representation of the percentage -->
                    <div style="position:absolute;left:30%;width:40%;border:1px solid green;height:100%;top:0px; text-align:center;"> 323</div> <!-- this is a numeric value -->
             </td>
            
        </tr>
    </table>
    cannot see what i did wrong.

  2. #2
    Addicted Member
    Join Date
    Dec 09
    Location
    sydney
    Posts
    175

    Re: <div> in <td> element

    ok here is what i found, TD position should not be set to absolute. a work around for me was to wrapp the 2 div in another div container
    Code:
     <td style="position:relative;text-align:center;">   
                         <div style="position:absolute;text-align:center;border:1px solid grey;width:100&#37;;height:100%;top:0px;left:0px;">
                            <div class="databar" style="position: absolute; height: 90%; width: 60%; border: thin solid aqua;background:yellow; left: 2px;top:0px;"></div>
                            <div style="position:absolute;left:30%;width:40%;border:1px solid green;height:80%;top:2px; text-align:center; vertical-align: middle;"> 323</div>
                        </div>                
                   </td>

  3. #3
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 08
    Location
    Trivandrum, Kerala, India
    Posts
    7,557

    Re: <div> in <td> element

    Can you please post a visual example(a screenshot) of what you are having now and what you are expecting.


    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD Athlon X2 5200+, ASUS Motherboard, 2 GB RAM, 400 GB HDD, Nvidia 8600 GT 512MB, 19.5" TFT(Wide), Creative 5.1 Home Theater

    Social Group: VBForums - Developers from India

    Skills: PHP, MySQL, jQuery, VB.Net, VB6, Photoshop...

  4. #4
    Addicted Member
    Join Date
    Dec 09
    Location
    sydney
    Posts
    175

    Re: <div> in <td> element

    Quote Originally Posted by wiss.dev View Post
    ok here is what i found, TD position should not be set to absolute. a work around for me was to wrapp the 2 div in another div container
    Code:
     <td style="position:relative;text-align:center;">   
                         <div style="position:absolute;text-align:center;border:1px solid grey;width:100%;height:100%;top:0px;left:0px;">
                            <div class="databar" style="position: absolute; height: 90%; width: 60%; border: thin solid aqua;background:yellow; left: 2px;top:0px;"></div>
                            <div style="position:absolute;left:30%;width:40%;border:1px solid green;height:80%;top:2px; text-align:center; vertical-align: middle;"> 323</div>
                        </div>                
                   </td>
    this was it, i wrapped the 2 divs in another div container

  5. #5
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 08
    Location
    Trivandrum, Kerala, India
    Posts
    7,557

    Re: <div> in <td> element

    Quote Originally Posted by wiss.dev View Post
    this was it, i wrapped the 2 divs in another div container
    You mean like this : http://jsfiddle.net/Ha3Cw/ ?

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD Athlon X2 5200+, ASUS Motherboard, 2 GB RAM, 400 GB HDD, Nvidia 8600 GT 512MB, 19.5" TFT(Wide), Creative 5.1 Home Theater

    Social Group: VBForums - Developers from India

    Skills: PHP, MySQL, jQuery, VB.Net, VB6, Photoshop...

  6. #6
    Addicted Member
    Join Date
    Dec 09
    Location
    sydney
    Posts
    175

    Re: [RESOLVED] <div> in <td> element

    yes, i just did some more css cosmetics and got it exactly like excel bars

  7. #7
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 08
    Location
    Trivandrum, Kerala, India
    Posts
    7,557

    Re: [RESOLVED] <div> in <td> element

    Quote Originally Posted by wiss.dev View Post
    yes, i just did some more css cosmetics and got it exactly like excel bars
    OK. So you were looking for something like this ?


    http://i.techrepublic.com.com/blogs/765.jpg

    It would have been a lot more better if you had given a visual sample as not everyone would be aware of what an Excel Bar is.

    Here's what I have coded to have the above effect: http://jsfiddle.net/kLmPj/



    EDIT:

    If you do not wish to see it in action by visiting the above link, then here's the code:
    HTML Code:
    <table id="my_excel">
      <thead>
          <tr>
              <th width="50&#37;">Name</th><th>Marks</th>
          </tr>
      </thead>
      <tbody>
          <tr>
              <td>ABC1</td>
              <td>
                  <span class="bar" style="width:75%;">75</span>
              </td>
          </tr>
          <tr>
              <td>ABC2</td>
              <td>
                  <span class="bar" style="width:50%;">50</span>
              </td>
          </tr>
          <tr>
              <td>ABC3</td>
              <td>
                  <span class="bar" style="width:13%;">13</span>
              </td>
          </tr>
      </tbody>
    </table>
    css Code:
    1. #my_excel{
    2.     width: 150px;
    3. }
    4. #my_excel td{
    5.     border: 1px solid black;
    6.     position: relative;
    7. }
    8. .bar{
    9.     position: absolute;
    10.     left: 0;
    11.     top: 0;
    12.     background-color: lightBlue;
    13. }&#8203;
    Last edited by akhileshbc; Jul 26th, 2012 at 10:13 PM. Reason: added codes

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD Athlon X2 5200+, ASUS Motherboard, 2 GB RAM, 400 GB HDD, Nvidia 8600 GT 512MB, 19.5" TFT(Wide), Creative 5.1 Home Theater

    Social Group: VBForums - Developers from India

    Skills: PHP, MySQL, jQuery, VB.Net, VB6, Photoshop...

  8. #8
    Addicted Member
    Join Date
    Dec 09
    Location
    sydney
    Posts
    175

    Re: [RESOLVED] <div> in <td> element

    Thanks Akhileshbc,, i already worked it out

Posting Permissions

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