Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using CSS To Allow Text To Expand Upward And Downward Horizontally From The Center

Posted on 2016-09-13
3
Medium Priority
?
92 Views
Last Modified: 2016-09-14
Greetings:

I have text dynamically added to a web page heading. The heading allows for 2 lines of text contained in a single web control. The text will automatically wrap if needed. If the heading is one line it appears in the center of the page heading i.e. there is equal space above and below the text in the heading. If I have 2 lines of text the web control expands from the horizontal center of the page heading such that the 1st line is positioned up half the line height and the 2nd line is pushed down half the line height. The result is a heading which is again centered horizontally within the page heading.

Any suggestions from the experts is most appreciated on how to accomplish this via CSS.

Thank you kindly,
David Bach
0
Comment
Question by:David Bach
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 22

Accepted Solution

by:
Kim Walker earned 2000 total points
ID: 41797228
Absolutely position your div with the top left corner at dead center of the window. Then transform/translate your div -50% vertical and horizontal. This will center the text vertically regardless of how many lines it is. Look at this fiddle and add more content to generate more lines of depth. Remove the border and background color if you don't need it.
width: 180px; height: auto;
position: absolute;
left: 50%; top: 50%;
transform: translate(-50%,-50%);

Open in new window

2
 

Author Closing Comment

by:David Bach
ID: 41798747
WOOT! ... Thank you, Kim!

This was right on what I wanted to do!


Thank you very much for your prompt reply and perfect answer.

David Bach
0
 
LVL 22

Expert Comment

by:Kim Walker
ID: 41799073
You're welcome.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
This article discusses four methods for overlaying images in a container on a web page
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this Micro Tutorial viewers will learn how to create a CSS image sprite (In a later tutorial, viewers will learn how to use CSS and HTML to create a navigation menu using this sprite) Open a new Photoshop document with a width of (Icon width)x(N…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question