简体   繁体   中英

html button muliple line align

I need some help with the following button alignment issue within html and css.

The following fiddle shows the problem

<div>
  <button style="height:100px">
    <div style="display:table">
      <div style="display:table-cell; vertical-align:middle">
        bob
        <p>
          bill
        </p>
      </div>
    </div>
  </button>
  <button style="height:100px">
    <div style="display:table">
      <div style="display:table-cell; vertical-align:middle">
        bob
      </div>
    </div>
  </button>
</div>

How do I get the buttons vertically aligned with their contents in the middle of themselves ?

I think you need this:

 button{ height:100px; vertical-align: top; } .outer{ display:table; } .inner{ display:table-cell; vertical-align:middle; } .inner p { margin: 0; } 
 <div> <button> <div class="outer"> <div class="inner"> bob <p> bill </p> </div> </div> </button> <button> <div class="outer"> <div class="inner"> bob </div> </div> </button> </div> 

Your HTML is invalid.

button elements cannot contain divs.

 button { height: 100px; vertical-align: top; } 
 <div> <button> <span>bob</br> bill</span> </button> <button> <span>bob</span> </button> </div> 

You can try this. CSS Flex-box

 .add_class{ display: -webkit-flex; display: flex; } button{ height:100px; margin:5px; } 
 <div class="add_class"> <button> <div class="outer"> <div class="inner"> bob <p> bill </p> </div> </div> </button> <button> <div class="outer"> <div class="inner"> bob </div> </div> </button> </div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM