1

I have a div in my site where I want text to be vertically aligned, here's some of the CSS

overflow-y:auto;
font-size: 150%;
justify-content: center;
flex-direction: column;
display:flex;
height:350px !important;
overflow-y:auto;

This works well when the text is short, but when it's long it gets cut off

m4n0
  • 29,823
  • 27
  • 76
  • 89
RobinReborn
  • 431
  • 2
  • 7
  • 23

2 Answers2

0

Have you tried using display: table-cell instead?

Also, you don't need !important;

HTML:

<div class="content">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec magna felis, porttitor eu porttitor at, mattis a ante. Suspendisse vitae porttitor tellus. Vivamus eget laoreet ligula, vitae dignissim ex. Phasellus accumsan porttitor lectus, non accumsan 
</div>

CSS:

.content {
    display: table-cell;
    vertical-align:middle;
    width:200px;
    height:350px;
    background: #ff0000;
}

JS Fiddle: http://jsfiddle.net/9ppf5xdg/

Phillip Chan
  • 993
  • 7
  • 17
0

Try using:text-align: center;

that alone should work just fine

I put 2 deferent div's one with a percentage width, with a shorter text and the other with a set px width, with a longer text.

div{
  background-color: royalblue;
  width: 50%;
  text-align: center;
  margin:2px;
}

.d{
  background-color: royalblue;
  width: 250px;
  text-align: center;
  margin:2px;
}
<div>Sup World</div>
<div class='d'>Sup World Sup World</div>
Michael Barreiro
  • 328
  • 1
  • 3
  • 9