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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:08:10+00:00 2026-05-11T21:08:10+00:00

I have a webpage with an elastic layout that changes its width if the

  • 0

I have a webpage with an elastic layout that changes its width if the browser window is resized.

In this layout there are headlines (h2) that will have a variable length (actually being headlines from blogposts that I don’t have control over). Currently – if they are wider than the window – they are broken into two lines.

Is there an elegant, tested (cross-browser) solution – for example with jQuery – that shortens the innerHTML of that headline tag and adds “…” if the text would be too wide to fit into one line at the current screen/container width?

  • 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-11T21:08:10+00:00Added an answer on May 11, 2026 at 9:08 pm

    I’ve got a solution working in FF3, Safari and IE6+ with single and multiline text

    .ellipsis {
        white-space: nowrap;
        overflow: hidden;
    }
    
    .ellipsis.multiline {
        white-space: normal;
    }
    
    <div class="ellipsis" style="width: 100px; border: 1px solid black;">Lorem ipsum dolor sit amet, consectetur adipisicing elit</div>
    <div class="ellipsis multiline" style="width: 100px; height: 40px; border: 1px solid black; margin-bottom: 100px">Lorem ipsum dolor sit amet, consectetur adipisicing elit</div>
    
    <script type="text/javascript" src="/js/jquery.ellipsis.js"></script>
    <script type="text/javascript">
    $(".ellipsis").ellipsis();
    </script>
    

    jquery.ellipsis.js

    (function($) {
        $.fn.ellipsis = function()
        {
            return this.each(function()
            {
                var el = $(this);
    
                if(el.css("overflow") == "hidden")
                {
                    var text = el.html();
                    var multiline = el.hasClass('multiline');
                    var t = $(this.cloneNode(true))
                        .hide()
                        .css('position', 'absolute')
                        .css('overflow', 'visible')
                        .width(multiline ? el.width() : 'auto')
                        .height(multiline ? 'auto' : el.height())
                        ;
    
                    el.after(t);
    
                    function height() { return t.height() > el.height(); };
                    function width() { return t.width() > el.width(); };
    
                    var func = multiline ? height : width;
    
                    while (text.length > 0 && func())
                    {
                        text = text.substr(0, text.length - 1);
                        t.html(text + "...");
                    }
    
                    el.html(t.html());
                    t.remove();
                }
            });
        };
    })(jQuery);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a webpage that uses a custom plugin, like this: <embed height=0 width=0
Have a webpage that will be viewed by mainly IE users, so CSS3 is
I have this webpage that I want to post to my profile in FB.
I have a webpage that uses sprites for its navigation link. In IE7 sometimes
I have a webpage, in which there is a sort that I have to
I have a webpage that is giving me this error on a couple of
I have a webpage that pulls information from a database, converts it to .csv
I have a webpage (say www.example.com/a.asp) .. I am having an iframe in this
I have a webpage that is taking way too long and need to optimize
I have a webpage on my site that displays a table, reloads the XML

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.