Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Basically I got a div parent that consists of 1+ div child elements (with a button within each one). Now I'd like the buttons to fill the entire width of the parent - but share it. That is, if there's one child button it should fill 100% - if there are 2 they should have a width of 50% of the size each etc.

How can I do this?

Edit: As requested - here's the code (although I think the above explanation is better):

.buttons
{
    background: #f1f1f1;
    border-top: 1px solid #ddd;
    padding: 15px;
    height: 34px;
}

.submitbutton
{
    width: inherit;
    background: #C2E5FC; /* Old browsers */
    background: -moz-linear-gradient(top, #C2E5FC 0%, #008BE8 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#C2E5FC), color-stop(100%,#008BE8)); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top, #C2E5FC 0%,#008BE8 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top, #C2E5FC 0%,#008BE8 100%); /* Opera11.10+ */
    background: -ms-linear-gradient(top, #C2E5FC 0%,#008BE8 100%); /* IE10+ */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#C2E5FC', endColorstr='#008BE8',GradientType=0 ); /* IE6-9 */
    background: linear-gradient(top, #C2E5FC 0%,#008BE8 100%); /* W3C */
    border: 1px solid #008BE8;
    -webkit-border-radius: 20px;
    -moz-border-radius: 20px;
    border-radius: 20px;
    line-height: 20px;
    font-size: 16px;
    padding: 6px 12px;
    color: #fff;
    text-shadow: -1px -1px #008BE8;
    margin-left: 10px;
    cursor: pointer;
}

The html:

<div class="buttons">
    <input class="submitbutton" type="submit" value="Register">
    <input class="submitbutton" type="submit" value="Cancel">
</div>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
184 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can enclose them inside a li and use this css:

.buttons > li {
display: table-cell !important; 
width: 1% !important;
float: none !important;
}

.buttons > li >* {
width:100%
}

See jsfiddle Jsfiddle view


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...