Search code examples
cssvertical-alignment

css vertical-align not working


Please help to vertically align the tittle. It seems not working properly.

enter image description here

<html>
<body>

<head>
<style type="text/css">
html *
{
    margin: 0px;
    padding: 0px;}
.Title
    {
    width: 50%;
    display:inline-block;
    vertical-align:middle;
    text-align: center;
    font-weight: bold;
    font-size: larger;
    border: solid;
    border-width: thin;
    }

.btn{
    color:white;
    background-color:#8CC152;
    margin: 0px !important;
    width: auto;
    display: inline-block;
    padding: 6px 12px;
    margin-bottom: 0px;
    font-size: 14px;
    font-weight: 400;
    line-height: 1.42857;
    text-align: center;
    white-space: nowrap;
    vertical-align: middle;
    cursor: pointer;
    -moz-user-select: none;
    background-image: none;
    border: 1px solid transparent;
}
.btn:hover{
    background-color:#A0D468;
}

.btn-next{
    border-radius: 4px;
    border-top-left-radius: 0px;
    border-bottom-left-radius: 0px;
    float:right;
}

.btn-prev{
    border-radius: 4px;
border-top-right-radius: 0px;
    border-bottom-right-radius: 0px;
    float:left;
}
</style>
</head>

<div class='Title'>
    <p>
        This is a title
        <a href='?m=1'><span class='btn btn-prev'>LEFT</span></a>
        <a href='?m=2'><span class='btn btn-next'>RIGHT</span></a>
        </p>
</div>

</body>
</html>

Solution

  • Set a line-height for the paragraph

    p {
     line-height: 32px;
     vertical-align: middle;
    }
    

    p {
      line-height: 32px;
      vertical-align: middle;
    }
    <head>
      <style type="text/css">
        html * {
          margin: 0px;
          padding: 0px;
        }
        .Title {
          width: 50%;
          display: inline-block;
          vertical-align: middle;
          text-align: center;
          font-weight: bold;
          font-size: larger;
          border: solid;
          border-width: thin;
        }
        .btn {
          color: white;
          background-color: #8CC152;
          margin: 0px !important;
          width: auto;
          display: inline-block;
          padding: 6px 12px;
          margin-bottom: 0px;
          font-size: 14px;
          font-weight: 400;
          line-height: 1.42857;
          text-align: center;
          white-space: nowrap;
          vertical-align: middle;
          cursor: pointer;
          -moz-user-select: none;
          background-image: none;
          border: 1px solid transparent;
        }
        .btn:hover {
          background-color: #A0D468;
        }
        .btn-next {
          border-radius: 4px;
          border-top-left-radius: 0px;
          border-bottom-left-radius: 0px;
          float: right;
        }
        .btn-prev {
          border-radius: 4px;
          border-top-right-radius: 0px;
          border-bottom-right-radius: 0px;
          float: left;
        }
      </style>
    </head>
    
    <div class='Title'>
      <p>
        This is a title
        <a href='?m=1'><span class='btn btn-prev'>LEFT</span></a>
        <a href='?m=2'><span class='btn btn-next'>RIGHT</span></a>
      </p>
    </div>
    
    </body>
    
    </html>