Left- center- and right-aligned text on the same line

0 votes

Is it possible to use HTML/CSS to have left-, center-, and right-aligned text on the same line under the following conditions?

The text on the left and right will be brief, but I do not know how long they will be.
The text in the center may be long enough to wrap.
The text in the center should be EXACTLY in the center.
The text in the center should not overlap the text in the left or right margins.
The obvious solution of using three divs, two of which are floating left and right, works well, except that the centerpiece of text is not exactly centered (for example, if the left piece of text is longer than the right, the center appears centered just right of the absolute center). I only need a solution that works on WebKit. Any ideas?

HTML:

<div id="left">Left</div>
<div id="center">Center text</div>
<div id="right">Right</div>

CSS:

#left {
    float: left;
    text-align: left;
    padding-right: 10px;
}

#center {
    text-align: center;
}

#right {
    float: right;
    text-align: right;
    padding-left: 10px;
}
Aug 17 in HTML by Deepak
• 940 points
153 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In HTML

0 votes
0 answers
0 votes
0 answers

horizontal line and right way to code it in html, css

I need to draw a horizontal line ...READ MORE

Aug 19 in HTML by Tejashwini
• 540 points
23 views
0 votes
0 answers

Center a DIV horizontally and vertically

Can I  CENTER A DIV vertically and horizontally? ...READ MORE

May 23 in HTML by Kichu
• 19,040 points
35 views
0 votes
0 answers

Is there a way to change the color of the placeholder text?

I tried to change the placeholder color ...READ MORE

Jul 4 in HTML by Tejashwini
• 1,960 points
23 views
0 votes
0 answers

What's the right way to decode a string that has special HTML entities in it?

Let's say I submit a service request ...READ MORE

Jul 8 in HTML by Tejashwini
• 1,960 points
33 views
0 votes
0 answers

How to use HTML to print header and footer on every printed page of a document?

Can HTML pages be printed with unique ...READ MORE

Jul 12 in HTML by Ashwini
• 1,160 points
256 views
0 votes
2 answers

Define a SQL query? What is the difference between SELECT and UPDATE Query? How do you use SQL in SAS?

HI.. SQL is Structured Query Language, which is ...READ MORE

answered Aug 8, 2020 in PHP by anonymous
5,050 views
0 votes
1 answer

Using/Handling colon inside a JSF generated HTML element ID in CSS selector

Yes, you can.  Just Backslash (\) the colon.  Like ...READ MORE

answered Nov 14, 2018 in Others by DataKing99
• 8,240 points
1,732 views
0 votes
1 answer

What is a css selector and where is it used?

CSS Selector is a combination of element ...READ MORE

answered Nov 21, 2018 in Data Analytics by Kalgi
• 52,350 points
296 views
0 votes
1 answer

What is the difference between span and div?

The div should be used to wrap sections of ...READ MORE

answered Jan 16, 2020 in Web Development by Niraj

edited Jan 21, 2020 by Niroj 2,371 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP