views:

3572

answers:

15

How can I hide the div without using display:none or JavaScript?

In my country, a lot of Blackberrys come with the CSS support disabled (the mobile companies here are not so good to developers). I have text that says

<div class="BBwarn">
please activate your css support and a link
</div>

I want to hide that once the user activates CSS support, but i can't use display:none; because it is only supported in BB firmware 4.6. It is a public site and I can't make all my visitors upgrade.

Does anybody knows a solution to this? I hope the question is easier to understand now.

Update: Thank you all for the answers but I can't use

  • position:absolute
  • overflow

because they are available from Blackberry firmware 4.6 and up

+2  A: 

You could position it absolutely off the screen.

But I, also, am not a mobile developer.

Tom Ritter
I don't know how to do that without using margin
rblanch
+2  A: 

This is a common way: margin-left: -9999;

krusty.ar
doesn't work previous to 4.6 firmware
rblanch
in that case replace the text in the div:<div class="BBwarn">please upgrade your device if you want this to go away</div>and make it bold red and blinking (if that works):D
krusty.ar
+1  A: 

visibility: hidden; will work, but the space taken up by that particular div will still appear. If you are going to use the negative left-margin method, remember that you will need to set the object's position to absolute.

cLFlaVA
A: 

Sorry @Shog9 this is my first question here

Ok to clarify

In my country a lot of Blackberrys come with the css disabled (the mobile companies here are not so good to developers) I have a text that says

<div class="BBwarn">
please activate your css support and a link
</div>

I want to hide that once you activate the css support but i cant use display:none; because it is only supported in BB firmware 4.6. It is a public site and I can't make all my visitors upgrade

Does anybody knows a solution to this ? I hope the question is easier to understand now

rblanch
I've edited your question to include these details - you should always do this, rather than adding detail in replies. Thanks for the clarification!
Shog9
+1  A: 
<div style="height:0;width:0;overflow:hidden;">
<!-- content here -->
</div>

Incidentally, this is what I do to preload images, which is nice because it doesn't use javascript.

Visibility:hidden won't do the same thing because some browsers are smart and won't make the request unless it thinks its actually visible.

Daniel Schaffer
overflow only works with 4.6 and up
rblanch
d'oh! well that sucks.
Daniel Schaffer
i don't understand why this is better than using javascript? if someone without JS comes to your site, they'll download a heap of images they'll never see (presuming these images are used for rollovers, lightboxes, etc)
nickf
+3  A: 

things to try:

  • use the z-index to put it behind some other element
  • move it off the screen by absolute positioning
  • visbility: hidden
  • make the content "invisible" by setting background to foreground color (works only for text)
  • opacity: 0

but the real question is: why?

mfx
because i want the warning to disapear once you have activated css
rblanch
+1  A: 

Why not try the simple:

position: absolute;
left: -1000px;

I can't see why it wouldn't work.

John_
You can't use position in firmware previous to 4.6 but thanks
rblanch
A: 

Do you also have to activate Javascript? You could just remove the div with javascript in the onfocus. (I'm expecting this only works in 4.6)

jmucchiello
no , maybe it works with earlier phones but the mobile company also disables javascript by default32% of my traffic comes form blackberrys and a lot of them don't have neither css nor javascript activated hence the users dont get the best they could on the same device
rblanch
A: 

How about:

  visibility: hidden;

That should hide the DIV, (note how it will still be rendered but be invisible, that means it will take space in the document as if it was visible, but be invisible (unlike display:none; where the div will not be rendered)).

Pim Jager
See comments by mfx and myself above.
cLFlaVA
Yeah I noticed after posting.
Pim Jager
+1  A: 

I assume You don't want to use JavaScript because the Blackberrys don't support it.

What about if you did the opposite and displayed the block of code with JavaScript, rather than tried to hide it?

<script type="text/javascript"><!--
document.open();
document.writeln('<div class="BBwarn">');
document.writeln('please activate your css support and a link');
document.writeln('</div>');
document.close();
//--></script>

This is a bit of a hack, but would not display the text with disabled JavaScript...

cLFlaVA
Your solution doesn't work because I want to show the warning to phones with css and javascript disabled .Thanks anyway.
rblanch
+1  A: 

I'm not sure of the percentages you're talking about that are using < 4.6, but if it's that important to you, then I can see a rationale for accepting that you can't please all the people all the time, and an acceptable cascading solution to this should be achievable. Probably with a link to explain the benefits of upgrading and enabling css.

height: 0; 
overflow: hidden;
visibility: hidden; 
color: #fff; 
background: #fff;

BTW - you'd better make sure that you're css is good if you're telling someone to turn it on... :-)

Cheers,
Steve

Steve Perks
Nice -- didn't think of using color/background-color! Maybe toss in font-size: 1px;?
strager
Hmm; actually, this was written a few days ago by @mfx...
strager
@strager - I think the main thing here though is that you should consider how important this is. If it's that important, then having a link to it for some users who already have css enabled shouldn't be that big a deal if it's explained to them
Steve Perks
@Steve Perks I am considering it but it is the last resource.
rblanch
+2  A: 

What makes you think display: none is not supported before version 4.6? Did you test that, or are you going by their documentation?

I'm not a mobile developer either, so I'm just going by what I gleaned from the documentation.

The BlackBerry Browser 4.6 CSS Reference indeed mentions "Availability: BlackBerry® Device Software version 4.6 or later" for the display property, but their BlackBerry Browser 4.3 Content Developer Guide indicates that 4.3 already supported a very limited version of the display property, including display: none. Versions before 4.3 don't support the display property (again, going by the BlackBerry Browser developer documentation).

Can you assume your users do at least have firmware version 4.3, or is that just as unacceptable as assuming they have 4.6?

Have you tried simply setting the width and height to zero? I'm not familiar with the BlackBerry (Browser), but I'm sceptically assuming its CSS support is less than perfect, certainly on the older versions. I wouldn't be surprised if this worked:

.BBwarn {
    display: none; /* for 4.6 and up */
    width: 0px;    /* for 4.3 */
    height: 0px;
}

But then width and height are only supported on all elements starting from version 4.3. Before that they could only be applied to <button> and <img> tags and some <input> types (according to the documentation).

So perhaps the safest way to really make it work on all BlackBerry firmware versions is to use an image for the warning, and use CSS to set its width and height to zero.

If an image is not an option (due to lozalization issues or so, perhaps), an ugly hack might be to specify an empty/illegal image source and put the warning text in the alt attribute. I don't know if setting its width and height to zero would still hide that alt text then.

mercator
A: 

What exactly is wrong with (the earlier mentioned)

width: 0 height:0 visibility: hidden

borisCallens
A: 

width: 0 height:0 visibility: hidden

...Does not always work with firmware 2.2 and older. Sometimes you can get an element to be hidden, but it will reappear with certain keystrokes (like underscore, for instance).

A: 

Or you could use Please enable Javascript

And use an image that reads "Enable CSS" and style it using "display:none".

So that whenever the corresponding feature is enabled these warnings wont show.

Alternately, I presume you are using some server side code? You could try detecting for the most common known platforms that support specific versions of css/javascript and deliver content accordingly. You might not even have to write it all yourself.

conqenator