Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3240622
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:06:23+00:00 2026-05-17T18:06:23+00:00

I have two divs, whose heights I would like to control relative to each

  • 0

I have two divs, whose heights I would like to control relative to each other. The point of these divs is that when a user mouses over one of them, it expands vertically and the other retracts vertically (smoothed with CSS transitions). Basic markup:

<div class="product">
    <h2>Product Name</h2>

    <div class="preview" style="background:url('/images/preview.png'); "></div>
    <div class="detail" style="background:url('/images/design.png'); "></div>

    <div class="product_info">
        <span class="quantity">7 Available</span>
        <span class="price">$19</span>
    </div>
</div>

This is generated a number of times with unique images and other data pulled from a database, so these images are just placeholders, but that’s not the question.

Here’s the stripped down CSS:

div.product {
    margin: 4px;
    padding: 4px;
    display: inline-block;
    width: 221px;
    height: 319px;
    box-shadow: 0 0 5px #ccc;
    -moz-box-shadow: 0 0 5px #ccc;
    -webkit-box-shadow: 0 0 5px #ccc;
}

div.product div.preview, div.product div.detail {
    height: 127px;
    width: 205px;
    margin: auto;
    margin-bottom: 2px;
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
    box-shadow: 0 0 5px #ccc;
    -moz-box-shadow: 0 0 5px #ccc;
    -webkit-box-shadow: 0 0 5px #ccc;
    -moz-transition: 0.25s linear;
    -o-transition: 0.25s linear;
    -webkit-transition: 0.25s linear;
}

div.product div.detail:hover, div.product div.preview:hover {
    height: 254px;
}

div.product h2 {
    width: 100%;
    text-align: center;
    margin-bottom: 4px;
}

div.product span.price {
    color: #B32B2B;
    font-weight: bold;
    font-size: 14px;
    text-align: right;
    float: right;
}

div.product span.quantity {
    text-align: left;
    float: left;
}

Now, the idea is that when you mouse over either image it expands to fill the space of the other image, which shrinks in response. This can’t be done in CSS with this markup, and not with anything I’ve tried.

I need to use JavaScript on each one of those divs for onmouseover and previousSibling to modify the CSS height. The problem is, things just don’t want to work for me. Anyone have a solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T18:06:24+00:00Added an answer on May 17, 2026 at 6:06 pm

    Okay, thanks to WSkid, I’ve got a solution working. Took only minor modifications. Final JavaScript:

    <script type="text/javascript">
        $(document).ready(function(){
            $('div.preview').each(function(){
                var curDiv = $(this);
                curDiv.hover(function(){
                    curDiv.nextAll($('div.detail:first')).addClass('short');
                    curDiv.addClass('expand');
                },function(){
                    curDiv.nextAll($('div.detail:first')).removeClass('short');
                    curDiv.removeClass('expand');
                });
           });
            $('div.detail').each(function(){
                var curDiv = $(this);
                curDiv.hover(function(){
                    curDiv.prevAll($('div.preview:first')).addClass('short');
                    curDiv.addClass('expand');
                },function(){
                    curDiv.prevAll($('div.preview:first')).removeClass('short');
                    curDiv.removeClass('expand');
                });
           });
        });
    </script>
    

    Final CSS:

    div.preview, div.detail {
        height: 205px;
    }
    
    div.expand {
        height: 248px;
    }
    
    div.short {
        height: 8px;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two divs that are floating next to each other. What i would
I have two applications written in Java that communicate with each other using XML
I need a solution that will set the heights of two divs whose class
I have two divs floating next to each other, with class name div1 and
I have two divs placed inside a larger div. Each one of these two
I have two divs and two separate links that triggers slideDown and slideUp for
I have a container div that holds two internal divs; both should take 100%
I have two divs inside a div, I want them both adjacent to each
I have two divs that are float:left: <div id=inventor> <table> <tr id=1><td>Alexander Graham Bell</td></tr>
I have a div with two nested divs inside, the (float:left) one is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.