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 9214045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:53:19+00:00 2026-06-18T01:53:19+00:00

I have a div with ul inside it. ul can contain an unknown number

  • 0

I have a div with ul inside it. ul can contain an unknown number of elements. Each element can contain different amounts of content. It can be long or short lines of text.

Example: http://codepen.io/anon/pen/Augrd

This DIV when the page is loaded should not be more than 100px in height.

What I want to achieve: if inside this DIV is too much content and it is overflowed, then I want to display the link on which the user can click and “open” this DIV making it more in height.

  • 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-18T01:53:20+00:00Added an answer on June 18, 2026 at 1:53 am

    This detects the natural height of your <div> and automatically generates a “More…” link when the natural height of the <div> is greater than its current height (it does not show one if 100px is enough to show all the contents). You do not have to adjust the javascript for different heights of the <div>.

    DEMO

    Javascript

    var main = document.getElementById("main");
    var original_height = main.offsetHeight;
    main.style.height = 'auto';
    var natrual_height = main.offsetHeight;
    main.style.height = original_height+"px";;
    var more = document.getElementById("more");
    if (natrual_height > original_height) {
      more.innerHTML = '<a href="javascript:void(0)" onClick="show_more()">More...</a>';
    }
    function show_more() {
      if (main.offsetHeight < natrual_height) {
          main.style.height = 'auto';
          more.innerHTML = '<a href="javascript:void(0)" onClick="show_more()">Less...</a>';
      } else {
          main.style.height = original_height+"px";;
          more.innerHTML = '<a href="javascript:void(0)" onClick="show_more()">More...</a>';
      }
    }
    

    HTML

    <div id="main" class="main">
    <ul>
      <li>Something</li>
      <li>LoremLoremLoremLoremLoremLoremLorem</li>
      <li>Ipsum</li>
      <li>1234</li>
     <li>LoremLoremLoremLoremLoremLoremLoremLoremLoremLoremLoremLoremLoremLorem</li>
      <li>5678</li>
      <li>111111</li>
      <li>abc</li>
    </ul>
    </div>
    <div id="more">
    
    </div>
    

    CSS

    .main {
      height: 100px;
      overflow: hidden;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example, I have a bunch of elements inside a #dialogbox div, can I
I have a div element ( #receivedInfo ) with p elements inside of it.
I have a div having a css class MyClass. Inside this div, I can
I have a content div and inside it there are two div's with background
I have a div which contain other tags inside it <div id=mainDiv> <div> <table>
I have a div contain the image inside it like this : <div class=gallery
I have a div inside of a table which is inside of a form
I have this div inside a repeater, where i set the class, onmouseover and
I have a div inside a table cell. When I click in the table
I have one parent DIV inside parent DIV i have two DIV one in

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.