Impact on adjacent div

Within my code, I have two sibling divs that contain additional nested divs as shown below:

<div class="btn_lists">
    <div class="btn green_btn">
        <img src="<?= asset_url() ?>images/escolar_07__1.png" />
    </div>
</div>
<div class="btn-desc-container">
    <div class="btn-desc_1">
        <p>Description</p>
    </div>
</div>

The initial status of btn-desc_1 is set to display: none; However, my goal is to have the display change to inline-block when hovering over green_btn.

Is there an efficient way to achieve this?

Answer №1

It is impossible to accomplish this using CSS alone. You can utilize the following jQuery code snippet:

$('.green_btn').hover(function(){
    $('.btn-desc_1').toggleClass('display-inline');
})

Check out the example here: http://example.com/jsfiddle-demo

Answer №2

A unique and slightly eerie response. May not be the most trustworthy source of information, as it is purely for illustrative purposes. Avoid using this method in a practical setting. Instead of hovering, interaction is achieved by clicking on images:

The use of :checked is limited to IE9+: https://developer.mozilla.org/en-US/docs/Web/CSS/:checked

To see a live example, click on the images of kittens: http://jsfiddle.net/bzH7S/2/

<body>
    <input type="radio" name="btn" value="1" id="radio1">
    <input type="radio" name="btn" value="2" id="radio2">
    <div id="wrap">
        <div class="btn_lists">
            <label for="radio1" class="btn btn1"><img src="1"></label>
            <label for="radio2" class="btn btn2"><img src="2"></label>
        </div>
        <div class="btn-desc-container">
            <div class="btn-desc_1"><p>Kitten One</p></div>
            <div class="btn-desc_2"><p>Kitten Second</p></div>
        </div>
    </div>
</body>

CSS:

body > input {
     display: none;
}

.btn-desc-container > div {
    display: none;
}

#radio1:checked ~ #wrap .btn-desc_1,
#radio2:checked ~ #wrap .btn-desc_2 {
    display: block;
}

Answer №3

There is no solution for achieving this unless btn_desc1 is a descendant of green_btn. In that case, the following CSS code would work:

.green_btn:hover > .btn-desc_1
{
    display:inline-block;
}

accompanied by this HTML structure:

<div class="btn_lists">
    <div class="btn green_btn">
        <img width='400px' heigh='400px' src="http://www.pieisgood.org/images/slice.jpg" />
        <div class="btn-desc_1">
        <p>Description</p>
    </div>
</div>

in your CSS file. Alternatively, you can use JQuery to achieve the same effect, as suggested by nidzik:

$('.green_btn').hover(function(){
    $('.btn-desc_1').toggleClass('display-inline');
})

Check out the demo here

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

Switching images with Jquery

Seeking help to create an FAQ page using HTML, CSS, and jQuery. My goal is to rotate an arrow when a question is opened and revert it back when another question is clicked. I've successfully achieved this with <p> tags but facing issues with the ...

CSS must be applied to various sections of an HTML document

For example, I have 2 CSS files. In one CSS file, I have the style: a{color: blue;} In the second file, I have: a{color: red;} I want to apply these styles to my HTML file. <div> <a>first file ...

Using relative positioning in CSS causes the div to move to a new line

Feel free to check out this demo I've created for reference: http://jsfiddle.net/jcb9xm44/ In a nutshell, the scenario involves two inline-block divs nested within a parent div: <div class="outer"> <div class="inner1"> Y & ...

IE9 does not properly display SVGs used as background images

Utilizing SVG files as backgrounds for my HTML elements has been successful in most major browsers. However, an issue arises when trying to ensure compatibility with Internet Explorer 9. The problem lies within IE9's rendering of the SVG backgrounds, ...

Tips for creating a scrolling animation effect with images

I'm currently attempting to create an animation on an image using HTML/CSS. The issue I'm facing is that the animation triggers upon page load, but I would like it to activate when scrolling down to the image. Below is my snippet of HTML: <fi ...

Incorporate AJAX functionality with a simple HTML button

Upon clicking the button, the AJAX call fails to execute. Below is the HTML code for the buttons: <td><button id=${data[i].id} name="update" type="button" value="${data[i].id}" class="btn btn-primary update" ...

What is the best way to implement CSS styling in the existing Vue.js template?

Currently delving into the world of Vue.js, I've discovered that styling child components is achieved by referencing classes, ids, and tags defined in the component's template. Let's take a look at the App.vue component as an example: <st ...

BeautifulSoup: Retrieve text from HTML lists that are designated exclusively with bullet points

Seeking assistance on how to extract the text specifically within a bulleted list from a Wikipedia article using BeautifulSoup. I am aware that list items are enclosed in <li> tags in HTML, regardless of the type of marker used before each item in t ...

CSS Flexbox: Dealing with Overlapping Flex Items on Narrow Screens

Hey there! I've successfully created a custom timeline using flexbox, but I'm encountering an issue on smaller screens. As the window size decreases, the flex items start to overlap. Is there a way you can assist me in adding some space without d ...

Changing the Color of Hamburger Menu Lines in Bootstrap

How can I change the color of the hamburger menu icon's lines for medium and smaller screen sizes? I have attempted changing it through style attributes and using !important in my CSS file, but so far nothing has been successful. ...

Stop vuetify from cluttering the global style scope

Seeking to embed a Vue component into another from an external source without using a Vue Plugin. The components are mounting correctly, but the embedded component's use of Vuetify is affecting the parent application's style. Visual examples can ...

The concept of CSS Parent Elements refers to the relationship

Is it possible to dynamically apply CSS style based on the parent property of a div element using JavaScript? Here is an example: <div clas="parent"> <div class="child"> <div class="x"></div> </div> </d ...

Refreshing HTML tables with AJAX in Django

After going through all the posts here, I found that some are outdated and others don't quite match my issue. Apologies for bringing it up again. I have a basic HTML table with data in it. My goal is to update this data without refreshing the entire ...

What is the best way to choose CSS class attributes using Mootools and the getStyle()

Seeking to duplicate an object, I am trying to figure out how to retrieve class CSS attributes from Mootools. css: .card { width: 109px; height: 145px; } html: <div id="cards"> <div class="card" id="c0"> <div class="face fron ...

Switching between a secondary menu using ClassieJS or jQuery?

Currently, the code is configured to toggle the same menu for every icon. To see my current progress, you can check out this fiddle: http://jsfiddle.net/2Lyttauv/ My goal is to have a unique menu for each individual icon. I began by creating the followi ...

Checkbox value not being accurately retrieved by Struts2 page

I have a form that captures phone information for two different phones, with each phone having its own set of details. If the user enters the same phone number for both phones, the second checkbox is automatically checked using the JavaScript code below: ...

Display a list of personalized post types and emphasize the item that is currently being viewed

I've created a unique type of post called 'product'. Every product page has a sidebar listing all products, with the current product displayed in bold text. For instance, when viewing product 3, it should appear like this: Sidebar Pr ...

Sliding an image from the left side to the right, and then repeating the movement from left to right

I am currently working on a CSS effect for some images. My goal is to have an image appear from the left side, move towards the right side, then reappear from the left and repeat this cycle. I managed to achieve this using the code below: @keyframes sli ...

Using AngularJS to automatically fill in HTML select fields

Encountering an issue with an HTML select element in AngularJS. The API response returns one of the values as an integer, however, setting the "value" attribute for autofill is proving to be a challenge. Below is a screenshot showcasing the data received ...

Instructions on transforming a XAML grid in WPF into a JSON array

Currently, I am utilizing a XAML WPF grid in my project and I am looking to transform the structure of the grid into JSON format. Do you have any suggestions or ideas on how this can be achieved? For reference, here is an example: <GridBinding> ...