Solved

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

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…

861 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