html - css button : button horizontal align and size stretch with text size -


i'm trying make button left enter image description here, middle enter image description here (repeating) , right enter image description here background:

<div class="horizontal">     <div class="mybutton">         <div class="left" ></div>         <div class="middle" >             text         </div>         <div class="right" ></div>     </div> </div> 

my css following:

.horizontal {       width: 100%;   }  .mybutton {     width: 120px;      height: 30px; }  .left {     background-image: url("http://i.stack.imgur.com/r5gpp.png");     /*border: 1px solid red;*/     float: left;     height: 30px;     width: 4px; }  .middle {     background-image: url("http://i.stack.imgur.com/yxpke.png");    /* border: 1px solid yellow;*/     float: left;     height: 30px;     padding-left: 5px;     padding-right: 5px;     text-align: center;     width: 100px; }  .right {     background-image: url("http://i.stack.imgur.com/oaple.png");     /*border: 1px solid green;*/     float: left;     height: 30px;     width: 4px; } 

now need is:

  • mybutton aligned in middle of horizontal block (the page).

enter image description here

  • and middle stretched text fit (without manually setting width 120px in example).

enter image description here

i have no clue how this.

here's fiddle : http://jsfiddle.net/kcbpw/3/ ,

thank much.

here's updated fiddle: http://jsfiddle.net/stevenschobert/fndrt/

to fix text-wrapping & vertical centering in .middle class, add line-height:30px , min-width:50px;

.middle {     min-width: 50px;     line-height:30px;     /* rest of styles ... */ } 

for horizontal alignment, can add text-align:center; .horizontal class , margin:auto; .mybutton.

.horizontal {     width: 100%;     text-align:center; }  .mybutton {     margin:auto auto;     /* cont... */ } 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -