Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble With CSS Floats

Tags:

html

css

I'm trying to create a dynamic popup window that is able to be re-sized. However, since I'm not able to use static widths, I'm running into issues with using floats and percentages for the widths.

When I specify a percentage for the width of a floating div, it assumes I mean the 100% of the width of the containing div. What I'm trying to do, is set the width to the remainder of the width in the current div. If I use a table, it will work. So essentially, I need to be able to take the following code for a table and make it work using a div...

<table style="width: 100px;" cellpadding="0" cellspacing="0">
   <tr style="height: 25px;">
      <td style="width: 10px; background-color: Red;"></td>
      <td style="background-color: Blue;"></td>
      <td style="width: 10px; background-color: Black;"></td>
   </tr>
</table>

Shows the following:


I have the following so far, but it does not work as intended...

<div id="container" style="width: 100px; height: 25px;">
   <div id="left" style="float: left; width: 10px; background-color: Red; height: 100%;"></div>
   <div id="mid" style="float: left; background-color: Blue; height: 100%;"></div>
   <div id="right" style="float: right; width: 10px; background-color: Black; height: 100%;"></div>
</div>

Code above shows the following:


Anyway, if someone could help me translate the table method into something that will work with a div, I would grately appreciate it.

Thanks,
C



Note:

I tried adding the code into the actual post, but it appears that the post is not interpreting the html. Therefore the sections where it says "shows the following", don't actually do that.

like image 573
regex Avatar asked Nov 16 '25 13:11

regex


1 Answers

By default divs are block level elements so you don't need to specify "display: block;".

like image 139
Nathan Bowers Avatar answered Nov 19 '25 10:11

Nathan Bowers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!