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 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

Ask A Question

Stats

  • Questions 116k
  • Answers 116k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Messaging applications in general are event driven, ie. when a… May 11, 2026 at 10:35 pm
  • Editorial Team
    Editorial Team added an answer The key to this is anchoring and docking. Design the… May 11, 2026 at 10:35 pm
  • Editorial Team
    Editorial Team added an answer I don't think you can declare that kind of thing… May 11, 2026 at 10:35 pm

Related Questions

I have a Google calendar embedded on a webpage, with events related to activities
I have a webpage with DHTML navigation menu. On the page also have an
I have an ObjectDataSource with an ID of ObjectDataSource1 on a webpage. I also
I have a webpage with search form fields and on click of submit button,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.