Search code examples
csslayoutfixed

How to have a fixed and % elements alongside one another in a line


I want a container to be filled in a single line in the following way:

  • 60px fixed yellow

And then of the remaining space:

  • 20% blue
  • 60% black
  • 20% red

This is what I have so far (doesn't work):

CSS

body {
    background-color: #fff;
    padding: 0px;
    margin:100px;
}

.container {
    overflow: hidden;
    padding: 0px;
    margin: 0px auto;
    width: 90%;
    background-color: white;
    border-radius: 10px;
    box-shadow: 0px 0px 6px 0px #ccc;
}

.blue_container {
    background-color: blue;
    width: 20%;
    float:left;
}

.black_container {
    width:60%;
    float:left;
    background-color: black;
}

.red_container {
    width: 20%;
    float:left;
    background-color: red;

}

.fixed_conatiner {
    float:left;
    background-color: yellow;
    width: 60px;
}

.transparent_container[type="fixed"] {
    padding:0px;
    margin:0px;
    width: 60px;

}

.transparent_container[type="avazmishe"] {
    padding:0px;
    margin:0px;
}

HTML

<div class="container">
    <div class="transparent_container" type="fixed">
        <div class="fixed_container"><br/></div>
    </div>
    <div class="transparent_container" type="resizable">
        <div class="blue_container"><br/></div>
        <div class="black_container"><br/></div>
        <div class="red_container"><br/></div>
    </div>
</div>

Solution

  • You were on the right track, all you have to do is subtract that fixed containers width from your fluid container with a left margin. Try this:

    .transparent_container {
        margin-left: 60px;
    }