html - How to allign text vertical and horizontal? -


i have layout want have text centered horizontaly , verticaly

i tried (display: table-cell; vertical-align: middle)

but when tried ruin layout:

li {list-style:none;}  h3 {margin:0px}  p {margin:0px}  ul {margin:0px; padding:0px}
<li style="background:#263f73; border-style: dotted; border-width: 1px; height:100px;">      <div style="width:70%; float: left; "><h6 style="margin:0px;"><h3>text</h3></h6></div>    <ul style="float: right; height:100%; width: 30%;">      <li>        <li style=" height:50%; background:#ffffff;"><p style=" margin: 0px;"><div><p class="centertext">text</p></div></li>        <li style=" height:50%; background:#fff465;"><p style=" margin: 0px;"><div><p class="centertext">text</p></div></li>      </li>    </ul>      </li>

first of have in mind html not valid! (like h3 can't in h6, li must inside ul, if using external css, don't use inline too...)

if text single line ever, apply line-height same container:

li {    list-style: none;  }  p {    margin: 0px  }  ul {    margin: 0px;    padding: 0px  }  .centertext {    line-height: 50px;  }  .text1 {    line-height: 100px;    font-size: 18px;  }
<li style="background:#263f73; border-style: dotted; border-width: 1px; height:100px;">      <div style="width:70%; float: left; ">      <h6 style="margin:0px;" class="text1">text1</h6>    </div>    <ul style="float: right; height:100%; width: 30%;">      <li style=" height:50%; background:#ffffff;">        <p style=" margin: 0px;">          <p class="centertext">text2</p>        </li>      <li style=" height:50%; background:#fff465;">        <p style=" margin: 0px;">          <p class="centertext">text3</p>      </li>    </ul>    </li>

if have multiline text, use display: table , display: table-cell

li {    list-style: none;  }  p {    margin: 0px  }  ul {    margin: 0px;    padding: 0px  }  .table {    display: table;  }  .tcell {    display: table-cell;    vertical-align: middle;  }
<li style="background:#263f73; border-style: dotted; border-width: 1px; height:100px;">      <div style="width:70%; float: left; height: 100%;" class="table">      <div style="margin:0px;" class="tcell">text1<br/>multiple</div>    </div>    <ul style="float: right; height:100%; width: 30%;">      <li style=" height:50%; background:#ffffff; width: 100%" class="table">        <p style=" margin: 0px;" class="tcell">          text2        </p>      </li>      <li style=" height:50%; background:#fff465; width: 100%" class="table">        <p style=" margin: 0px;" class="tcell">          text3        </p>      </li>    </ul>    </li>


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

How do you convert a timestamp into a datetime in python with the correct timezone? -