Solved

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

Posted on 2016-09-13
3
74 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 500 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

Technology Partners: 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

CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

687 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