Hello. How can I make it so that when I click on the pictures, the backgrounds of the block (div) change to the clicked picture?

Here is the diagram:

alt text

Please advise. Thanks in advance!!

    4 answers 4

    To be honest, I didn’t understand anything from the β€œscheme”, but I allowed myself to guess.

    There are pictures on the page, and when you click on this picture, would you like the background of the given diva to change?

    something like this ?

    • there are different blocks, div_1, div_2, div_3, div_4; and when you click on the picture reduced, then in a certain block the background will be the same picture. There are β€œPictures” on a separate block, are there some pictures that will be displayed on the background of the block? - rszh
    • google jquery galleries. - zloctb
    • No, I think the gallery will not work, it is necessary on each block different pictures appeared - rszh

    I'm not sure that I understood correctly, but if you need a background with this picture to be set by clicking on a picture in a certain block, you just need to do this:

    <div id="images"> <img src="1.jpg" /> <img src="2.jpg" /> <img src="3.jpg" /> <img src="4.jpg" /> <img src="5.jpg" /> <img src="6.jpg" /> <img src="7.jpg" /> </div> <div id="blocks"> <div id="div_1"></div> <div id="div_2"></div> <div id="div_3"></div> <div id="div_4"></div> </div> <script> $(function () { $(".images img").click(function(){ $("#div_1").css("background", "url('" + $(this).attr("src") + "') 0 0 no-repeat"); }) }) </script> 

      He wants to say that there is a block on top located a panel of pictures. Click on the pictures and the entire background of this diva is replaced by this picture. I think there can not do without a script. Alas, I can’t help with anything just html + css.

        What if one block were changed when clicking on a certain picture, then:

        HTML:

         <div id="div_1"></div>//Π‘Π»ΠΎΠΊΠΈ <div id="div_2"></div> <div id="div_3"></div> <div id="div_4"></div> <div class="images">//ΠšΠΎΠ½Ρ‚Π΅ΠΉΠ½Π΅Ρ€ с ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ°ΠΌΠΈ <img src="source" class="forDiv_1">//ΠšΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠΈ с ΠΌΠ΅Ρ‚ΠΊΠ°ΠΌΠΈ, для ΠΏΠ΅Ρ€Π²ΠΎΠ³ΠΎ Π±Π»ΠΎΠΊΠ° - forDiv_1 ΠΈ Ρ‚.Π΄. МоТСм ΠΊΠΎΠΏΠΈΠΏΠ°ΡΡ‚ΠΈΡ‚ΡŒ ΡΡ‚ΠΎΠ»ΡŒΠΊΠΎ, ΡΡ‚ΠΎΠ»ΡŒΠΊΠΎ Π½Π°Π΄ΠΎ. <img src="source" class="forDiv_2"> <img src="source" class="forDiv_3"> <img src="source" class="forDiv_4"> </div> 

        Here is jQuery:

          $(".images > img").click(function(){//ДобираСмся Π΄ΠΎ Π½Π°ΡˆΠΈΡ… ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΎΠΊ Π² ΠΊΠΎΠ½Ρ‚Π΅ΠΉΠ½Π΅Ρ€Π΅ if($(this).attr("class") === "forDiv_1")//ΠŸΡ€ΠΎΠ²Π΅Ρ€ΡΠ΅ΠΌ, Ссли ΠΊΠ»ΠΈΠΊΠ½ΡƒΠ»ΠΈ Π½Π° ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΡƒ, которая мСняСт ΠΏΠ΅Ρ€Π²Ρ‹ΠΉ Π±Π»ΠΎΠΊ $("#div_1").css("background", "url("+$(this).attr("src")+") 0 0 no-repeat");//мСняСм Π΅Π³ΠΎ if($(this).attr("class") === "forDiv_2")//ΠŸΠΎΠ²Ρ‚ΠΎΡ€ΡΠ΅ΠΌ для ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ Π±Π»ΠΎΠΊΠ° $("#div_2").css("background", "url("+$(this).attr("src")+") 0 0 no-repeat"); if($(this).attr("class") === "forDiv_3") $("#div_3").css("background", "url("+$(this).attr("src")+") 0 0 no-repeat"); if($(this).attr("class") === "forDiv_4") $("#div_4").css("background", "url("+$(this).attr("src")+") 0 0 no-repeat"); });