473,386 Members | 2,042 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,386 software developers and data experts.

CSS display not working (or more likely Im doing something wrong)

I am trying to use DIV tags and a class to hide the DIV and the HTML
within. I will use JavScript to change it from hidden to visible but
that will come later.

Below is the code I am using

<div class="hide">
<tr>
<td nowrap>Name:</td>
<td nowrap>Monty</td>
</tr>
<tr>
<td nowrap>Name:</td>
<td nowrap>Homer</td>
</tr>
</div>

The CSS code required to hide it is:

..hide {
display: none;
}

Unfortunetely, it isnt hidden. It seems to work when I do something
like:

<div class="hide"><p>I am some hidden text</p></div>

Why wont it work for when I try to hide table rows?

Burnsy

Aug 10 '05 #1
4 2223
On 10 Aug 2005 08:31:31 -0700, <bi******@yahoo.co.uk> wrote:
I am trying to use DIV tags and a class to hide the DIV and the HTML
within. I will use JavScript to change it from hidden to visible but
that will come later.

Below is the code I am using

<div class="hide">
<tr>
<td nowrap>Name:</td>
<td nowrap>Monty</td>
</tr>
<tr>
<td nowrap>Name:</td>
<td nowrap>Homer</td>
</tr>
</div>

You are aware that table rows are part of tables?

<table class="hide">
<tr>
<td></td>
<tr>
</table>

Secondly, 'nowrap' is a depricated attribute with html 4.01 (and only available
with old transitional style html):
<http://www.w3.org/TR/html401/struct/tables.html#adef-nowrap>
Use a style like table.hide td { white-space:nowrap; } or something.

Thirdly, rather than using a class name that describes the wanted visual
behaviour, one should use a class name that makes sense even if the behaviour
gets ignored or has to change in the future. So no 'hide' but rather the why it
has to be hidden.
The CSS code required to hide it is:
.hide {
display: none;
}

Unfortunetely, it isnt hidden. It seems to work when I do something
like:
<div class="hide"><p>I am some hidden text</p></div>

Why wont it work for when I try to hide table rows?


The last code example is valid html. The first (with the table rows in the div)
isn't. You don't know what happens if you write invalid code.

Create valid code and see if the behaviour still is not what you want. Then come
back here and ask again.

Also: providing an URL is almost always the best option, because rendering of
elements can be influenced by things you don't think of now, but others might
spot had they had the whole picture.

--
,-- --<--@ -- PretLetters: 'woest wyf', met vele interesses: ----------.
| weblog | http://home.wanadoo.nl/b.de.zoete/_private/weblog.html |
| webontwerp | http://home.wanadoo.nl/b.de.zoete/html/webontwerp.html |
|zweefvliegen | http://home.wanadoo.nl/b.de.zoete/html/vliegen.html |
`-------------------------------------------------- --<--@ ------------'

Aug 10 '05 #2
> You are aware that table rows are part of tables?

Yes but I would like to hide a selection of table rows within a table.
Sorry, I really should have supplied more code
Secondly, 'nowrap' is a depricated attribute with html 4.01 (and only available
with old transitional style html):
<http://www.w3.org/TR/html401/struct/tables.html#adef-nowrap>
Use a style like table.hide td { white-space:nowrap; } or something.
Unfortunetely, I have taken a job position that was filled by another
person before me. This is the code I have to work with in the mean
time. Its present throughout the entire page.
Thirdly, rather than using a class name that describes the wanted visual
behaviour, one should use a class name that makes sense even if the behaviour
gets ignored or has to change in the future. So no 'hide' but rather the why it
has to be hidden.


I'd rather stick with the name 'hide'. I can then apply it to other
elements and know that it simply hides that element (well, usually
does, lol). Anyway, thats not really too much of an issue in this case
but I appreciate the tip.

My idea:

What the final outcome will be is where you will click on a link and it
will show / hide a number of table rows within a <div> tag. The idea in
real, will be applied to a 'whats new' page where under every month
heading is a list and links of whats new on the Intranet I work on. As
mentioned previously, I am working with someones old code and it is
quite a large page (hopefully you get the idea why I am wanting to use
some space saving techniques, see working example below) so I would
like to apply this idea without having to retype the page another way
as this would be a lot of fiddly work.

Anyway, here is a simple example of a page that kinda does what I want:

http://www.martynbissett.co.uk/test/test_showhidetr.htm

As you can see, when you click the links it will show / hide the table
row below. This is the exact concept of what I am trying to achieve but
I need it to show / hide a number of rows so my solution was to nest
them within <div> tags. See below for this code:

http://www.martynbissett.co.uk/test/...howhidediv.htm

As you will be able to see, although I have done as intended with the
<div> tags (view source), it doesnt show / hide them. I would like to
know why and how to overcome this (if possible)

Anyway, sorry about the large reply but hopefully this is enough
information. If you have made it this far in the text then your doin
well, lol.

Burnsy

Aug 10 '05 #3
bi******@yahoo.co.uk schreef:
Anyway, here is a simple example of a page that kinda does what I want:

http://www.martynbissett.co.uk/test/test_showhidetr.htm

As you can see, when you click the links it will show / hide the table
row below.


Hmm, this works OK in Explorer, but in Firefox clicking on the links
keeps adding space; the space under the revealed text isn't removed when
you click the link again, and every time you show/hide the text, the
whitespace increases. But if everyone on your intranet uses only IE,
that isn't a problem, of course.

Berna

--
( )_( ) Berna M. Bleeker-Slikker
/ . . \ be***********@gmail.com
\ \@/ / http://www.volksliedjes.nl
Aug 11 '05 #4
Berna Bleeker wrote:
bi******@yahoo.co.uk schreef:
Anyway, here is a simple example of a page that kinda does what I want:

http://www.martynbissett.co.uk/test/test_showhidetr.htm

As you can see, when you click the links it will show / hide the table
row below.

Hmm, this works OK in Explorer, but in Firefox clicking on the links
keeps adding space; the space under the revealed text isn't removed when
you click the link again, and every time you show/hide the text, the
whitespace increases. But if everyone on your intranet uses only IE,
that isn't a problem, of course.


That is because the OP is using display: block for a table row which
should be display: table-row. IE does not understand table-row and is
happy with the non-standards compliant 'block'.

The simple, cross-browser solution is to toggle the display between
'none' and '' so that the row is returned ot its default (table-row for
CSS 2 compliant browsers and whatever for those that aren't).

Here's a modified version that will work correctly in most browsers -
standards compliant or otherwise:
<style type="css/text">

..hide { display: none; }
..show { display: ; }

</style>
<script type="text/javascript">

function showhide(el) {
var elem;
if (document.getElementById && (elem = document.getElementById(el))){
if ( elem.className ) {
elem.className = ('hide' == elem.className)? 'show':'hide';
}
}
}

</script>

--
Rob
Aug 12 '05 #5

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

Similar topics

3
by: Charles May | last post by:
I have a listview which checkboxes containing items to invoice. The Create Invoice button (button1) is disabled unless there are items checked. However, I had to use an if..then..else statement to...
1
by: Chiller | last post by:
Ok, I've implemented a few changes to the code and the bool functions now seem to be functioning correctly; however, I think I'm doing the convertions incorrectly because the values printed out...
6
by: Michael Sparks | last post by:
Hi, I suspect this is a bug with AMK's Crypto package from http://www.amk.ca/python/code/crypto , but want to check to see if I'm being dumb before posting a bug report. I'm looking at...
9
by: Eric Lilja | last post by:
Hello, I have two code snippets I want you to look at. My program compiles without warnings (warning level set to max, gcc 3.4.3) with either snippet but the latter one causes a segfault at...
4
by: David R | last post by:
Here's the relevant XHTML: ------------------------------------------------------------------------------------- <dl> <dt>Add...</dt> <dd><label for="radSection" ><input type="radio"...
6
by: rwsims | last post by:
This works in firefox, not at all in ie6. I'm not getting any errors, but only the doalert() function works, not the click() function. I'm sure there's something obvious, but I'm just not seeing...
9
by: Randy | last post by:
Hi all, I've been working on a simple two column layout for a site, but according to browsershots.org, my desing is not showing up correctly in Win/IE 5.01, 5.5 & 6 ! Please see details here:...
5
by: Simon Brooke | last post by:
This is supposed to be a very simple XSL stylesheet to strip styling information out of HTML documents - it could not be more basic. And yet, it doesn't work. I'm obviously getting something very...
0
by: Pat | last post by:
Hi Guys, Please help me. I am having a strange issue. Not sure if I am doing something wrong or this is a bug. This is a sample code. This contains 2 text boxes(txtName, txtPhone) and 2 buttons...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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.