Creating a CSS rollover effect for your logo on a WordPress website

Struggling to implement a CSS image rollover on a Wordpress header logo. The solution may be simple for you experts, but I can't find it anywhere on Stackoverflow. Could it have something to do with the position? Adding :relative or :absolute doesn't seem to make any difference.

Check out my CSS below:

#top {
height: 105px;
padding-left: 10px;
padding-top:27px;
}
#logo {


/*  background-attachment: scroll;
background-image: url(images/logo.png);
background-repeat: no-repeat;
background-position: left top;*/
height: 70px;
width: 461px;
 }

 #logo a:hover { 

background-attachment: scroll;
background-image: url('images/flatgrey.png');
background-repeat: no-repeat;
background-position: left top;*/
height: 70px;
width: 461px;


 }

 #logo a {

display:block;
height: 70px;
width: 461px;

& PHP

  <body <?php body_class(); ?>>

<div id="outer">
    <div id="top">
        <div id="logo">
            <?php               
            ob_start();
            ob_implicit_flush(0);
            echo get_option('imbalance_custom_logo'); 
            $my_logo = ob_get_contents();
            ob_end_clean();
            if (
            $my_logo == ''
            ): ?>
            <a href="<?php bloginfo("url"); ?>/">
            <img src="<?php bloginfo('template_url'); ?    >/images/logo.png" alt="<?php bloginfo('name'); ?>" /></a>
            <?php else: ?>
            <a href="<?php bloginfo("url"); ?>/"><img src="<?php echo      get_option('imbalance_custom_logo'); ?>" alt="<?php bloginfo('name'); ?>" /></a>             
            <?php endif ?>

Answer №1

After removing the background-attachment and background-position lines for #logo, I updated the style for #logo to:

#logo {
background-image: url(images/logo.png);
background-repeat: no-repeat;
height: 70px;
width: 461px;
 }

It appears that this change resolved my issue. Would you like to try it out to see if it solves your problem as well?

Answer №2

If you're looking to switch out logo.png with flatgrey.png when hovering, the best approach is to remove the entire

<img src=".../images/logo.png"...>
tag and insert

background-image: url('images/logo.png');
into the CSS for #logo a. Additionally, make sure to transfer the background-repeat: no-repeat; line from the CSS for #logo a:hover to #logo a.

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

How come user CSS in Stylish takes precedence over the author's CSS?

Here's a sample page: <!DOCTYPE html> <html> <head> <style type="text/css"> body { background: black; } </style> </head> <body> </bod ...

What is the best way to choose all elements except for <body>? Alternatively, how can <body> be styled to its default appearance?

Web browsers often apply default styles to different elements, but users have the option to override these defaults using custom stylesheets. I personally like to customize these default styles with my own, for example: * {padding:0; margin:0; } However ...

Printing without sufficient paper will result in an incomplete printout

https://i.stack.imgur.com/jNlRr.jpg I am facing an issue with printing the last column "Potensi". The text in this column is not fully printed. How can I resolve this problem? I am using PHP. Thank you ...

Display and conceal different sections using hyperlinks

Hey there, I'm back with another issue related to this code snippet on jsfiddle: https://jsfiddle.net/4qq6xnfr/9/. The problem I'm facing is that when I click on one of the 5 links in the first column, a second div appears with 3 links. Upon clic ...

Emphasizing buttons that are in a "pressed" or "inactive" state

I've implemented three push buttons in my code using input with type="button", which act as toggle buttons (on/off). In the past, I used images to indicate when a button was pressed or reset, but now I want to achieve this effect using CSS. However, ...

Tips for preventing the appearance of a horizontal scroll bar when utilizing the FlexLayoutModule in Angular

import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-property-feed', templateUrl: './property-feed.component.html', styleUrls: ['./property-feed.component.scss'] }) export class Prope ...

Can a pledge be honored at a precise moment?

I have implemented transitions on my web page. When clicked, everything fades out to an opacity of 0 over a duration of 1 second. Then, a new page is swapped in and everything fades back in to an opacity of 1 over another 1-second duration. The issue aris ...

How to reduce the text input field size in Django Bootstrap for a sleeker design

I have a form with various elements like textfields, radio buttons, and text areas. The textfield size is currently too small and does not look good: I'm wondering how I can make the textfields slightly larger and why the height of the text area is s ...

Is there a way to modify the color of a checkbox within MUI?

I'm currently customizing the checkbox color in Material UI while using FormIk for data submission. I aim to change the default checkbox color to red, but I'm unsure about how to achieve this. <FormGroup> <Box display=" ...

Set the position to fixed so it doesn't scroll

Is there a way to create a fixed position div that remains in place when the user scrolls, similar to the effect shown in this example image? Position Absolute: https://i.sstatic.net/4RAcc.png Position Fixed (desired effect): https://i.sstatic.net/3DIna. ...

Looking for ways to incorporate both external and internal styling using jQuery and CSS in my template?

I've been working on a django project for a while now, and I'm facing some challenges with getting external and internal CSS to work. Only inline CSS seems to be functioning properly. I have two questions: How can I get external or internal C ...

Having trouble with the functionality of JQuery drop feature?

As I delve into implementing drag and drop functionality with JQuery, I encounter a peculiar issue. I have set up 3 'draggable' divs and corresponding 3 'droppable' divs. The intended behavior is for each draggable element to be accepte ...

Issues with Curved Corner Touchdown Feature

Having trouble with getting the round css to work properly in the below code It seems to be only applying the background color, but not the border styling The border code is on the same line as the round css: style=" border : 1px solid #D6D6D6; and t ...

Is it possible to have the logo centered with the menu bar?

I found a cool theme: Check it out here! Does anyone know how to center the logo and menubar on this template? <section class="page_toplogo ls s-pt-25 s-pb-20 s-py-md-30"> <div class="container"> ...

The request to access mywebsite/wp-admin/admin-ajax.php resulted in a 400 (Bad Request) error

I am currently utilizing Ajax to manage filters in a custom post type. However, I keep receiving a Bad Request error for both the POST and GET methods, and I'm unsure of the reason behind it. Here is the Ajax code that I am using: (function($) { ...

The close button within the modal is malfunctioning even with the implementation of the on() function

My "show more" button triggers the modal to pop up, but when I click on the X button in the top left corner, it doesn't close as expected. However, clicking outside of the box or pressing the "esc" key does work. I suspect that the issue lies with th ...

Contrasting the distinctions between a pair of CSS class declarations

After using my customized CSS class named myclass alongside Bootstrap's built-in class container, I have a question about how to declare a div element with both classes. Should I go with: <div class="myclass container">some code</div> o ...

Hello there! I'm currently working on implementing a button that will alter the CSS grid layout

I need help designing a button that can alter the layout of my CSS grid. The grid information is contained within a class called 'container'. My goal is to change the grid layout by simply clicking a button, using either HTML and CSS or JavaScri ...

Guide to dynamically refreshing a section of the webpage while fetching data from the database

I'm currently developing a website using PHP & MySQL where some queries return multiple records. Each record has its own dedicated page, allowing users to navigate between them using arrows. So far, everything is working smoothly. However, I've ...

I'm having trouble getting the "flex direction: row" property to work within a table row

First, I applied flex to the table > tr. Next, I configured the flex-direction to be row. table { width: 100%; } tr { display: flex; flex-direction: row; flex-wrap: wrap; overflow: hidden; width:100%; } td:nth-child(1) { flex: 0 0 20%; ...