Search code examples
cssflexboxstyles

box with a title bar completely flushed to the top


I need to create a box with contents inside it. I tried creating the box this way, but it is not quiet what I need:

.main-box {
    border-radius: 25px;
    border: 2px solid #000;
    padding: 20px;
    width: 70%;
    margin-left: 20%;
}

.box-title {
    background-color: #5b5b39;
    padding: 5px;
    color: #fff;
    font-weight: bold;
}

.box-content {
    padding-left: 10px;
    padding-right: 10px;
}

this is how it looks with the above style sheet:

enter image description here

I am asked to create something like this:

enter image description here

I don't want any space between the border and title and the title bar should completely flush the top of the box.


Solution

  • .box {
      border: 1px solid black;
      border-radius: 10px;
    }
    
    .header-wrapper {
      border: 1px solid black;
      background-color: lightblue;
      border-radius: 10px 10px 0 0;
      padding-left: 10px;
    }
    <div class="box">
      <div class="header-wrapper">
        <h2>Order Details</h2>
      </div>
      <div class="content">
        <ul>
          <li>item a</li>
          <li>item a</li>
          <li>item a</li>
        </ul>
      </div>
    </div>