-5

I have the following code.

.circle
{
width:251px;
height:251px;
border-radius:50%;
font-size:16px;
color:#fff;
line-height:50px;
text-align:center;
background:#000;
}
<!DOCTYPE HTML>
<body>
<div class="circle">Hello Guys! Please help Me...</div>
</body>

jsFiddle Link

What I want to do is center the text but I don't know how to do that.

Memor-X
  • 2,870
  • 6
  • 33
  • 57

2 Answers2

1

http://jsfiddle.net/b6335umv/1/ line-height is what you need.

.circle
{
width:251px;
height:251px;
border-radius:50%;
font-size:16px;
color:#fff;
text-align:center;
background:#000;
line-height: 251px;
}
Shniper
  • 854
  • 1
  • 9
  • 31
1

Line height is a good solution for this. The key being (when the containing element has a defined height) that line-height and the containing elements height are the same.

In your case

.circle {
  width:251px;
  height:251px;
  border-radius:50%;
  font-size:16px;
  color:#fff;
  line-height:251px;
  text-align:center;
  background:#000;
}

However in responsive cases where the elements are more fluid and the height isn't explicitly defined, it's usually better to use use line-height without units. This article has a pretty good explanation of the details about why.

catch22
  • 391
  • 1
  • 3
  • 13