473,387 Members | 1,724 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,387 software developers and data experts.

Can I avoid specifying width when using floats?

I'd like to build a table-less layout for a very simple page.
The layout should look a bit like this (view with fixed font)

+-------------+ ID: 2984884
| | Last Name: Doe
| | First Name: John
| (picture) | DOB: 1999-11-11
| | City: Pasadena
| | Job Desc: Manager in charge of the restructuring
+-------------+ project for our west coast client
Last visit: 2003-12-12
Favorite color: blue
Car: Honda
Shoe size: 8
Postal code: 12345
Other stuff: Whatever
For the life of me, I cannot figure out how to this with CSS -- all
the examples I've seen specify a width for at least one of the two
DIVS. Problem is, I do not know that at design time! The images and
text in the database vary wildly. Plus, how can I prevent the text
from sneaking under the first DIV anyway??

I hope someone out there can help me. TIA.
Jul 20 '05 #1
4 1825
Terry wrote:
I'd like to build a table-less layout for a very simple page.
The layout should look a bit like this (view with fixed font)

+-------------+ ID: 2984884
| | Last Name: Doe
| | First Name: John
| (picture) | DOB: 1999-11-11
| | City: Pasadena
| | Job Desc: Manager in charge of the restructuring
+-------------+ project for our west coast client
Last visit: 2003-12-12
Favorite color: blue
Car: Honda
Shoe size: 8
Postal code: 12345
Other stuff: Whatever
Since the picture and the personal data are related, they are tabular
data, hence the use of a table to mark it up is appropriate.
For the life of me, I cannot figure out how to this with CSS -- all
the examples I've seen specify a width for at least one of the two
DIVS.
For a non table markup you'd need only 1 div, div's by default have a
width of 100%, so to get a div to share horizontal space with something
else you'd need to alter the default width.
Problem is, I do not know that at design time! The images and
text in the database vary wildly.
Tables use a shrink to fit algorithm.
Plus, how can I prevent the text
from sneaking under the first DIV anyway??


Should not happen unless you float the image.

--
Spartanicus
Jul 20 '05 #2
"Terry" <a1*****@yahoo.com> wrote in message
news:7a**************************@posting.google.c om...
For the life of me, I cannot figure out how to this with CSS -- all the examples I've seen specify a width for at least one of the two DIVS. Problem is, I do not know that at design time! The images and text in the database vary wildly. Plus, how can I prevent the text from sneaking under the first DIV anyway??


Without a table: if there is truly "wild" variation in width,
you're going to run into difficulties if some images are so wide
the viewport cannot handle both the image and a reasonable block
of text side-by-side. Perhaps this is a case where you might set
a standard width as an attribute for the img in the HTML. As much
as it goes against my instincts, this *would* allow you to make
all the pics a uniform width, the aspect should remain the same,
and the width of the div parent to the img could be set.

Be sure you set a width that will not distort smaller images
grossly.

Jul 20 '05 #3
Terry wrote:
I'd like to build a table-less layout for a very simple page.
Getting rid of tables for layout is a good choice. But *do* use tables
for tabular data.
ID: 2984884
Last Name: Doe
First Name: John
DOB: 1999-11-11

[rest of data snipped]

This is tabular data. The first part is the row header, the second is
table data. Put the photo outside of the table (it has no natural
table header, and doesn't look like it should be part of the table).
Use a div to group the table and photo together.

<div class="personel">

<img src="doejohn.jpeg" alt="John Doe">

<table>
<tr>
<th>ID</th><td>2984884</td>
</tr>
<tr>
<th>Last Name</th><td>Doe</td>
</tr>
<!-- etc. -->
</table>

</div>

The photo has an intrinsic width, so you could simply float it left.
..personel img { float: left }

--
Brian
follow the directions in my address to email me

Jul 20 '05 #4
Thanks to all for your input -- I finally went with a table, reading
Spartanicus' logic seemed to make good sense to me. And I'll save all
other techniques for future dev. Thanks again.
Jul 20 '05 #5

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

Similar topics

1
by: trialanderror | last post by:
I've been happily chugging along thinking I understood floating divs and now find that I know a lot less than I thought I did. And the more I try "fixing" things, the worse it gets. A lot of what...
2
by: Stian Lund | last post by:
Hi, on the following page, http://stian.freeshell.org/index.php the floated image in the latest post is shown as tiny/zero-width in Mozilla 1.7 and Firefox 1.0 (you can just about make it left of...
16
by: Michael Rozdoba | last post by:
I'm far from a CSS expert, but what I see of it I really like & I love keeping content & style separate. I also hate the way table layout produces convoluted bulky code. However when asked why...
9
by: Daniel Kabs | last post by:
Hello there again! On my quest to remove layout tables in favor of CSS controlled elements, I am faced with quite a problem. A table cell that has no explicit width attribute set usually...
6
by: Hacking Bear | last post by:
Hi, I still don't quite fully understand how to handle mixing border/margin pixel width with percentage width. In the example below, I want to place side-by-side two DIV boxes inside a box....
4
by: Nathan Sokalski | last post by:
I have a <tdthat contains several elements, some of which are left-aligned, right-aligned, or centered. I do not know the widths of these elements beforehand, so I cannot give my <tda fixed width....
11
by: yawnmoth | last post by:
How do you get both of these div's to have a 100% width? (1): <div style="float: left; background: black; color: white">Hello, world! </div> <div style="clear: both; background: blue; color:...
50
by: Dave Rado | last post by:
Hi I've created a banner with a drop-shadow using a div - there's a mock- up at http://tinyurl.com/6n7czu . The only problem is that the way I've done it, I have to specify the width of the div...
2
by: Jim Carlock | last post by:
I ran into a problem a think. Either that or I overlooked something. I seem to run into this problem quite often. I fail to pinpoint the problem and it appears as a bug with mozilla browsers....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.