Creating bespoke CSS for an individual post in WordPress

I am currently working on styling a landing page for a Facebook campaign within a WordPress website that is not my own. I want to style the elements of the landing page without affecting the general CSS of the entire website, so I am directly editing the elements within the text editor of the entry itself.

When users click on the link from Facebook, they will be directed to the landing page I'm creating. The primary components of this page are two buttons that will guide users further through the content. I have designed these buttons as squared anchor tags, but in order to enhance usability, I would like the background color to change when the user hovers over them.

Below is the code I used to create the buttons:

<a class="green" style="background-color: #92c03e; display: inline-block;
padding: 10px; margin-right: 20px; color: #ffffff; text-decoration:none;">
Button 1
</a>

<a class="blue" style="background-color: #35a8e0; display: inline-block; 
padding: 10px; color: #ffffff; text-decoration: none;">
Button 2
</a>

Normally, if I had a stylesheet, I could simply style the a:hover property with another background color, but since I am customizing individual elements on the page, I am unsure how to apply styles to the :hover state within the style="" attribute. Is there a way to manipulate the :hover property of an HTML element directly within the HTML code? Alternatively, can a stylesheet be created within the WordPress entry?

I attempted to incorporate the following code into the entry, but it did not produce the desired effect:

<style media="screen" type="text/css">
.green a:hover {background-color: #799f34;}
.blue a:hover {background-color: #2c8cba;}
</style>

If anyone could offer guidance on how to achieve this, I would greatly appreciate it! Thanks!

Answer №1

To override background-color directly in HTML, make sure to include !important in your CSS rules.

a:hover.green  {background-color: #799f34!important;}
a:hover.blue {background-color: #2c8cba!important;}

If you prefer to do this within HTML instead of CSS, here are a couple of examples I came across: example one and related post

Answer №2

I suggest placing this code inside a separate block/ div to distinguish this page from others. I have created a snippet of your code to provide clarity:

#land-pg .green:hover {background-color: #799f34 !important;}
#land-pg .blue:hover {background-color: #2c8cba !important;}
<div id="land-pg">

<a class="green" style="background-color: #92c03e; display: inline-block;
padding: 100px; margin-right: 20px; color: #ffffff; text-decoration:none;">
Button 1
</a>

<a class="blue" style="background-color: #35a8e0; display: inline-block; 
padding: 100px; color: #ffffff; text-decoration: none;">
Button 2
</a>

</div>
ANOTHER SAME DIV BELOW which are not affected
<a class="green" style="background-color: #92c03e; display: inline-block;
padding: 100px; margin-right: 20px; color: #ffffff; text-decoration:none;">
Button 1
</a>

<a class="blue" style="background-color: #35a8e0; display: inline-block; 
padding: 100px; color: #ffffff; text-decoration: none;">
Button 2
</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

"PxToRem: A handy PostCSS plugin for converting pixel units

As a beginner in the world of Node.js and post processors for CSS, I recently took the time to install the following tools after going through multiple articles: Node.js (including npm) Gulp PostCSS Pxtorem (a PostCSS plugin for Gulp) My goal is to util ...

Issue where the link in the first column of a horizontal scrolling table is unclick

In my attempt to create a fixed first column horizontal scrolling table, I encountered an issue where hyperlinks in the first column become unclickable once scrolled to the right. This seems to be because the fixed column is not clickable by default, and o ...

How to Use Conditional In-Line CSS for Internet Explorer and Other Browsers

After inspecting the source code for this website, I noticed a cool feature where the page changes based on your scrolling position. It creates a visually appealing effect. Upon further examination of the source in FireFox, I observed the use of -webkit-t ...

Is it possible to create a button function in HTML that can alter the CSS image tag?

Is there a way I could create a function that can retrieve a value, update an image source, and then incrementally select another value? It would be incredibly helpful if you could provide a reference where I could learn how to do this or explain it in det ...

Problem arising from animation not commencing at expected starting point

Creating a feature on an app that involves breathing exercises using CSS animations. The challenge I'm facing is ensuring the words "exhale" and "inhale" appear synchronously with the animation of a circle shrinking and enlarging. However, the animati ...

showing information obtained via ajax as a hyperlink

When using AJAX to pass an "id" and "data" to PHP, the following jQuery AJAX code is used: 1.$.ajax({//Make the Ajax Request 2. type: "POST", 3. url: "dbtryout2_2.php", 4. data:datastr, 5. success: ...

Using duplicate HTML elements with jQuery can cause the script to malfunction and become ineffective

Hello everyone! I am fairly new to jQuery and recently created a script that works perfectly for the HTML below. However, I am running into an issue when duplicating the HTML and script - after clicking, only the last project-info and project-images are be ...

What could be the reason that the style tag present in this SVG is not impacting any of the elements?

My SVG file consists of a single element with a fill set to red: <svg width="100" height="60" viewBox="0 0 100 60" fill="none" xmlns="http://www.w3.org/2000/svg"> <path fill="red" d=&qu ...

Issue occurred in ajax function when trying to present data in a form

I am encountering an issue while trying to fetch data from the database and display it in my form. The error message I'm getting is VM1704:1 Uncaught SyntaxError: Unexpected end of JSON input. In my PHP file, I have retrieved the data from the databas ...

Passing a value from a dropdown menu to a different template page in Django 1.6

I am looking to capture the user's selection from a dropdown field and use it to filter profile listings on the next page. The goal is for the user to choose an option from the dropdown on the index.html page, submit the form, and then be redirected t ...

Delete an entry from the list

I have a fully functional Ajax call and function that fills up a datalist. This datalist is utilized to choose from a limited list and add it to a UL element on the page. Once an option is added from the datalist to the actual list, I aim to eliminate that ...

Is it possible to specify the same attribute multiple times within an HTML5 element?

After reviewing the HTML5 specification (W3C Recommendation 28 October 2014), I am unable to locate any specific information on whether an element can have the same attribute specified multiple times. For instance, the attribute style sometimes has a lengt ...

full-page overlay is covering the entire screen

Is there a CSS-based solution to create an overlay that remains visible even when the page is scrolled down? I want to use this overlay behind a popup. Using JavaScript to set the height of the overlay based on the page's content is one option, but I& ...

Steps for initializing and loading the Ace editor:

I've been attempting to utilize the Ace code editor library (), but I'm encountering some issues. The embedding guide suggests that the required js files should be loaded from Amazon's CDN. <script src="http://d1n0x3qji82z53.cloudfront.n ...

Focusing on a particular iframe

I am currently using the "Music" theme from Organic Theme on my WordPress site and have inserted this code to prevent SoundCloud and MixCloud oEmbeds from stretching the page width: iframe, embed { height: 100%; width: 100%; } Although the fitvid ...

Craft a dynamic countdown timer that blinks using CSS

I am attempting to design a blinking countdown timer that starts at 5 seconds and disappears when it reaches 0. CSS: .blinky { transition: 1s opacity; -moz-transition: 1s opacity; -webkit-transition: 1s opacity; } HTML: <div id="count ...

placing a vertical bootstrap button along the left border

My goal is to place a vertical bootstrap button on the left side of the screen. Currently, I have implemented the following CSS: #button1 { position: absolute !important; z-index: 10 !important; left: 0px !important; bottom: 20% !important; tr ...

Does Courier New font have any downsides?

Is it possible to highlight text in a flex textarea using htmlText when certain font tags are not supported? I am looking for a font that is the opposite of Courier New so that when embedded in Flash and written with a specific color, I can achieve a hig ...

What is the best way to give a video a border-radius in an HTML/CSS code?

Is there a way I can apply border-radius to the <video> element? This is what my video currently looks like: (image shown here: <a href="https://i.sstatic.net/izKz0.png") I attempted styling the video tag with CSS, but the changes did ...

JavaScript: Modify the dropdown class with a toggle option

Hi there, I'm currently facing a small issue and I could really use some assistance. I have a dropdown menu with two selection options - "green" and "blue", and I need to toggle a class based on the selected option. If you'd like to take a look, ...