Alter the color of a hyperlink when it is hovered over

Looking to create a menu with links and descriptive paragraphs that change color when hovered over. Preferably done with CSS only, without the use of JS or jQuery.

For example:

<a class="title" href="page1.html">Page 1</a>
<hr/>
<a class="description" href="page1.html">Description of Page 1</a>
<br><br>
<a class="title" href="page2.html">Page 2</a>
<hr/>
<a class="description" href="page2.html">Description of Page 2</a>
<br><br>
<a class="title" href="page3.html">Page 3</a>
<hr/>
<a class="description" href="page3.html">Description of Page 3</a>

Thank you!

Answer №1

To achieve this effect using only CSS, you can group the elements under a single parent element (such as a div or a p).

Don't forget to adjust the anchor styling in order to be able to change the color. a{color:inherit}

.colorChanger {
  color:green;
}
.colorChanger:hover {
  color:blue;
}
a{
  color:inherit;
}
<div class = 'colorChanger'>
  <a class="title" href="page3.html">Page 1</a>
  <hr/>
  <a class="description" href="page3.html">Description of Page 1</a>
</div>
<br><br>
<div class = 'colorChanger'>
  <a class="title" href="page3.html">Page 2</a>
  <hr/>
  <a class="description" href="page3.html">Description of Page 2</a>
</div>
<br><br>
<div class = 'colorChanger'>
  <a class="title" href="page3.html">Page 3</a>
  <hr/>
  <a class="description" href="page3.html">Description of Page 3</a>
</div>

Answer №2

If you want to enhance the look of your pages, consider adding a unique class for identification!

a.page_1:hover ~ a.description.page_1{
  color:green;
}
<a class="title page_1" href="page1.html">Page 1</a>
<hr/>
<a class="description page_1" href="page1.html">Description of Page 1</a>
<br><br>
<a class="title" href="page2.html">Page 2</a>
<hr/>
<a class="description" href="page2.html">Description of Page 2</a>
<br><br>
<a class="title" href="page3.html">Page 3</a>
<hr/>
<a class="description" href="page3.html">Description of Page 3</a>

Answer №3

Give this a shot: Check out the demo here

<div class="title active"><a href="page1.html">Page 1</a>

    <hr/>
    <p class="description">Description of Page 1</p>
</div>
<br>
<br>
<div class="title"><a href="page2.html">Page 2</a>

    <hr/>
    <p class="description">Description of Page 2</p>
</div>
<div class="title">
    <br>
    <br>
<a href="page3.html">Page 3</a>

    <hr/>
    <p class="description">Description of Page 3</p>
</div>

CSS:

.title {
    color:green;
}
.title:hover>.description, .active>.description {
    color:red;
    background:yellow;
}

Answer №4

.header:hover + .details {
   <customstyle>
}

However, this effect will only work if you eliminate the <br/> as it specifically targets immediate sibling elements.

Implementing this with JavaScript or jQuery would be much simpler and wouldn't necessitate altering your HTML structure to conform to a CSS-only solution.

Answer №5

Here is a CSS snippet that can help solve this issue

.title:hover + .description {
    color: #ff0000;
}

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

An error occurs when I attempt to run npm init

Error MODULE_NOT_FOUND When running npm init in the project folder, this error is displayed. View Image ...

How can you apply the min-width property to a CSS element floating to the right?

Check out this demonstration When utilizing float:right in the CSS rules, the html does not adhere to the specified min-width. .right { float:right; background:blue; min-width:400px; } By removing the float:right or adjusting it to float:lef ...

Apply a CSS3 Box Shadow to a diagonal corner

Currently, I am exploring some new coding techniques to enhance my skills. I have a slanted left corner design element. Now, I am trying to incorporate a box shadow effect as shown in the following image: https://i.sstatic.net/1MnL2.png This is the code ...

The resize() function in jQuery triggers a stack overflow exception

I am trying to manage the resizing of a div on my website, but I am encountering a stackoverflow exception when using the resize function. Can someone please help me understand what I am doing wrong? For reference, here is a jsfiddle example: https://jsfi ...

Hide the 1, 2, 3 page buttons in Datatables pagination and instead display only the Next and Previous buttons for navigation

I recently implemented datadables.net pagination for my HTML table. I am looking to customize the pagination buttons by hiding or removing the 1, 2, 3 ... buttons and only display Next and Previous Buttons. Is there a way to achieve this by setting paging ...

The image tag disrupting the spacing between lines

Here's a snippet of the css and html code: CSS: div { height:24px; line-height:24px; } HTML: <div><img src="image.png"/>Text</div> According to the code, a div should be 24 pixels high with text vertically centered after ...

ChakraUI failing to display on the screen

Exploring Chakra UI in my latest project has been an exciting journey for me. I made sure to install all the necessary dependencies and started importing components from the ChakraUI Docs. Initially, I successfully imported and rendered the button feature ...

The linear gradient feature in asp.net does not function properly on Internet Explorer versions 6 through 8

After running the following code below, it appears that the linear gradient is not functioning properly in IE6 to IE8. background-image: linear-gradient(45deg, white 0%, gray 50%, black 100%); I attempted to resolve this issue by adding the code snippet ...

Tips for inserting an object model with a hyperlink attribute into a table cell using Django

Currently, I am creating a basic web page with the help of django. I have a table on this page that displays a list of articles. Each article is comprised of a name, id, summary, and link. The main objective is to have the article name function as a clicka ...

Is there a way to design a mosaic-style image gallery featuring images of varying sizes in a random and dynamic layout, all without relying

In my quest to create a unique mosaic-style image gallery, I have scoured the internet for suggestions and have come across numerous recommendations for using available plugins. However, I am curious if there is a way for me to personally create a mosaic ...

Whenever I try to include something within the `componentWillUnmount` function,

I'm currently learning React on my own. I've been trying to save session data in my componentWillUnmount method. However, when I add code inside componentWillUnmount, nothing seems to happen. I tried debugging by adding console logs and debugger ...

Send a notification for every change made to a text field in Python

As a beginner in Python and web programming, I currently have functional HTML and Python code on app engine utilizing jinja2 and webapp2 libraries. This code retrieves query results based on user input in a text box followed by hitting the submit button. H ...

Using a background image in the navigation menu with CSS

Looking to create a horizontal menu with a responsive background image. Struggling with the issue of the 'ul' menu being misaligned with the background image when in full-screen mode. Attempted to use separate 'div' containers for the ...

Persist the modified contenteditable data into a JSON file by utilizing PHP Ajax

I am currently working on making a webpage content editable using HTML 5 and saving the data in a JSON file for future use. Additionally, I would like to implement AJAX to load only the edited part of the page and have a PHP file modify the JSON file. An ...

Guide to creating a dynamic amount of slides in a React carousel for optimal responsiveness

Looking for a solution to adjust the number of elements displayed in my React Carousel based on available size? I have a React Carousel that currently shows 3 elements at one time. Here is the code snippet: const RCarousel = ({items}) => { const numIt ...

What is the name of the scrolling header effect achieved in the following?

I've been seeing a lot of people using a unique header effect lately and I'm curious to learn more about how it's done. Can anyone explain the process behind achieving this effect, what it's called, and if there are any good tutorials a ...

What steps are required for my font to be displayed on my website?

I am completely new to programming and have found myself struggling with website development. I can't seem to figure out why my text is not displaying in the custom font I want. It shows up as white italics instead. Any assistance would be greatly app ...

Vue JS: Extracting both the unique ID and value from an array of input simultaneously

I am new to Vue and currently exploring its capabilities. I am experimenting with the Element UI for Vue's user interface. Specifically, I am working with the Input Number Component, to manage an array of data. Let's assume my data is structured ...

Building a stack of DIVs, some with fixed heights and others without, potentially using only CSS

Hello everyone! I am having trouble deciding on the best approach to achieve a layout like the one below: +------------------------------------------------------------+ | div 0 , varying height +---------------------------------------------------------- ...

Ways to vertically align a div in Bootstrap 4?

As I delve into working with bootstrap 4, I am experimenting with creating various basic layouts. In line with the guidelines provided in bootstrap 4 documentation, I aimed to vertically align block elements by applying the class align-items-center. Despi ...