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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:59:17+00:00 2026-06-13T23:59:17+00:00

So say i have a <div> with a long text inside and defined height,

  • 0

So say i have a <div> with a long text inside and defined height, and when text overflows that div height i want to display ... at the end of the text, so this is easy with a little css, but i want something a bit more advanced.

What i want is to have that ... and a button (Show more), and i kind of made it, but it’s quite a dirty hack and i know there should be better solution, anyways please take a look a this fiddle: http://jsfiddle.net/DgBR2/1/

Basically i just floated another div with white background on top of the text, but if i would want to change that text height or something else this would create problems in the future, so i want something better.

  • 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-13T23:59:19+00:00Added an answer on June 13, 2026 at 11:59 pm

    Revised 11/07/2012

    Robust Text Overflow Slider

    Robust Fiddle

    Features:
    1. Auto adjusts for font size
    2. Auto Adjusts for ‘Show More / Show Less’ Buttons
    3. Easily Change Animation Speed
    4. Easily Change ‘Show More / Show Less’ Button Spacing
    5. Easily Choose Which side the ‘Show More / Show Less’ Displays On
    6. Easily Set how many Lines of Text should initially appear

    JQuery

    //Editable Values
    
    var lines = 5; //Choose how many lines you would like to initially show
    var buttonspacing = 7; //Choose Button Spacing
    var buttonside = 'right'; //Choose the Side the Button will display on: 'right' or 'left'
    var animationspeed = 1000; //Choose Animation Speed (Milliseconds)
    
    
    //Do not edit below
    
    var lineheight = $('.text').css("line-height").replace("px", "");
    startheight = lineheight * lines;
    $('.text_container').css({'height' : startheight });
    
    var buttonheight =  $('.button').height();
    
    $('div.container').css({'padding-bottom' : (buttonheight + buttonspacing ) });
    
    if(buttonside == 'right'){
        $('.button').css({'bottom' : (buttonspacing / 2), 'right' : buttonspacing });
    }else{
       $('.button').css({'bottom' : (buttonspacing / 2), 'left' : buttonspacing });
    }
    
    $('.open').on('click', function(){
            var newheight = $(this).parent('div.container').find('div.text').height();
            $(this).parent('div.container').find('div.text_container').animate({'height' : newheight }, animationspeed );
            $(this).hide().siblings('.close').show();
    
            });
    
    $('.close').on('click', function(){
        var h = $(this).parent('div.container').find('div.text').height();
        $(this).parent('div.container').find('div.text_container').animate({'height' : startheight }, animationspeed );
        $(this).hide().siblings('.open').show();
        });
    
    
    $('div.container').each(function(){
        if( $(this).find('div.text').height() >= $(this).find('div.text_container').height() ){
            $(this).find('.button.open').show();
    
        }
    });
    

    HTML

    <div class="container">
        <div class="text_container">
            <div class='text'>
    
               // Text goes Here
    
            </div>
         </div>
        <div class='button open'>...Show More</div>
        <div class='button close'>...Show Less</div>
    </div>
    

    CSS

    .button {position:absolute; z-index:5; display:none; cursor:pointer; color:#555555;}
    .close {display:none; }
    .open {display:none;}
    
    .container{
        width:200px;
        overflow:hidden;
        border:1px solid #cacaca;
        border-radius:5px;
        font-size:12px;
        position:relative;
        margin:auto;
        padding:10px 10px 0px 10px;
        float:left;
        margin:5px;
    }
    
    .text_container{
        height:105px;
        overflow:hidden;
    
    }
    
    .text {}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have this text that I want to display in an HTML
Lets say we have a <div style=width:100px;>This text is too long to fit</div> The
Let's say I have a div that's 500 x 500px. Inside that, I have
So my questions is similar to this: crop text too long inside div What
Lets say I have a div #elements with a ul inside.The div has position:
say for example i have 2 div in a div like this <div style=width:
lets say I have a <div id=god> Supertext </div> I want to assign <div
Let's say I have this: <div id=wrapper> <pre class=highlight> $(function(){ // hide all links
So let's say i have one div and one image like this <div id=image_wrapper>
Let's say I have a div: <div id=mainContent>some random text. bla bla bla.</div> let's

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.