"Trigger a hover effect on one element, but have it impact a

I have a simple question that I couldn't find a direct answer to, so here it is: I have two boxes and I want to hover over the first one but have it affect the second one (meaning when hovering over the first box, the second box should scale up with a transition effect). Is this achievable with CSS alone or would I need to use JavaScript as well? Here's my code:

<!DOCTYPE html>
<html>
<head>
<style>
div {
display: inline-block;
margin: 30px;
font-weight: bold;
}
.a {
width: 100px;
height: 100px;
border : 1px solid black;
line-height: 100px;
text-align: center;
}
.c{
width: 100px;
height: 100px;
border : 1px solid black;
line-height: 100px;
text-align: center;
}
.d:hover {
 transform: scale(1.2);
  transition: all 0.9s ease-in-out;
}
</style>
</head>
<body>

<div class="a b">Hover me</div>

<div class="c d">Affect me</div>

</body>
</html>

Answer №1

When working with CSS, you have the option to utilize + for targeting a direct sibling or ~ for selecting an indirect sibling.

.x:hover + .y {
 transform: rotate(30deg);
 transition: all 0.5s ease-in-out;
}

Answer №2

It is recommended to utilize a combinator selector for this scenario.

div {
  display: inline-block;
  margin: 30px;
  font-weight: bold;
}

.a {
  width: 100px;
  height: 100px;
  border: 1px solid black;
  line-height: 100px;
  text-align: center;
}

.c {
  width: 100px;
  height: 100px;
  border: 1px solid black;
  line-height: 100px;
  text-align: center;
}

.a:hover + .d {
  transform: scale(1.2);
  transition: all 0.9s ease-in-out;
}
<div class="a b">Hover me</div>
<div class="c d">Affect me</div>

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

The border should not start at the left of the page; instead, I would like it to begin at the letter "T" in "Tech."

I am having an issue with the bottom border starting from the extreme left of the page. I want it to start from the letter "T" in Tech instead. #page-container { width: 1250px; margin: 0 auto; } h2 { font-weight: normal; padding-left: 15px; ...

I am looking to organize my content by creating categories such as How, When, and Why for different videos. How can I achieve this for a large amount of text

I am in the process of organizing categories for the text I have. My goal is to display text from specific categories based on the color that a random video lands on. For example, if the video lands on the color red, I want text from the category labeled " ...

Error: The function `res.status` is unsupported

I've been working on a function to allow uploading images to imgur through my express API (nodejs), but I'm running into an issue when calling a function that returns a promise: TypeError: res.status is not a function at uploadpicture.then T ...

Insert an HTML element prior to the content using the ng-bind directive

I am working with a table that is generated by an ng-repeat loop and connected to a model using ng-bind. In the first column, I want to dynamically add an HTML element based on a specific condition. How can I accomplish this? <!doctype html> <htm ...

Error in ReactJS: Module ""."" not found

I encountered an issue when attempting to call a function inside that retrieves an asset URL from the local directory. The error message displayed was missing module "." The function operates flawlessly outside of the require function. header.jsx class ...

Continue running the remaining part of the function once the asynchronous function has completed its execution

To obtain the last 4 digits of a payment using Stripe, I need to execute an async function that contains another async function. Once these functions are resolved, I aim to update the database with the last four digits. It is crucial to ensure that the dat ...

Add the file to the array field

I struggle with manipulating sub documents in MongoDB, especially when trying to implement an address book structure like the one below: { [<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="90e5e3f5e2a1d0fdf1f9fcbef3fffd"> ...

Consolidating various JavaScript events into one single event

Whenever a user types a key, my function is triggered. I want to consolidate these events so they only occur at a maximum rate of 500ms. Is there a simple method to achieve this in Javascript or through a commonly used library? Or should I create my own t ...

How can you limit access to certain routes in Nuxt.js to only clients who possess a valid JWT token?

In Nuxt.js, implementing authentication can be done in the following steps: The client authenticates by sending its credentials in an HTTP request to a specific API route in the Nuxt backend; The Nuxt backend responds with a JWT token for accessing protec ...

Overflow of Primary Text in Material UI List Item

I apologize if this question has already been asked, but I have searched and couldn't find the solution! I am facing an issue with a Material UI listview that has a fixed width within a sidebar. The titles of some options are not properly rendering a ...

Initiate an Ajax form submission to dynamically update the contents of a

For my project, I've set up a main page specifically for document creation in the DocumentsController. Users have the ability to alter the status of the document on this page. If the status is NEW, users are permitted to add a new device (referred to ...

Showing outcomes by making rapid consecutive AJAX requests

If you need a visual representation, I have a PHP script for a Hotel Management application that showcases a calendar (with columns representing days of the month and rows displaying prices per day). This script can be accessed in edit mode, where it gene ...

The attribute "value" for Material-UI autocomplete cannot be used in conjunction with the "getOptionLabel" attribute

<Autocomplete id="license-select" options={licReqList} value = {licReqList[0] ? licReqList[0].licReqStr : null} getOptionLabel={(option) => option.licReqStr} onChange={ha ...

Identify and forward to the mobile-friendly version of the site

I am currently working on a website that requires separate files for mobile view as the html layout poses challenges in making it responsive. My goal is to find code that can detect if the user is accessing the site from a mobile device, and automatically ...

When using Google login in React and Node.js, the requested scope may not be returned as expected

Looking to get additional scope data from Google API during login on my app. I am utilizing react-google-login to obtain a token in my React application with the following scopes: scope='https://www.googleapis.com/auth/user.birthday.read https://www. ...

Modify Bootstrap Card Styling Using JavaScript

When the clock strikes certain evening hours on my website, the Bootstrap card's default light style no longer fits the dark theme. I've attempted to switch the card to a dark style by tying in some JavaScript code, but it's not quite doing ...

Displaying the Status of a Script that is Running Asynchronously

My script takes around 5 minutes to complete and sends an email with a file attachment once finished. The entire process happens on a single PHP page without using AJAX. I want the front end to handle form submission seamlessly, processing the request in ...

Using threejs to pass multiple secondary geometries into vertex shaders

Suppose I have a geometry that I am using to create points or an InstancedMesh by utilizing the vertices. However, if I want to change this underlying geometry to something else - such as from a cone to a sphere - that has the same number of vertices, how ...

Restricting the amount of text that can be applied to an HTML5 canvas

Currently, I am in the process of developing a tree structure engine using an HTML5 canvas. In this engine, each tree node is connected to a database and has a unique name along with various other values. To represent these nodes visually, I have assigned ...

Can you share tips for passing a variable from a post request to a function that accepts parameters as a string or an array of strings in Node.js?

I am struggling to insert the variable named query into the end of the prompt. I attempted to use template literals but it was unsuccessful. (async () => { const gbtResponse = await openai.createCompletion({ model: "text-davinci-002", prompt ...