Skip to content
  • Recent
  • Tags
  • Popular
  • Users
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

Lay Theme Forum

  1. Home
  2. General Discussion
  3. Image swap with mouse hover with <div> responsive size?

Image swap with mouse hover with <div> responsive size?

Scheduled Pinned Locked Moved General Discussion
4 Posts 2 Posters 1.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dsong3832
    wrote on last edited by
    #1

    Hello,

    Trying to combine css and html code to make an image change (two images with same sizes) with a simple mouse hover. Since the img src can't be changed with css only, I'm using a <div class> insert. However, I'm wondering if it's possible to have this <div> section also conform to the responsive size changes as in with my other images on the project as of now (The div section is in the middle of images, and when I set the css size fixed with px values, it remains the same regardless of window size).

    Could anyone help? Thanks!

    1 Reply Last reply
    0
    • mariusjopenM Offline
      mariusjopenM Offline
      mariusjopen
      Global Moderator
      wrote on last edited by
      #2

      Hi @dsong3832
      this is very difficult to understand.

      Can you show us a little sketch or even a link to your website?

      You could use background images of CSS:
      https://stackoverflow.com/questions/18032220/css-change-image-src-on-imghover

      Best!

      Marius

      www.mariusjopen.world

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dsong3832
        wrote on last edited by
        #3

        Hello @mariusjopen

        Sorry about the confusion. Though I'm also experimenting with different things on the website and unable to share the actual link, here's sort of what I have so far:

        In Laytheme - Custom CSS & HTML, I have set up the css as following:

        Hover {
        background: url('image A.jpg');
        width=100px
        height=150px
        }
        div:hover {
        background: url('image B.jpg');
        width=100px
        heigh=150px
        }

        Now, I've inserted a following code, using the "page" editor section -> HTML Code, in between images that are displayed on my current page, as in the following:

        <div id=hover></div>

        And it shows the hovering images perfectly! The only problem is... My whole page is now responsive to the window size, meaning the size of image changes according to your window size. Yet, since I've dedicated the pixel width to <div> code, that's the only image that doesn't change its size and goes out of whack in proportion when I change the window size.

        However, I realized that <div> doesn't really show up unless I dedicate the pixel width and height. So my question is, is it possible to make my <div> hovering image also respond to the changes in window size?

        Thank you!

        1 Reply Last reply
        0
        • mariusjopenM Offline
          mariusjopenM Offline
          mariusjopen
          Global Moderator
          wrote on last edited by
          #4

          Hi @dsong3832
          ok. Now I understand.

          Your solution is a quick and dirty solution. but possible. I would not use it for a complex website. But for a portfolio website which you build yourself it should be fine.

          Otherwise you need to use jQuery.

          First of all your code looks pretty messed up. Try this:

          #hover {
          background: url('image A.jpg');
          background-repeat: no-repeat;
          background-size: contain;
          width: 30vw;
          height: 10vw;
          }
          
          #hover:hover {
          background: url('image B.jpg');
          }
          
          <div id="hover"></div>
          

          Play around with the size to see what fits you the best.Also you can play around with the background-image-size.

          I hope I could help!

          Have a good day!

          Marius

          www.mariusjopen.world

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          I also code custom websites or custom Lay features.
          šŸ’æ Email me here: šŸ’æ
          info@laytheme.com

          Before you post:
          1. When using a WordPress Cache plugin, disable it or clear your cache.
          2. Update Lay Theme and all Lay Theme Addons
          3. Disable all Plugins
          4. Go to Lay Options → Custom CSS & HTML, click "Turn Off All Custom Code", click "Save Changes"

          This often solves issues you might run into

          When you post:
          1. Post a link to where the problem is
          2. Does the problem happen on Chrome, Firefox, Safari or iPhone or Android?
          3. If the problem is difficult to explain, post screenshots / link to a video to explain it
          Online Users
          G
          Glyph
          N
          NAS
          A
          alasdair17
          Forgot your key, lost your files, need a previous Lay Theme or Addon version? Go to www.laykeymanager.com
          laytheme.com
          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Recent
          • Tags
          • Popular
          • Users
          • Search