1

I've managed to get the #feature_container to grow to the remaining space of #header but I don't want the feature boxes to also grow (in pink), how can I stop the feature box from stretching as well? My aim is to have the 3 feature boxes sitting in the middle but I want to still be able to control the size of the feature boxes and just keep them in the middle of the remaining space.

Here is an example of what I am trying to do: enter image description here

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  width: 100%;
  margin: 0;
}

#header {
  height: 100vh;
  height: 100%;
  background-color: grey;
}

#fixed_div {
  display: inline-block;
}

#feature_header_container {
  display: flex;
  height: 100%;
  background-color: red;
}

#feature_container {
  display: inline-flex;
  flex-grow: 1;
  justify-content: center;
  background-color: blue;
  color: white;
}

.feature_box {
  display: inline-flex;
  background-color: pink;
}
<div id="header">

  <div id="fixed_div">
    <p>Hello World!</p>
  </div>

  <div id="feature_header_container">

    <div id="feature_container">

      <div class="feature_box">
        <p>Test</p>
      </div>

      <div class="feature_box">
        <p>Test</p>
      </div>

      <div class="feature_box">
        <p>Test</p>
      </div>

    </div>

  </div>

</div>
Erdss4
  • 1,025
  • 3
  • 11
  • 31
  • please add a representation of your expected output. I can see feature-boxes are already `in the middle of the remaining space`. – Sudipto Roy Mar 24 '20 at 14:27
  • Also clarify whether you mean vertical space or horizontal space or both – wlh Mar 24 '20 at 14:29
  • 2
    Add `align-items: center` to your container. A default setting on flex containers is `align-items: stretch`. https://jsfiddle.net/afeLtsnd/ – Michael Benjamin Mar 24 '20 at 14:51

2 Answers2

1

Please find the answer here. You can use the below style to #feature_header_container .And i have added the padding and margin separate the each items. If you don't want that, you can remove them.

  .feature_box {
    background-color: #C71585;
    height: 10%;
    width: 10%;
    text-align: center;
    padding:10px;
    margin:10px;
  }

code

* {
        box-sizing: border-box;
      }

      html,
      body {
        height: 100%;
        width: 100%;
        margin: 0;
      }

      #header {
        height: 100vh;
        height: 100%;
        background-color: grey;
      }

      #fixed_div {
        display: inline-block;
      }

      #feature_header_container {
        display: flex;
        height: 100%;
        align-items: center;
        background-color: #006effc5;
      }

      #feature_container {
        display: inline-flex;
        flex-grow: 1;
        justify-content: center;
        color: white;
      }

      .feature_box {
        background-color: #C71585;
        height: 10%;
        width: 10%;
        text-align: center;
        padding:10px;
        margin:10px;
      }
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
   
  </head>
  <body>
    <div id="header">
      <div id="fixed_div">
        <p>Hello World!</p>
      </div>

      <div id="feature_header_container">
        <div id="feature_container">
          <div class="feature_box">
            <p>Test</p>
          </div>

          <div class="feature_box">
            <p>Test</p>
          </div>

          <div class="feature_box">
            <p>Test</p>
          </div>
        </div>
      </div>
    </div>
  </body>
</html>
teddcp
  • 1,514
  • 2
  • 11
  • 25
1
#feature_container {
...
align-items: center;
...
}

.feature_box {
...
height: 50px;
...
}
Syxs
  • 158
  • 6