473,397 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Adapt width of DIV to content

Hi!

I have a HTML table which width will vary (since it's dynamically
built). Above the table I want to align a select box with the table's
right edge.

A simple solution is to add an extra row (and use colspan) and put the
select box there.

Is it possible to solve the problem using a container DIV and CSS?

My idea is to use a container DIV to hold both the select box and the
table. The table will always be wider than the select box. If it is
possible to set the width of the DIV to adapt to the width of the
table, then the problem is solved since it's easy to right align the
input box to the DIV.

Thanks!

Jul 7 '08 #1
6 8876
On 2008-07-07, fr***********@hotmail.com <fr***********@hotmail.comwrote:
Hi!

I have a HTML table which width will vary (since it's dynamically
built). Above the table I want to align a select box with the table's
right edge.

A simple solution is to add an extra row (and use colspan) and put the
select box there.

Is it possible to solve the problem using a container DIV and CSS?
You need to give the DIV shrink-to-fit width, which you can get by
giving it display: inline-block, display: table, display: table-cell or
float: left. Float: left is probably the most widely supported.
My idea is to use a container DIV to hold both the select box and the
table. The table will always be wider than the select box. If it is
possible to set the width of the DIV to adapt to the width of the
table, then the problem is solved since it's easy to right align the
input box to the DIV.
Are you putting the select box in the div too? Then you could float the
table to get it to the left of the select. But the select will end up
below the table if there isn't enough horizontal room.
Jul 7 '08 #2
You need to give the DIV shrink-to-fit width, which you can get by
giving it display: inline-block, display: table, display: table-cell or
float: left. Float: left is probably the most widely supported.
This worked just fine in FF but not in IE7 (both Windows). Is it
possible to get it to work in most browsers?
Are you putting the select box in the div too? Then you could float the
table to get it to the left of the select. But the select will end up
below the table if there isn't enough horizontal room.
The select box is above the table inside the same container div.
Jul 7 '08 #3
Another problem is that the div should be horizontally centered on the
page. I use margin-left: auto; margin-right: auto; to accomplish that
but adding the rules you suggested makes the div left aligned.
Jul 7 '08 #4
On 2008-07-07, fr***********@hotmail.com <fr***********@hotmail.comwrote:
Another problem is that the div should be horizontally centered on the
page. I use margin-left: auto; margin-right: auto; to accomplish that
but adding the rules you suggested makes the div left aligned.
You're out of luck then-- you can't centre a float and IE doesn't
support display: table.

See also:

http://netweaver.com.au/alt/shrinkTo...rinkToFit.html

dorayme may have a more up-to-date URL, I thought I remembered seeing
more about centring somewhere. Anyway that URL still works.
Jul 7 '08 #5
On 2008-07-07, fr***********@hotmail.com <fr***********@hotmail.comwrote:
>You need to give the DIV shrink-to-fit width, which you can get by
giving it display: inline-block, display: table, display: table-cell or
float: left. Float: left is probably the most widely supported.

This worked just fine in FF but not in IE7 (both Windows). Is it
possible to get it to work in most browsers?
I thought IE7 did support float up to a point, but I can't really help
you as I'm not familiar with many of its bugs and quirks.
Jul 7 '08 #6
In article <sl*********************@bowser.marioworld>,
Ben C <sp******@spam.eggswrote:
On 2008-07-07, fr***********@hotmail.com <fr***********@hotmail.comwrote:
Another problem is that the div should be horizontally centered on the
page. I use margin-left: auto; margin-right: auto; to accomplish that
but adding the rules you suggested makes the div left aligned.

You're out of luck then-- you can't centre a float and IE doesn't
support display: table.

See also:

http://netweaver.com.au/alt/shrinkTo...rinkToFit.html

dorayme may have a more up-to-date URL, I thought I remembered seeing
more about centring somewhere. Anyway that URL still works.
Yes, I won't move that one. It is just that it is also nearly identical
to page 4 of another more comprehensive piece I made on centring:

<http://netweaver.com.au/centring/>

--
dorayme
Jul 8 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

179
by: SoloCDM | last post by:
How do I keep my entire web page at a fixed width? ********************************************************************* Signed, SoloCDM
157
by: Dennis | last post by:
Is there some way --using, say, DOM or javascript-- to detect the current pixel width and/or height of a relatively sized table or of one of its columns or rows. I'm going to be writing javascript...
2
by: MSE | last post by:
How can I make a website that adapts to the screen resolution? I would also like to include a picture that stretches when the screen res. increases, if you know what I mean.
28
by: Gabriel | last post by:
greetings, I want to achieve the following effect : Menu1 | Menu2 | Menu3 | Menu4 | Menu5 | I played with padding, border-width and the like and it's ok for the | . My problem is that...
7
by: McKirahan | last post by:
What is "active content"? My ASP page just returns HTML.... I have a page with an .htm extension that has a form whose action is an ASP page which generates a report after updating a database...
4
by: Daniel Fugmann | last post by:
Hello, I use popups to show small pieces of information. These texts vary much in their lenghts and I dislike fixed size popups here because when the text is short there is so much empty space....
7
by: Johnny | last post by:
June 2, 2005 Greetings, I have a whole lot of questions that all have to do with the same topic: Width. By "width" I mean how wide a particular Web page is, how wide a table is, how wide a...
8
by: Harris Kosmidis | last post by:
It seems I cannot understand CSS, well. I have donw the following page: http://www.pennias.gr/home.php It's in greek but the context is of no importance. I used a big table to put in my page...
4
by: Jon | last post by:
Hello all, Would anyone be able to help shed some light on a problem I have with the below site: http://www.maychild.co.uk/consultancy.aspx. It looks fine in IE, but is far to wide in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.