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, 2022 in HTML by Deepak
• 980 points
6,088 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

when I click the right button in my slider it moves right, but after once moving right its neither moves right nor left

Views.py File def index(request): allProds ...READ MORE

Oct 25, 2020 in HTML by Dhruvil
• 120 points
1,052 views
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, 2022 in HTML by Tejashwini
• 780 points
566 views
0 votes
0 answers

Center a DIV horizontally and vertically

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

May 23, 2022 in HTML by Kichu
• 19,040 points
392 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, 2022 in HTML by Tejashwini
• 3,820 points
404 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, 2022 in HTML by Tejashwini
• 3,820 points
496 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, 2022 in HTML by Ashwini
• 5,430 points
3,589 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
10,540 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,250 points
2,846 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
924 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 3,638 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