2

I am working on a HTLM editor who combine HTML & CSS in the same page. I want that the users have a zoom when mouseover on a picture in front page

<h4><img style="border: 1px solid black; align: right;" title="" src="sys_attachment.do?sys_id=00ee33cbdb1b9c507261e03cd396190b" alt="" width="204" align="right" border="1" hspace="" vspace="" /></h4>
<h4><strong>4. Entrez votre mot de passe.</strong></h4>
<ul style="list-style-type: disc; list-style-position: inside;">
    <li>Puis, cliquez sur "Suivant".</li>
</ul>

I searched for solution but the solution is always when HTML and CSS are separated If someone has any advice or solution, please help me !

Sorry for my english, i am still learning !

isherwood
  • 58,414
  • 16
  • 114
  • 157
SRP
  • 209
  • 6
  • 15
  • 1
    I suggest reading up on CSS. Anything in a separate file can be included inline. You could also just paste the contents of that file into a – Libra Sep 24 '20 at 15:31
  • btw, you can't have Hover effect without using either ` – Alberto Sinigaglia Sep 24 '20 at 15:32
  • you know that you can include style element into your html file where you will set all your css. If this is what you want ? – MaxiGui Sep 24 '20 at 15:32
  • Can you add CSS Firstly in question ? – Rayees AC Sep 24 '20 at 15:34
  • @MaxiGui This is what i want (i think !) but i don't know where i have to place it – SRP Sep 24 '20 at 15:35
  • @RayeesAC I can't add any file, sorry – SRP Sep 24 '20 at 15:36
  • try this `img:hover{transform:scale(1.5)}` – Rayees AC Sep 24 '20 at 15:38
  • @Laif Do you have any example of that ? – SRP Sep 24 '20 at 15:38
  • What, specifically? @SRP – Libra Sep 24 '20 at 15:40
  • @Laif An example when i can paste the contents into a – SRP Sep 24 '20 at 15:45
  • When I say header I'm referring to the tag. Refer to MaziGui's answer below, he used what I am talking about. Again, you should really be using an external CSS sheet. – Libra Sep 24 '20 at 15:46
  • Thx for your advice i will try what MaziGui said. And i will paste your message about an external CSS sheet aha ! – SRP Sep 24 '20 at 15:48

1 Answers1

5

Here a full example working with css :hover. No need JS.

You need to set the style element into your head element out of body element

<html>
  <head>
    <style>
    .zoom {
      transition: transform .2s; /* Animation */
    }

    .zoom:hover {
      transform: scale(1.5); /* (150% zoom - Note: if the zoom is too large, it will go outside of the viewport) */
      position:absolute;
      right:0;
    }
    </style>
  </head>
  <body>
    <p>&nbsp;</p>
    <hr />
    <h4 class="zoom"><img style="border: 1px solid black; align: right;" title="" src="https://cdn.pixabay.com/photo/2020/09/09/13/03/bike-riding-5557589_1280.png" alt="" width="204" align="right" border="1" hspace="" vspace="" /></h4>
    <h4><strong>4. Entrez votre mot de passe.</strong></h4>
    <ul style="list-style-type: disc; list-style-position: inside;">
    <li>Puis, cliquez sur "Suivant".</li>
    </ul>
    <p>&nbsp;</p>
  </body>
</html>

Here is a solution with JS Adapt from answer here : Javascript: Zoom in on mouseover WITHOUT Jquery or plugins

<html>
  <head>
    <style>
    </style>
  </head>
  
  <body>
    <p>&nbsp;</p>
      <hr />
      <h4>
        <img id="imgZoom" style="border: 1px solid black; align: right;" width="200px" height="200px" align="right" onmousemove="zoomIn(event)" onmouseout="zoomOut()" src="https://cdn.pixabay.com/photo/2020/09/09/13/03/bike-riding-5557589_1280.png">
        <div style="border: 1px solid black;
            width: 200px;
            height: 200px;
            display: none;
            background-image: url('https://cdn.pixabay.com/photo/2020/09/09/13/03/bike-riding-5557589_1280.png');
            background-repeat: no-repeat;"
            id="overlay"
            onmousemove="zoomIn(event)"></div>
        </h4>
      <h4><strong>4. Entrez votre mot de passe.</strong></h4>
      <ul style="list-style-type: disc; list-style-position: inside;">
      <li>Puis, cliquez sur "Suivant".</li>
      </ul>
    <p>&nbsp;</p>
    
    
    <script>
      function zoomIn(event) {
        var element = document.getElementById("overlay");
        element.style.display = "inline-block";
        var img = document.getElementById("imgZoom");
        var posX = event.offsetX ? (event.offsetX) : event.pageX - img.offsetLeft;
        var posY = event.offsetY ? (event.offsetY) : event.pageY - img.offsetTop;
        element.style.backgroundPosition = (-posX * 4) + "px " + (-posY * 4) + "px";

      }

      function zoomOut() {
        var element = document.getElementById("overlay");
        element.style.display = "none";
      }
    </script>
  </body>
</html>

Last example with style directly in body: It is accepted normaly based https://www.w3.org/Submission/1996/1/WD-jsss-960822

<html>

  <body>
    <style>
      .zoom {
        transition: transform .2s; /* Animation */
      }

      .zoom:hover {
        transform: scale(1.5); /* (150% zoom - Note: if the zoom is too large, it will go outside of the viewport) */
        position:absolute;
        right:0;
      }
      </style>
    <p>&nbsp;</p>
    <hr />
    <h4 class="zoom"><img style="border: 1px solid black; align: right;" title="" src="https://cdn.pixabay.com/photo/2020/09/09/13/03/bike-riding-5557589_1280.png" alt="" width="204" align="right" border="1" hspace="" vspace="" /></h4>
    <h4><strong>4. Entrez votre mot de passe.</strong></h4>
    <ul style="list-style-type: disc; list-style-position: inside;">
    <li>Puis, cliquez sur "Suivant".</li>
    </ul>
    <p>&nbsp;</p>
  </body>
</html>
MaxiGui
  • 6,190
  • 4
  • 16
  • 33
  • I don't have the header on the editor, you can check all i see here : https://pastebin.com/FiScLYJa – SRP Sep 24 '20 at 15:43
  • `header` element and `head` are totaly different. Plus, the code you are providing goes for sur into a `body` element – MaxiGui Sep 24 '20 at 15:44
  • This is all i can modify is it still possible to include the – SRP Sep 24 '20 at 15:50
  • @SRP Ok in this case, you can check the 2nd snippet I added it is with js and it all goes to the body element – MaxiGui Sep 24 '20 at 15:58
  • I added all your code since the first

    to the last

    – SRP Sep 24 '20 at 16:15
  • Can you tell me on what type of project you are working ? Because it might that it is deleting script element for security reason – MaxiGui Sep 24 '20 at 16:28
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/222030/discussion-between-srp-and-maxigui). – SRP Sep 24 '20 at 16:28