Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!
  • 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

simple scenario with DIVs

 
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
Mac IntelliJ IDE Python VI Editor Java
  • 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
Mac IntelliJ IDE Python VI Editor Java
  • 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.
 
Marshal
Posts: 67273
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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!