How can I do this without a table? (Full Version)

All Forums >> [Web Development] >> Cascading Style Sheets



Message


BeTheBall -> How can I do this without a table? (5/3/2006 15:47:42)

Any thoughts on how to do something as in the image below? Specifically, having the word Note float to the left and the rest of the text left-aligned to the right.



[image]local://upfiles/5648/CEF0CBF8469E412DB30F36FB31E37FD9.gif[/image]




rdouglass -> RE: How can I do this without a table? (5/3/2006 15:58:26)

Here's one way:

http://www.rogerdouglass.com/btb.asp




jaybee -> RE: How can I do this without a table? (5/3/2006 18:10:02)

This method sets up a hanging indent by using a negative text-align. With this though, you need to set it in it's own Div with plenty of padding round it otherwise the "outdented" line will shoot out of the container




rubyaim -> RE: How can I do this without a table? (5/3/2006 19:03:50)

Hi Duane, another option using a definition list. I've been playing around with code from Max Design.

Forgive the nursery rhymes, I get bored with latin text.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=windows-1252" />
<title>DL Test</title>

<style type="text/css">

dl.rhyme {
margin: 2em 0;
padding: 0;
font-family: verdana, arial, helvetica, sans-serif;
font-size: 0.85em;
}

.rhyme dt {
width: 10%;
float: left;
margin: 0;
padding: .5em;
font-weight: bold;
}

/* commented backslash hack for mac-ie5 \*/
dt { clear: both; }
/* end hack */

.rhyme dd {
float: left;
width: 80%;
margin: 0;
padding: .5em;
}
</style>
</head>
<body>

<dl class="rhyme">
<dt>Diddle</dt>
<dd>Hey, diddle, diddle, The cat and the fiddle, The cow jumped over the moon. The little dog laughed To see such sport, And the dish ran away with the spoon.</dd>
<dt>Twinkle</dt>
<dd>Twinkle, twinkle, little star, How I wonder what you are. Up above the world so high, Like a diamond in the sky. Twinkle, twinkle, little star, How I wonder what you are.</dd>
<dt>Pussycat</dt>
<dd>Pussycat, pussycat, where have you been? I've been to London to visit the Queen. Pussycat, pussycat, what did you there? I frightened a little mouse under her chair.</dd>
<dt>Spider</dt>
<dd>Eencey Weencey spider, climed up the water spout; Down came the rain, and washed poor Eencey out; Out came the sun, and dried up all the rain; And the Eencey Weencey spider, climbed up the spout again.</dd>
</dl>

</body>
</html>




BeTheBall -> RE: How can I do this without a table? (5/3/2006 19:15:52)

Thanks for all the suggestions. I am sure I will pick the one that involved the least amount of coding . . . just my nature. [;)]




jaybee -> RE: How can I do this without a table? (5/3/2006 19:28:10)

Yes you can use Definition lists for all sorts of things but they are really meant for definitions and will be read as such by screen readers.

In Duane's case he just needs a visual representation of some text for emphasis.

You should be able to see the page on my example properly now, I was mucking around with my css so things may have been unreadable when you got there.




rubyaim -> RE: How can I do this without a table? (5/3/2006 19:40:01)

I did say I was only playing [:)]

The more options there are the better you can find something that suits whatever you are trying to do.

I'd have no hesitation using a DL like this on my Intranet, but would think about other options for something available to the entire world.





jaybee -> RE: How can I do this without a table? (5/3/2006 19:51:16)

dl are great but there has been a lot of discussion about their use for things other than defs. At one time people were using them for menus (I did) which they do very nicely but it always comes back to screen readers and confusing users.

That Max Design example you gave is a perfect example of using them to replace tables for definitions.




rubyaim -> RE: How can I do this without a table? (5/3/2006 20:12:03)

And in case anyone lands on this after a search, here is more on definition lists:
W3C - Definition lists: the DL, DT, and DD elements

The Max Design site also has an explanation:
What are definition lists?




BeTheBall -> RE: How can I do this without a table? (5/3/2006 20:33:35)

I wondered whether the use would be proper or not as well, but in this case one could argue that the text following the word note is a "definition" of that particular Note. Probably a stretch, but conceivable.

quote:

You should be able to see the page on my example properly now, I was mucking around with my css so things may have been unreadable when you got there.


Very nice jaybee. Thanks again to all for the help.




BeTheBall -> RE: How can I do this without a table? (5/4/2006 18:31:20)

Roger, ran into a bit of a dilemma with your method. Try adding some text in a <p> tag just below the divs and then view the page in FF or Opera. The line of text ends up several inches below the text in the divs. I can see how this CSS stuff could lead to a drinking problem!


Edit - Curiously, change the HTML version in your doctype to 4.01 and the problem is resolved.

[:@]




rdouglass -> RE: How can I do this without a table? (5/5/2006 9:21:52)

quote:

change the HTML version in your doctype to 4.01 and the problem is resolved.


That *thing* again...[:D] Anyways, that was a very quick 'throw together' just to give an example. It is simple and I like simple (if CSS can *ever* be simple that is.[;)])




BeTheBall -> RE: How can I do this without a table? (5/5/2006 9:51:54)

quote:

ORIGINAL: rdouglass

quote:

change the HTML version in your doctype to 4.01 and the problem is resolved.


That *thing* again...[:D] Anyways, that was a very quick 'throw together' just to give an example. It is simple and I like simple (if CSS can *ever* be simple that is.[;)])


No kidding. I am sure over time I will look back and think it quite simple and logical, but right now I am floundering a bit. I am going to jump into the XML world in the coming days which will probably really get my head spinning.




Tailslide -> RE: How can I do this without a table? (5/5/2006 10:03:26)

You will, honestly Duane. It's a totally different way of looking at web designing/building and it takes a while to get to grips with it - but it really does become mostly very logical. There certainly are cross-browser issues but on the whole I'd suggest learning to avoid them rather than try to "fix" them all (which is possible but boring frankly).




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.046875