0

thanks for taking your time to help me!

I am trying to style sister div but not by using this id #rooms-booking-manager-change-search-form

Example

div + #rooms-booking-manager-change-search-form { padding:10px; font-size:18px; }

<div>Arrival Date: 19/09/2013</div>
<div>Departure Date: 21/09/2013</div>
<div>Nights: 2</div>
<form id="rooms-booking-manager-change-search-form"></form>

enter image description here

Solution:

div ~ #rooms-booking-manager-change-search-form {
    background: red;
}
Mr_Green
  • 39,139
  • 43
  • 154
  • 250
  • `sister or brother` == `parent and child` – Deepak Ingole Sep 17 '13 at 08:55
  • 2
    Can you be more specific please? You say you are trying to style the `div`s that are next to each other, but which ones do you want to style and how? There are selectors that can probably help you here (such as `+`) but it's difficult to give specific help without knowing exactly what you want to achieve. – Sean Sep 17 '13 at 09:01
  • if you're trying to target the `div`s, its not working. http://jsfiddle.net/avrahamcool/yWXuu/2/ – avrahamcool Sep 17 '13 at 09:35
  • possible duplicate of [CSS previous sibling selector](http://stackoverflow.com/q/1817792). – Mr_Green Sep 17 '13 at 09:48
  • just a comment on your "solution" section in your post. `id's` are meant to be unique. – Mr_Green Sep 17 '13 at 09:57

4 Answers4

0

You can select the an element next to another element using the plus sign.

E.g.

div + div { padding: 10px; }
CaribouCode
  • 13,156
  • 22
  • 91
  • 166
0

take a look at this Article it ist a Good Description of sibling and Child Selectors http://css-tricks.com/child-and-sibling-selectors/

Jan Wiemers
  • 341
  • 1
  • 6
0

You could create a wrapper for all the form items as follows

<div class="form-item-wrapper>
    <div class="form-item form-type-item">
    <div class="form-item form-type-item">
</div>

and then the CSS is :

<style>
    .form-item-wrapper > div{
        padding: 10px  
    }
</style>

Here is a good article http://css-tricks.com/child-and-sibling-selectors/

user1812741
  • 301
  • 2
  • 5
  • 14
  • Hi, thanks for your help I can't create any wrapper, the only way i have using css, where i want to style pre div by using this id #rooms-booking-manager-change-search-form – user2786773 Sep 17 '13 at 09:09
0

I hope I understood you correctly (edit your question and explain yourself more clearly)

Do you try to select all the divs that come prior to your form (#rooms-booking-manager-change-search-form)?

If you are not allowed to change the DOM, you can't achieve that via pure CSS selectors, but if you're allowed to use JQuery, then its pretty simple.

$("#rooms-booking-manager-change-search-form").prevAll('div').css('background-color','red');

Working Fiddle

Community
  • 1
  • 1
avrahamcool
  • 13,552
  • 5
  • 47
  • 58