1

I need to select element that I think can be selected with this code:

#main_slider h2 < img#main_slider_menu_image {
    background: initial !important;
    text-align: left !important;
    width: 90% !important;
}

I'm trying to select #main_slider h2 that have image with id #main_slider_menu_image. I really need make it work. But this code is not working now. So have can I write it true to make this work?

Also add full html block:

<div class="main" id="main_slider">
    <h2>Фланцевые уплотнения</h2>
    <img id="main_slider_menu_image" class="slider_img" src="/upload/iblock/360/ngzzkvgrvbicbboyyo thkgszaddkxcakjzktvq.png">
    <p>
        Прокладки стальные овального и восьмиугольного сечения, уплотнительные линзы. Прокладки паронитовые, фторопластовые, безасбестовые, прокладки из терморасширенного графита. Прокладки спирально-навитые.
    </p>
</div>

Jquery added now as tag, because no way to do it by CSS. Still loking answer. I have selected p by using:

img#main_slider_menu_image ~ p  { 

 }

because p is after img, but I can't select h2 this way because it before img. Image switch classes in slider and I have task to change style of h2, And all I have is only image with different classes. and when list hovered image switch id to main_slider_menu_image . Very difficult task for me, and I son't know the programmer who made this slider... The website is Bitrix website Image to understand what I need

sanchahous
  • 171
  • 3
  • 17

1 Answers1

1

That's < doesn't exists in CSS. There will be the opposite:

#main_slider h2 > img#main_slider_menu_image 

See more:

https://developer.mozilla.org/es/docs/Web/CSS/Child_selectors

In your case, your solution is the sibling selector

#main_slider h2 + img#main_slider_menu_image 

https://developer.mozilla.org/es/docs/Web/CSS/Adjacent_sibling_selectors

Marcos Pérez Gude
  • 20,206
  • 4
  • 34
  • 65
  • #main_slider h2 + img#main_slider_menu_image have tried this code, but this select image instead of h2 – sanchahous Nov 16 '15 at 16:42
  • Sorry, I don't understand that you need to select `h2`. Unfortunately this doesn't exists in CSS, so you need to try with a javascript/jquery solution. See the @RiccardoC answer. Good luck. – Marcos Pérez Gude Nov 16 '15 at 16:44
  • Thank's you. Now I know that I need to use jQuery) Because I'm bad with JS:) – sanchahous Nov 16 '15 at 16:45