Solved

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

Posted on 2016-09-13
3
39 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
  • 2
3 Comments
 
LVL 21

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 21

Expert Comment

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

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
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…
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now