wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes simple scenario with DIVs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "simple scenario with DIVs" Watch "simple scenario with DIVs" New topic
Author

simple scenario with DIVs

Eduardo Bueno
Ranch Hand

Joined: Jun 04, 2009
Posts: 155
I have this simple scenario which I'm trying to find a css solution for. I have a page with two divs side by side - div1 and div2. at some point div2 may not be rendered, so I have div1 only and I want to align it to the center. I realized I can do it by changing its margin-left attribute, but first I must check if the other div (div2) was not rendered. how do I do this?
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

You can achieve this by using css selector.



For reading child-and-sibling-selectors to get the idea behind.


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2840
    
  11

The way I'm reading that last rule is: select .div2 if it is preceded by .div1, whereas I think Eduardo needs something that will select .div1 if it is not followed by by .div2. Am I reading that wrong? If not, then it might need some jQuery, because I believe styling is applied sequentially through the document. That is, there's no look-ahead to see what's coming next. Also, when you say div 2 isn't rendered, do you mean it's not in the DOM (or the page source) or is it there, and just set not to display?
Eduardo Bueno
Ranch Hand

Joined: Jun 04, 2009
Posts: 155
You've read it right, Greg. Anyway I didn't know about those tricks - thank you very much Muhammad.

I can use jQuery and yes, it's not in the DOM.
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2840
    
  11

So, something like this should work:

Eduardo Bueno
Ranch Hand

Joined: Jun 04, 2009
Posts: 155
Thank you very much, I didn't know I could use length() in this case.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60802
    
  65

It's .length, not .length(), and it contains the number of matched elements in the jQuery wrapped set.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: simple scenario with DIVs
 
Similar Threads
Dynamically moving the DIV
Showing Hiding <s:div> tag in Struts2
Client side rendeing
Firebug question
skip validation