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

  • SEARCH
  • Home
  • 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 8024407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:51:52+00:00 2026-06-04T22:51:52+00:00

I would like to improve my user experience of the following code: HTML: <div

  • 0

I would like to improve my user experience of the following code:

HTML:

<div class="news-item">
    <div class="main-content">
        <div class="header"> Header 1 </div>
        <div class="content"> lorum ipsum </div>
        <div class="time"> time </div>
    </div>
</div>

<div class="news-item">
    <div class="main-content">
        <div class="header"> Header </div>
        <div class="content"> lorum ipsum </div>
        <div class="time"> time </div>
    </div>
</div>​

JavaScript:

jQuery(document).ready(function() {
    $(".header").click(function () {
      $(this).parent().toggleClass("expand");
    });
});​

CSS:

body {
    background-color: whitesmoke;
}

.header{
    font-size: 20px;
    padding-bottom: 20px;
    cursor:pointer;
}

.main-content {
    margin: 0 0 12px 70px;
    padding: 0;
    background: rgb(251, 251, 251);
    width: 80%;
    -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
    -moz-box-shadow: 0 1px 2px rgba(0,0,0,0.35);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
    position:relative;
    margin-left: 20px;
    margin-top: 20px;
    background-color: white;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
    padding: 22px;
    height: 20px;
    overflow: hidden;
}

.expand {
    height: 200px;
}​

Demo: http://jsfiddle.net/9UJ7f/4/

As you may notice, when you click the Header, the box expands or collapses.

However, this only works when we click the Header, e.g. when we click the box’s border (in collapsed mode) nothing happens.

To eradicate “void-clicks”, I would like it to be like this:

A. In Collapsed Mode:
If you click anywhere on the box (.main-content class), the item will expand

B. In Expanded Mode:
If you click only the .Header class, the item contracts again.

What would be the best approach to do this ?

UPDATE:

OK, you were right. The CSS was a bit off.
I choose sandeep’s solution as it was the most minimalistic but best working solution.
But also thanks to everyone else who helped. Especially the JS solutions from thecodeparadox & Arif. (though it still has some “void clicks” around the border).
You are awesome, guys. I’ll give you all a thumbs up.

  • 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-06-04T22:51:54+00:00Added an answer on June 4, 2026 at 10:51 pm

    Give padding to heading DIV. Write like this:

        .main-content {
            margin: 0 0 12px 70px;
            padding: 0;
            background: rgb(251, 251, 251);
            width: 80%;
            -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
            -moz-box-shadow: 0 1px 2px rgba(0,0,0,0.35);
            box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
            position:relative;
            margin-left: 20px;
            margin-top: 20px;
            background-color: white;
            -webkit-border-radius: 5px;
            -moz-border-radius: 5px;
            border-radius: 5px;
            padding-bottom: 22px;
            height: 42px;
            overflow: hidden;
        }
        .header  ~ div{
            margin:22px;
        }
    
        .header{
            font-size: 20px;
            padding: 22px;
            cursor:pointer;
        }
    

    Check this http://jsfiddle.net/9UJ7f/14/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to improve the lambda-code generated for the assert OCaml 3.12.1 construct.
I am using Ruby on Rails 3.2.2 and I would like to improve code
I would like to improve the speed of my script that uploads a small
Would like to sort the following XML by joining the fsxml/formula/ingrrow where itemcode =
Would like to know the c# code to actually retrieve the IP type: Static
I am developing my own class model for my database and I would like
I am developing a GWT app and I would like to improve the performance
Does OpenID improve the user experience? Edit Not to detract from the other comments,
I am using Ruby on Rails 3.0.7 and I would like to improve the
I have a decent working web application (Java/Servlet/Jsp) that I would like to improve

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.