0

This what I get [1]: https://i.stack.imgur.com/TGQiR.png

I want it like this [2]: https://i.stack.imgur.com/Mu7g5.png

Here is my code, this is the CSS file.

.shape{
  width:200px;
  height:250px;
  color:#4F5E73;
  margin:20px auto;
  background-color:rgb(236, 236, 236);
  text-align:center;
}

This is how I show the shape and text.

<div class="shape">
  <span style="font-size:72px;"> 7 </span> <br />
  <span style="font-size:18px;"> minutes to Applecross High School </span> <br />
</div>
Sergej
  • 1,082
  • 11
  • 27
Jalon Juanis
  • 65
  • 12

6 Answers6

2

Try this, add padding to .shape and to align everything in center and within our assigned height and width, so for that we have included box-sizing:border-box; this tells browser to include padding within element's height and width (i.e. overe-here is .shape).

.shape {
  width:210px;
  height:250px;
  color:#4F5E73;
  background-color:rgb(236, 236, 236);
  text-align:center;
  padding:50px;
  box-sizing:border-box;
}  
<div class="shape">
  <span style="font-size:72px;"> 7 </span>
  <span style="font-size:18px;"> minutes</span><br>
  <span>to Applecross High</span> 
  <span>School </span> 
</div>
Sergej
  • 1,082
  • 11
  • 27
frnt
  • 8,455
  • 2
  • 22
  • 25
0

You can use flex for modern browsers. css:

  .shape{
      display:flex;
      align-items: center;
      width:200px;
      height:250px;
      color:#4F5E73;
      margin:20px auto;
      background-color:rgb(236, 236, 236);
      text-align:center;
  }

you should use some fallbacks for -webkit- and so on

Simon Kraus
  • 736
  • 4
  • 14
0

HTML:

<div class="shape">
  <div class="vert-align">
    <span style="font-size:72px;"> 7 </span> <br />
    <span style="font-size:18px;"> minutes to Applecross High School </span> <br />
  </div>
</div>

CSS:

.shape {
  width: 200px;
  height: 250px;
  color: #4F5E73;
  margin: 20px auto;
  background-color: rgb(236, 236, 236);
  text-align: center;
}
.shape .vert-align {
  position: relative;
  top: 50%;
  transform: translateY(-50%);
}
Sergej
  • 1,082
  • 11
  • 27
SamAI
  • 121
  • 1
  • 8
0

If you want a solution which is supported across browsers do sth like this:

HTML

<div class="shape">
  <div class="shape__inner">
    <span style="font-size:72px;">7</span>
    <span style="font-size:18px;">minutes to Applecross High School</span>
  </div>
</div>

CSS

.shape {
    width:200px;
    height:250px;
    color:#4F5E73;
    margin:20px auto;
    background-color:rgb(236, 236, 236);
    text-align:center;
}

.shape__inner {
   position: relative;
   top: 50%;
   transform: translateY(-50%);
}

Check a working example here

Marios Fakiolas
  • 1,525
  • 1
  • 12
  • 19
0

This jsFiddle can be a possible solution for your problem.

 .shape {
   width: 200px;
   height: 250px;
   color: #4F5E73;
   margin: 20px auto;
   background-color: rgb(236, 236, 236);
   text-align: center;
 }
 
 span {
   position: relative;
   top: 20%;
 }
<div class="shape">
  <span style="font-size:72px;"> 7 </span>
  <br />
  <span style="font-size:18px;"> minutes to Applecross High School </span>
  <br />
</div>
ReshaD
  • 936
  • 2
  • 18
  • 30
0

It's work, this is the answer.

.shape {
  width:210px;
  height:250px;
  color:#4F5E73;
  background-color:rgb(236, 236, 236);
  text-align:center;
  padding:50px;
  box-sizing:border-box;
}  
<div class="shape">
  <span style="font-size:72px;"> 7 </span>
  <span style="font-size:18px;"> minutes</span><br>
  <span>to Applecross High</span> 
  <span>School </span> 
</div>
Jalon Juanis
  • 65
  • 12