Attempting to enlarge logo or image when cursor hovers over it

Seeking to enhance logo/image size when cursor hovers over it, but facing an issue where it enlarges even on areas outside of the image itself - View Example. I followed a tutorial to achieve this effect, and specified the width as 1024x1024 for the logo/image in question. However, there seems to be a problem with the sizing.

<html>
<head>
  <title>Moral & Ethical Issues Concerning the Use of Computer Technology</title>
  <link rel="stylesheet" href="style.css">
  <link href="https://fonts.googleapis.com/css2?family=Montserrat+Alternates&display=swap" rel="stylesheet">
  <body>
    <div class="main">
      <nav>
            <div class="logo">
              <img src="logo.png">
            </div>
            <div class="navigation-links">
              <ul>
                <li><a href="#">general</a></li>
                <li><a href="#">pages</a></li>
                <li><a href="#">contact</a></li>
              </ul>
            </div>
      </nav>
      <div class="gift">
        <img src="giftbox.png" onmouseover=this.src="giftboxhover.png" onmouseout=this.src="giftbox.png">
      </div>
    </div>

  </body>
</html>

CSS:

*{
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Montserrat Alternates', sans-serif;
}
.logo {
  flex-basis: 15%;
   margin: 0;
}
.logo img{
  padding: 35px;
  width: 250px;
  height: 250px;
  transition: transform .9s ease;
  overflow: hidden;
}
.logo:hover img{
  transform: scale(1.35)
}
.navigation-links{
  flex: 1;
  text-align: right;
  margin-top: -205px;
  margin-right: 96px;
}
.navigation-links ul li {
  list-style: none;
  display: inline-block;
  margin: 15;
  font: Montserrat;
  font-weight: 700;

}
.navigation-links ul li a{
  color: #fff;
  text-decoration:none;
}
.gift img{
  height: 60px;
  float: right;
  margin-top: -61px;
  padding-right: 20px;
}

.main{
  width: 100%;
  height: 100vh;
  color: fff;
  background: linear-gradient(-60deg, #FFC300, #FF8166, #0087FF, #F44FFF);
  background-size: 400% 400%;
  position: relative;
  overflow: hidden;
  animation: changebackground 35s ease-in-out infinite;
}

@keyframes changebackground {
    0%{
        background-position: 0 50%;
    }
    50%{
      background-position: 100% 50%;
    }
    100%{
        background-position: 0 50%;
    }
}

Answer №1

The reason for this issue is that the .logo element in your CSS is taking up a width that exceeds the available space on the screen. If you want to learn more about how to prevent a div from being larger than its contents, you can visit this link.

To solve this problem, I recommend setting a specific max-width for the logo div.

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Montserrat Alternates', sans-serif;
}

.logo {
  flex-basis: 15%;
  margin: 0;
  max-width: 300px;
}

.logo img {
  padding: 35px;
  width: 250px;
  height: 250px;
  transition: transform .9s ease;
  overflow: hidden;
}

.logo:hover img {
  transform: scale(1.35)
}

.navigation-links {
  flex: 1;
  text-align: right;
  margin-top: -205px;
  margin-right: 96px;
}

.navigation-links ul li {
  list-style: none;
  display: inline-block;
  margin: 15;
  font: Montserrat;
  font-weight: 700;
}

.navigation-links ul li a {
  color: #fff;
  text-decoration: none;
}

.gift img {
  height: 60px;
  float: right;
  margin-top: -61px;
  padding-right: 20px;
}

.main {
  width: 100%;
  height: 100vh;
  color: fff;
  background: linear-gradient(-60deg, #FFC300, #FF8166, #0087FF, #F44FFF);
  background-size: 400% 400%;
  position: relative;
  overflow: hidden;
  animation: changebackground 35s ease-in-out infinite;
} 

@keyframes changebackground {
  0% {
    background-position: 0 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0 50%;
  }
}
<html>

<head>
  <title> Moral & Ethical Issues Concerning the use of Computer Technology </title>
  <link rel="stylesheet" href="style.css">
  <link href="https://fonts.googleapis.com/css2?family=Montserrat+Alternates&display=swap" rel="stylesheet">

  <body>
    <div class="main">
      <nav>
        <div class="logo">
          <img src="logo.png">
        </div>
        <div class="navigation-links">
          <ul>
            <li><a href="#">general</a></li>
            <li><a href="#">pages</a></li>
            <li><a href="#">contact</a></li>
          </ul>
        </div>
      </nav>
      <div class="gift">
        <img src="giftbox.png" onmouseover=this.src="giftboxhover.png" onmouseout=this.src="giftbox.png">
      </div>
    </div>

  </body>

</html>

Please note: To avoid similar issues in the future, you can simply inspect the elements on the page and check their sizes on the screen. Best of luck!

Answer №2

The reason the Image hover effect is not working is because the Parent div was selected instead of the Image itself. To fix this, update the code as follows:

*{
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Montserrat Alternates', sans-serif;
}
.logo {
  flex-basis: 15%;
   margin: 0;
}
.logo img{
  padding: 35px;
  width: 250px;
  height: 250px;
  transition: transform .9s ease;
  overflow: hidden;
}
.logo img:hover{ /* <<<<---  Update this line */
  transform: scale(1.35)
}
.navigation-links{
  flex: 1;
  text-align: right;
  margin-top: -205px;
  margin-right: 96px;
}
.navigation-links ul li {
  list-style: none;
  display: inline-block;
  margin: 15;
  font: Montserrat;
  font-weight: 700;

}
.navigation-links ul li a{
  color: #fff;
  text-decoration:none;
}
.gift img{
  height: 60px;
  float: right;
  margin-top: -61px;
  padding-right: 20px;
}

 


.main{
  width: 100%;
  height: 100vh;
  color: fff;
  background: linear-gradient(-60deg, #FFC300, #FF8166, #0087FF, #F44FFF);
  background-size: 400% 400%;
  position: relative;
  overflow: hidden;
  animation: changebackground 35s ease-in-out infinite;
}

@keyframes changebackground {
    0%{
        background-position: 0 50%;
    }
    50%{
      background-position: 100% 50%;
    }
    100%{
        background-position: 0 50%;
    }
}
<html>
<head>
  <title>  Moral & Ethical Issues Concerning the use of Computer Technology </title>
  <link rel="stylesheet" href="style.css">
  <link href="https://fonts.googleapis.com/css2?family=Montserrat+Alternates&display=swap" rel="stylesheet">
  <body>
    <div class="main">
      <nav>
            <div class="logo">
              <img src="logo.png">
            </div>
            <div class="navigation-links">
              <ul>
                <li><a href="#">general</a></li>
                <li><a href="#">pages</a></li>
                <li><a href="#">contact</a></li>
              </ul>
            </div>
      </nav>
      <div class="gift">
        <img src="giftbox.png" onmouseover=this.src="giftboxhover.png" onmouseout=this.src="giftbox.png">
      </div>
    </div>

  </body>
</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Caution: It is important for each child within a list to have a distinct "key" prop when using react-input

I'm currently facing an issue with the following code snippet: {array.map((item) => ( <> <input key={item.id} type="checkbox" /> ...

JavaScript event listener 'click' not functioning properly

I'm facing an issue with a click event in a script that is associated with a specific div id. When I move the mouse within the div area and click (the cursor remains unchanged), the event listener does not activate. How can I make the div area clickab ...

Open the PDF document in a stylish jQuery popup like fancybox or a similar plugin

Can a PDF file be loaded in a popup? I understand that some browsers may require Adobe Reader to view PDFs, but Chrome has its own built-in PDF viewer. ...

Moving your cursor over the text will eliminate the border of the <img> located directly above it

Check out the latest products here! <ul class="products"> <li class="product first"> <a href="http://www.gwendolynbarnes.com/product/finis/"> <img width="117" height="150" src="http://www.gwendolynbarnes.co ...

Adjust the divs right element by adding or removing 1 pixel for every size change in the browser

I have been exploring different approaches to achieve this task and it seems like using javascript might be the most effective way. I am currently dealing with a stubborn social icon container placement issue. More details on my previous question can be fo ...

Update the innerHTML content dynamically every 5 seconds with Vue.js

I'm working on a new website and I'd like to spice things up by changing the header text with a random word every 5 seconds. Here's the starting point: const header = document.querySelector('.header') const needs = ['jacket& ...

Unable to move up and down in my iframe

I am currently working on an Instagram page that is visible through an iframe. Everything seems to be functioning fine on my iMac, but I am facing an issue with scrolling on my iPhone and iPad? After reviewing my code, I couldn't find any hidden over ...

What are the steps for implementing responsive design animation in my particular scenario?

Can someone please help me with a strange bug in Chrome? I am trying to create a responsive design for my app. The width of the 'item' element should change based on the browser's width. It works fine when the page first loads in Chrome, b ...

Root location for offline and pre-production in the Backbone boilerplate router

I am currently utilizing the backbone boilerplate found at https://github.com/tbranyen/backbone-boilerplate My development process involves working on static HTML/JS files offline and conducting tests offline before deploying them to another site for pre- ...

Improved method for managing hash URLs in AJAX-enabled websites

When dealing with pages that have a hash mark in the URL address bar, it can be inconvenient unless using HTML 5 and history.pushState() for AJAX loads. For example, when item1.html is loaded and then the user clicks to view item2.html, the URL changes to ...

Displaying truncated title text

Would it be feasible to display clipped text (overflow: hidden) in a way that is fully readable when hovered over? An attempt like this: div:hover { overflow: visible; background-color: yellow; } results in the text overlapping, making it impossible ...

Interacting with blog posts through comments on both Facebook and the blog's official page on the social media

I'm currently working on a PHP blog and I am looking to integrate Facebook comments into each blog post. My goal is for these comments to be visible both on the website and on its corresponding Facebook page, allowing users from different platforms to ...

Creating a JavaScript-powered multi-department form: A step-by-step guide

Is there a way to maintain the form displayed on a webpage created in HTML5 and JavaScript for logging calls across three different departments? With buttons assigned to each department, clicking on them reveals the respective HTML form. That said, every t ...

Learn how to utilize AngularJS to create dropdown menus within data cells of an HTML table

I am working on populating rows in an HTML table based on the response I get from AngularJS. My goal is to have one of the table data cells formatted as a dropdown menu. Specific Requirements: The dropdown menu should include three values (A, B, and C). ...

What could be causing the font of the background text to change when CSS3 animation is applied?

Have you ever noticed a font style change in the background text when applying CSS3 animations for opacity and scale transforms? I have some text content on my page, including a "Click me" link that triggers a popup with a CSS3 animation. However, I'v ...

Retrieving data from a div container on an active website

Imagine having a website similar to , where you want to automatically retrieve the time value every second and save it in a .txt file. Initially, I considered using OCR (optical character recognition) software for this task, but soon realized that relying ...

Mastering the art of utilizing particles.js

Particles.js doesn't seem to be functioning properly for me—I'm struggling to pinpoint the issue. Any guidance or suggestions would be greatly welcomed, as I'm unsure whether it's related to an external dependency... HTML: <div ...

modifying the arrangement of span elements

Currently, I am assisting a colleague in crafting articles for scientific journals. Interestingly, various publishers have distinct requirements regarding the format of cited authors in the bibliography. Some demand "last name, first name," while others pr ...

Having trouble getting my image to appear at the top of the website, could it be an alignment issue?

Here is a screenshot showing the issue: https://i.stack.imgur.com/kSVQj.png. The quote on my website does not align to the top as expected. Can anyone provide a solution for this? Below is the corresponding code: <body> <div id="container"> ...

CSS for a Div with a Subtle Curve at the Bottom

Is there a way to achieve this specific shape using CSS? I attempted to use the following resources, but they didn't provide me with the desired outcome. Curved border with stroke in pure CSS? http://jsfiddle.net/ECHWb/ .banner-img{ height: 661p ...