• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

simple scenario with DIVs  RSS feed

 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can achieve this by using css selector.



For reading child-and-sibling-selectors to get the idea behind.
 
Sheriff
Posts: 3034
12
IntelliJ IDE Java Mac Python VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3034
12
IntelliJ IDE Java Mac Python VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, something like this should work:

 
Eduardo Bueno
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much, I didn't know I could use length() in this case.
 
Sheriff
Posts: 67257
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's .length, not .length(), and it contains the number of matched elements in the jQuery wrapped set.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!