473,569 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

converting from tables to css

I want to be a good little author and use CSS.

Therefore, I'm attempting to convert my tables to the equivalent CSS.

Unfortunately, I can't reproduce the same results. Can someone take a
look at http://www.greengoldcapital.info/test/test.shtml and see if
you can tell me what I'm doing wrong?

What you see there is of course a mess at this point, as I've tried
numerous ways to get this done and left most of those trials intact in
the code.

THE PROBLEM is that I want the first (css style code) to look
identical to the second (table style code). I cannot for the life of
me get the text to align vertically in the middle of the background
image.

As you can see, I've tried adjusting the margins, the padding, and of
course using the vertical alignment directive.

While I can move the text to the right using margin-left, margin-top
has no affect whatsoever that I can see. Padding has no effect, nor
does vertical-alignment.

I've tried every possible combination I can think of, the text will
not move vertically no matter what I do. I'm out of ideas.

Any thoughts?

Thank you in advance!

Mar 8 '07 #1
12 2436
Els
Dudely wrote:
I want to be a good little author and use CSS.

Therefore, I'm attempting to convert my tables to the equivalent CSS.

Unfortunately, I can't reproduce the same results. Can someone take a
look at http://www.greengoldcapital.info/test/test.shtml and see if
you can tell me what I'm doing wrong?

What you see there is of course a mess at this point, as I've tried
numerous ways to get this done and left most of those trials intact in
the code.

THE PROBLEM is that I want the first (css style code) to look
identical to the second (table style code). I cannot for the life of
me get the text to align vertically in the middle of the background
image.

As you can see, I've tried adjusting the margins, the padding, and of
course using the vertical alignment directive.

While I can move the text to the right using margin-left, margin-top
has no affect whatsoever that I can see. Padding has no effect, nor
does vertical-alignment.

I've tried every possible combination I can think of, the text will
not move vertically no matter what I do. I'm out of ideas.
Two options (well, there are more, but only two I'd want to suggest):
Either set a padding-top on the div. Be aware that padding is *added*
to height, so if the total height should remain 60px, you could use a
top padding of 20px, but then you must set the height to 40px, to add
up to 60px total, or, set the line-height on that span to 60px.

Please note though, that this might superficially convert your table
to a div, but will only get you into trouble later. Because, what
happens if the visitor decides he wants to see the text larger? By
giving the div an exact height of 60px, it won't stretch if you
enlarge the content.

To make a "CSS layout", you should first get rid of the tables in your
head IYSWIM. Think flexible, test what happens if visitors change
stuff like font-size, window size, etc.

Start with very simple pages, get to understand how things work, and
only then (this won't happen in one day!) try to mimic table layouts,
especially those that depend on image sizes.

Divs are very different in behaviour from tables, and the most
important difference might well be that they don't stretch beyond
whatever height you set them to. (except when viewed in IE5/6, but
that doesn't count ;-) )

--
Els http://locusmeus.com/
accessible web design: http://locusoptimus.com/

Now playing: Counting Crows - Barely Out Of Tuesday
Mar 8 '07 #2
On Mar 8, 3:36 pm, Els <els.aNOS...@ti scali.nlwrote:
Dudely wrote:
THE PROBLEM is that I want the first (css style code) to look
identical to the second (table style code). I cannot for the life of
me get the text to align vertically in the middle of the background
image.
As you can see, I've tried adjusting the margins, the padding, and of
course using the vertical alignment directive.
While I can move the text to the right using margin-left, margin-top
has no affect whatsoever that I can see. Padding has no effect, nor
does vertical-alignment.
I've tried every possible combination I can think of, the text will
not move vertically no matter what I do. I'm out of ideas.

Two options (well, there are more, but only two I'd want to suggest):
Either set a padding-top on the div. Be aware that padding is *added*
to height, so if the total height should remain 60px, you could use a
top padding of 20px, but then you must set the height to 40px, to add
up to 60px total, or, set the line-height on that span to 60px.

That works. I eliminated the span (I only put the span in because I
wasn't getting any results from manipulating the div) adjusted the top
and left padding and height to compensate, and it's very, very close
to the original table layout. Not exact, but good enough. What I
still don't understand is why "vertical-alignment: middle" did
absolutely nothing for me, as I would of expected that to be precisely
what I was aiming for.

Please note though, that this might superficially convert your table
to a div, but will only get you into trouble later. Because, what
happens if the visitor decides he wants to see the text larger? By
giving the div an exact height of 60px, it won't stretch if you
enlarge the content.

I'm kind of stuck between a rock and hard place. By setting it to
60px, the image IS being stretched so that I get the two-tone color
effect you should be seeing. Any other setting I've tried eliminates
the effect. Stretching the image vertically much beyond 60px makes
the image distorted as far as the colors are concerned giving too much
of a two-tone color effect. Unless you're viewing it at 60px, you're
getting an image I don't intend. Essentially you're seeing a green
image with a gold border. Stretching the image to 60px makes the gold
border stretch in a way I like. Much below or above 60px and you're
getting an effect I didn't intend. I don't know how to fix that.

Divs are very different in behaviour from tables, and the most
important difference might well be that they don't stretch beyond
whatever height you set them to. (except when viewed in IE5/6, but
that doesn't count ;-) )
It definitely has an interesting effect if I shrink the window down to
tiny. The table image stretches vertically (I don't like the
resulting image, but at least the text is still visible) whereas the
div... well, the text simply gets cut off. I suppose a poor image
with visible text is better than not being able to see the text, but I
don't know how to achieve that result with the div without losing the
original 60px stretched image for the "normal" case. i.e. full screen
viewing as intended.
Mar 9 '07 #3
Dudely wrote:
... Can someone take a
look at http://www.greengoldcapital.info/test/test.shtml and see if
you can tell me what I'm doing wrong?
>
THE PROBLEM is that I want the first (css style code) to look
identical to the second (table style code). I cannot for the life of
me get the text to align vertically in the middle of the background
image.
A partial answer from me, although Els knows of which she speaks; the
DIV alignments won't exactly duplicate tables (they _can_ do similar
things, but aren't identical).

Here's what you've got, trimmed by me to simplify the problem, then
bloated by me again to see what I'm doing, and edited by me to actually
do it:

<div style="border:5 px solid red; height: 60px;">
<span style="border:1 px solid yellow; position:absolu te;
top:25px;">Gree n Gold Capital</span>
</div>

<table border="5px" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td height="60px">G reen Gold Capital</td>
</tr>
</tbody>
</table>

Ignore or remove the borders if you want; they're there as my
visualization aid. I've added absolute positioning (slightly nasty) and
a fixed top value (twice as nasty) in units of px (four times as nasty).
Consider it a proof of concept. Consider also how quickly and easily it
breaks when the text is resized, or when the text is long but the
viewport is narrow. Which is what Els was saying.

--
John
Mar 9 '07 #4
Els
John Hosking wrote:
Dudely wrote:
>... Can someone take a
look at http://www.greengoldcapital.info/test/test.shtml and see if
you can tell me what I'm doing wrong?
>>
THE PROBLEM is that I want the first (css style code) to look
identical to the second (table style code). I cannot for the life of
me get the text to align vertically in the middle of the background
image.

A partial answer from me, although Els knows of which she speaks; the
DIV alignments won't exactly duplicate tables (they _can_ do similar
things, but aren't identical).

Here's what you've got, trimmed by me to simplify the problem, then
bloated by me again to see what I'm doing, and edited by me to actually
do it:

<div style="border:5 px solid red; height: 60px;">
<span style="border:1 px solid yellow; position:absolu te;
top:25px;">Gree n Gold Capital</span>
</div>

<table border="5px" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td height="60px">G reen Gold Capital</td>
</tr>
</tbody>
</table>

Ignore or remove the borders if you want; they're there as my
visualization aid. I've added absolute positioning (slightly nasty) and
a fixed top value (twice as nasty) in units of px (four times as nasty).
Consider it a proof of concept. Consider also how quickly and easily it
breaks when the text is resized, or when the text is long but the
viewport is narrow. Which is what Els was saying.
I also was saying that I didn't want to suggest other methods, and
this included the absolute positioning. The reason can be demonstrated
by using your example ;-) :

It is not likely that this example is the real actual webpage the OP
is trying to build. Which means that if he would use your code, and
place the div anywhere on the page but at the utter top, the span
would not end up in the right place at all.

--
Els http://locusmeus.com/
accessible web design: http://locusoptimus.com/

Now playing: Só Pra Contrariar - Minha Fantasia
Mar 9 '07 #5
Els
Dudely wrote:
>>I've tried every possible combination I can think of, the text will
not move vertically no matter what I do. I'm out of ideas.

Two options (well, there are more, but only two I'd want to suggest):
Either set a padding-top on the div. Be aware that padding is *added*
to height, so if the total height should remain 60px, you could use a
top padding of 20px, but then you must set the height to 40px, to add
up to 60px total, or, set the line-height on that span to 60px.

That works. I eliminated the span (I only put the span in because I
wasn't getting any results from manipulating the div) adjusted the top
and left padding and height to compensate, and it's very, very close
to the original table layout. Not exact, but good enough. What I
still don't understand is why "vertical-alignment: middle" did
absolutely nothing for me, as I would of expected that to be precisely
what I was aiming for.
Because vertical alignment is about the position of the letters within
their line-height. (except when set to table-cells, which is what you
are accustomed to)
>Please note though, that this might superficially convert your table
to a div, but will only get you into trouble later. Because, what
happens if the visitor decides he wants to see the text larger? By
giving the div an exact height of 60px, it won't stretch if you
enlarge the content.

I'm kind of stuck between a rock and hard place. By setting it to
60px, the image IS being stretched so that I get the two-tone color
effect you should be seeing. Any other setting I've tried eliminates
the effect. Stretching the image vertically much beyond 60px makes
the image distorted as far as the colors are concerned giving too much
of a two-tone color effect. Unless you're viewing it at 60px, you're
getting an image I don't intend. Essentially you're seeing a green
image with a gold border. Stretching the image to 60px makes the gold
border stretch in a way I like. Much below or above 60px and you're
getting an effect I didn't intend. I don't know how to fix that.
Fix it by thinking divs and forget tables. I never use an image that
has to be stretched, I make the image the way I want it before placing
it in HTML. This means my image would already be 60px high, and used
as a background, not foreground. Then, if the element would get higher
due to the content inside, I would either let the image repeat itself,
or I would set the background-color for that element to exactly the
same as the colour of the lowest pixel in the image. (Depending on the
image of course, but usually this latter method has my preference).

In your example, I'd say you want the text to always be on the
'middle' colour. Solution is to use two images. One for the top, one
for the bottom, and then solid background-color in the middle.
More complicated, but doable with nested divs. The text will always be
in the middle, the colours will always be as intended, only the middle
part may stretch with more or larger text or smaller horizontal space.
>Divs are very different in behaviour from tables, and the most
important difference might well be that they don't stretch beyond
whatever height you set them to. (except when viewed in IE5/6, but
that doesn't count ;-) )

It definitely has an interesting effect if I shrink the window down to
tiny. The table image stretches vertically (I don't like the
resulting image, but at least the text is still visible) whereas the
div... well, the text simply gets cut off.
Not in my Firefox and with the current version of your test example.
You've changed the original test case!

The div stretches. I did notice though, that you have set the height
of the div to 100%. This will be 100% of its parent, not of itself.
Keep this in mind when using divs like this on real pages ;-)
I suppose a poor image
with visible text is better than not being able to see the text, but I
don't know how to achieve that result with the div without losing the
original 60px stretched image for the "normal" case. i.e. full screen
viewing as intended.
By thinking differently, you won't need to achieve it (as you noticed
in the mean time :-) )
--
Els http://locusmeus.com/
accessible web design: http://locusoptimus.com/

Now playing: Só Pra Contrariar - Minha Fantasia
Mar 9 '07 #6
On 8 Mar, 23:06, "Dudely" <ab3...@gmail.c omwrote:
Therefore, I'm attempting to convert my tables to the equivalent CSS.

Unfortunately, I can't reproduce the same results.
Then use <table>. CSS and non-<tablemarkup is not a direct
replacement for <table>. There _are_ differences in behaviour,
particularly in how it responds to resizing and in how different
elements on a page behave in conjunction with each other. It's usually
thought that this is a _good_ thing, and why non-<tableCSS helps
achieve "fluid design".

However if you _insist_ on rigid grid-like behaviour, then you still
have to use <table (CSS' display:table*; property values aren't
widely supported, for enforcing grid-like behaviour on elements other
than <table>). You'll still be able to use CSS though, you just apply
it to HTML <table>s.

So stop worrying too much about making things look identical to the
original. You don't _want_ this, in nearly all cases. Take your
content and apply it to a fresh non-<tabledesign, don't insist on
doing it by stepwise refactoring from an old <tabledesign.

Mar 9 '07 #7
Dudely wrote:
>
>>THE PROBLEM is
to get the text to align vertically in the middle of the background
image.
Have a go at this using nested divs:

<div style="backgrou nd-image:
url(http://www.greengoldcapital.info/ima...rge_hbar.jpg);
height: 60px;position:r elative;">
<div style="padding-left: 3px;position:ab solute;
top:50%;margin-top:-.6em;">
Green Gold Capital
</div>
</div>

The ParentDiv has the background image, the height is set to 60px (same
as your table cell height) and rel positioned so that the child's abs
positioning will be relative to the parent and not to the viewport.
The ChildDiv has the text, is abs positioned and top:50% positions the
text down so the top of the div (which is basically the top of the text)
is centered over the height of the child. In order to center the text,
it is moved up with margin-top:-.6em which approximates 50% height of
the font (ChildDiv). This works well even when the text is resized.
I'm kind of stuck between a rock and hard place. By setting it to
60px, the image IS being stretched so that I get the two-tone color
effect you should be seeing. Any other setting I've tried eliminates
the effect. Stretching the image vertically much beyond 60px makes
the image distorted as far as the colors are concerned giving too much
of a two-tone color effect. Unless you're viewing it at 60px, you're
getting an image I don't intend. Essentially you're seeing a green
image with a gold border. Stretching the image to 60px makes the gold
border stretch in a way I like. Much below or above 60px and you're
getting an effect I didn't intend. I don't know how to fix that.
Strange talk about the image stretching. The image is actually 120
pixels tall and by specifying a 60px height, we only get to see one half
of the image as a background. If the height is increased, we get to see
more of the image, but there is no image stretching at all.

--
Gus
Mar 9 '07 #8
On 2007-03-09, Gus Richter <gu********@net scape.netwrote:
Dudely wrote:
>>
>>>THE PROBLEM is
to get the text to align vertically in the middle of the background
image.

Have a go at this using nested divs:

<div style="backgrou nd-image:
url(http://www.greengoldcapital.info/ima...rge_hbar.jpg);
height: 60px;position:r elative;">
<div style="padding-left: 3px;position:ab solute;
top:50%;margin-top:-.6em;">
Green Gold Capital
</div>
</div>

The ParentDiv has the background image, the height is set to 60px (same
as your table cell height) and rel positioned so that the child's abs
positioning will be relative to the parent and not to the viewport.
The ChildDiv has the text, is abs positioned and top:50% positions the
text down so the top of the div (which is basically the top of the text)
is centered over the height of the child. In order to center the text,
it is moved up with margin-top:-.6em which approximates 50% height of
the font (ChildDiv). This works well even when the text is resized.
Alternatively give the inner div

position: absolute;
height: 1.2em;
top: 0;
bottom: 0;
margin: auto 0;

which works out about the same, but the centering will remain correct if
the inner div has top and bottom padding or borders.
Mar 9 '07 #9
Ben C wrote:
Alternatively give the inner div

position: absolute;
height: 1.2em;
top: 0;
bottom: 0;
margin: auto 0;

which works out about the same, but the centering will remain correct if
the inner div has top and bottom padding or borders.
Good stuff. I like that better, thank you.

--
Gus
Mar 9 '07 #10

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

Similar topics

3
2981
by: lostinspace | last post by:
Hello, My sites were created primarily with tables as layout. :-( I have two page designs which I used frequently and hopefully somebody can provide some insight as to whether its best to remain with tables in CSS or use an alternative. The first page: http://www.mi-harness.com/hof/0a0.html Is part of a frames section, with 17 such...
4
2005
by: dschl | last post by:
Hi, I'm converting an Access 2000 database to Sql Server and must be missing something obvious. Using the Import utility in Sql Server, the Access queries seem to get executed and the resultant data imported as tables. Oops! Using the Upsize lizard in Access 2003, the queries aren't even in the selection list of "tables" to upsize. It...
8
5725
by: prabha | last post by:
Hello Everybody, I have to conert the word doc to multiple html files,according to the templates in the word doc. I had converted the word to xml.Also through Exsl ,had finished the multiple output html files. The problem is while reading through the worddoc paragraph,the special characters are not identified. So in the xml file,it's...
7
8677
by: RCS | last post by:
Okay, a rather 'interesting' situation has arisen at a place I work: I need to convert a database from Access to something that can be used over the web. I am currently maintaining and developing a mid-sized Access database (60 tables, 25 simultaneous users). Although I've been tossing up if I should try to convert the back end to SQL...
1
1388
by: Tom LeBold | last post by:
Do White papers or other documents exist that explain the steps to converting an Access database and/or tables to SQL 2000.
1
2625
by: Ramakrishnan Nagarajan | last post by:
Hi, I am converting Excel data into a Dataset in C#. There are around 24 columns in the Excel Sheet. First I tried to insert one row with correct values in the Excel sheet. i.e. for text columns I entered text values and for numeric columns I entered numeric values. It works fine and pass through all the validation checks and gets inserted...
6
23284
by: Ramakrishnan Nagarajan | last post by:
Hi can any one help me in converting a DataView into a DataSet or a DataTable into a DataSet, I tried the following ways dSet= ((DataSet)_gridRegStudDetails.DataSource); dSet = ((DataSet)_gridRegStudDetails.DataSource).Tables.DataSet; studData = ((DataSet)dView).Tables.DataSet; But not working can you pls help me out
3
2466
by: Parvesh | last post by:
hi, I am using a webservice which Returns the Result in an XML string, The XML response i get i svery cumbersome to parse, But if i could convert it to the Corresponding Class using the System.Xml.Serialization, i think that can solve my problem. But i tried using the Deserialize method for converting the XML to the Corresponding Object,...
2
5852
by: shenanwei | last post by:
DB2 V8.2 on AIX, type II index is created. I see this from deadlock event monitor. 5) Deadlocked Connection ... Participant no.: 2 Lock wait start time: 09/18/2006 23:04:09.911774 ...... Deadlocked Statement: Type : Dynamic Operation: Execute
4
5714
by: --CELKO-- | last post by:
I need to convert a bunch of DB2 triggers to Oracle. Is there any kind of tools for this?
0
7697
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8120
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7968
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5512
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.