CSS for a calculator I've a small assignment to do: style a given HTML file with CSS.

My result looks exactly as it should. But I'm not really satisfied with my style sheet. I'm sure there are better ways to achieve the same.

The different sizes are not specified. I had just an image as template.

How would a real web design solve this task?

jsFiddle



body &gt; div {
    width: 404px;
    border: 1px solid black;
    padding: 8px;
}

.header {
    margin-bottom: 5px;
}

.header input {
    width: 400px;
    height: 40px;
    border: 1px solid black;
    text-align: right;
}

.numberFields {
    margin: 0;
    width: 360px;
    font-size:0;
    overflow: auto;
    float: left;
}

.numberFields input {
    background-color: green;
    border: 1px solid black;
    width: 120px;
    height: 40px;
}

.numberFields input[name="0"] {
    width: 360px;
}

.operations {
    margin-left: 4px;
    width: 40px;
    font-size: 0;
    display: inline-block;
}

.operations input {
    background-color: purple;
    border: 1px solid black;
    width: 40px;
    height: 40px;
}

.sum {
    margin-top: 5px;
}

.sum input {
    background-color: purple;
    border: 1px solid black;
    width: 404px;
    height: 40px;
}
&lt;body&gt;
    &lt;div&gt;
        &lt;div class="header"&gt;
            &lt;input name="1" value="1" disabled /&gt;
        &lt;/div&gt;
        &lt;div class="numberFields"&gt;
            &lt;input type="button" name="1" value="1" /&gt;
            &lt;input type="button" name="2" value="2" /&gt;
            &lt;input type="button" name="3" value="3" /&gt;
            &lt;input type="button" name="4" value="4" /&gt;
            &lt;input type="button" name="5" value="5" /&gt;
            &lt;input type="button" name="6" value="6" /&gt;
            &lt;input type="button" name="7" value="7" /&gt;
            &lt;input type="button" name="8" value="8" /&gt;
            &lt;input type="button" name="9" value="9" /&gt;
            &lt;input type="button" name="0" value="0" /&gt;
        &lt;/div&gt;
        &lt;div class="operations"&gt;
            &lt;input type="button" name="+" value="+" /&gt;
            &lt;input type="button" name="-" value="-" /&gt;
            &lt;input type="button" name="*" value="*" /&gt;
            &lt;input type="button" name="/" value="/" /&gt;
        &lt;/div&gt;
        &lt;div class="sum"&gt;
            &lt;input type="button" name="=" value="=" /&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/body&gt;
First, your CSS has no errors, which is very good.  You can check for errors at the W3C validator.

Looking through your CSS, it looks very neat, and I would only remove a little bit of unnecessary code.  Also, the display seems to be optimized for IE.  I set it for FireFox and Chrome, and it displays almost correctly in IE.  The trouble is, the box for displaying the output is visibly small in FireFox and Chrome.  With my changes, it is 1 pixel too large in IE, but it is not as noticeable.

First, I would just use the body element here, instead of body &gt; div:

body &gt; div {
    width: 404px;
    border: 1px solid black;
    padding: 8px;
}


Right here, I adding a small padding so the font would have a small amount of space between it and the border:

.header input {
    /* ... */
    padding-right: 2px;
}


I found I could remove the overflow: auto; lines without effecting the display.

In .operations, you don't need to set font-size: 0;.  I do not know why you need to do that to remove the spacing in the .numberFields class, but I was unable to get it working without it.  I do not like that as it is not clear why you need to set the font-size there, and there is probably a cleaner way to do it, but the usual trick of using a negative margin value isn't working, and neither did setting the padding to 0px.

I did not make any other changes; as I said above, your CSS is very clean and neat.