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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:09:33+00:00 2026-05-20T21:09:33+00:00

I have text with a background image of a fixed width and height. I

  • 0

I have text with a background image of a fixed width and height. I want the text to be a fixed number of lines (3). The text wraps differently in different browsers, sometimes inserting an extra line which makes the text go over the boundary of the background image. This means I have to add/remove words from my text and continually check the rendering in each browser to see that it is the same number of lines.

I am guessing that either the browsers are rounding the width/margin/padding so that the width of the container is different, or that the text is rendered slightly differently in each browser (with more or less width).

What would be the recommended practice for this? I want the text in the container to be no more than 3 lines long, so I am just as well to fix the height of the container.

  • 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-20T21:09:34+00:00Added an answer on May 20, 2026 at 9:09 pm

    The recommended practice is not do something like this. Try to redesign so that the background image isn’t/doesn’t need to be of fixed height and the text doesn’t need to be limited to exactly three lines. If this is some kind of requirement imposed on you by your boss/customer, you’ll need to talk with them and explain, that this isn’t something one can or should do in HTML/CSS.

    Keep in mind, that not only the width of the characters will be different in each browser resulting in different wrapping, but browsers will display the text lines in different heights, too, so it can be that your element can’t contain three lines.

    If you have no other choice, consider using overflow: hidden on the fixed-size element, however this will most likely lead to cut off letters and/or words.


    EDIT re comment:

    I don’t think the available space would variate between browsers. If you were using relative units (em, %), then maybe there would be rounding differences of one pixel max. However you are using pixels, which should be identical in all current browsers (in Standards Mode).

    Anyway I’m not saying you should restrict the amount of text you want to display, just give the text some space to “breath” and don’t give the element a fixed height in pixels. Instead:

    • Set a line-height (for example 1.25) and a min-height three times the amount (here 3.75em).
    • Use your best estimate to limit the text you want to put in there to three lines.
    • Add some JavaScript that shortens the text, in case it does happen to go over three lines.
    • Adjust your layout (including a flexible background for that element), so it can survive both a few pixels difference due to different browser’s (and more importantly the user’s preferred) font size and can survive an additional line of text just in the seldom case that you mis-estimated the text length and JavaScript isn’t available.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following HTML (note the CSS making the background black and text
I'm trying to have text spans pop up on a hover pseudo-class for different
I have a text file where I want to change only the first line
I'm looking to have text display vertically, first letter at the bottom, last letter
In a project we have text files looking like this: mv A, R3 mv
I have a text file on my local machine that is generated by a
I have one text input and one button (see below). How can I use
I have a text file of this format: L O A D C A
I have a text file in the root of my web app http://localhost/foo.txt and
I have a text file of URLs, about 14000. Below is a couple of

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.