2

How can I have width:50% with panel-default, but including padding or margin (not sure which one is more appropriate) in the calculation, so that the panel-default perfectly fills 100% of the width?

SS

Code

.testing-here {
  padding: 2.5px;
  display: inline;
  box-sizing: border-box;
}
body {
  box-sizing: border-box;
}
.panel-default {
  box-sizing: border-box;
  border-style: none;
  position: relative;
  width: 50%;
  padding-bottom: 40%;
  /* = width for a 1:1 aspect ratio */
  overflow: hidden;
  background-color: #446CB3;
  border-radius: 0px;
  display: inline-block;
}
.panel-body {
  color: white;
  position: absolute;
}
<div class="testing-here">
  <div class="panel panel-default">
    <div class="panel-body">
      Basic panel example
    </div>
  </div>
</div>

UPDATE:

Right now if I set the width to 50% all the panels dropdown vertically because they can't fit side by side.

enter image description here

dippas
  • 58,591
  • 15
  • 114
  • 126
AnthonyGalli.com
  • 2,796
  • 5
  • 31
  • 80

2 Answers2

3

you need to :

  • add box-sizing:border-box to the *,*:before,*:after
  • fix inline-block gap , you can do that by reset parents font, font-size:0
  • remove display:inline from .testing-here
  • add border to .panel-default

*,
*:before,
*:after {
  box-sizing: border-box;
}
body {
  margin: 0
}
.testing-here {
  padding: 2.5px;
  font-size: 0
}
.panel-default {
  box-sizing: border-box;
  border-style: none;
  position: relative;
  width: 50%;
  padding-bottom: 40%;
  /* = width for a 1:1 aspect ratio */
  overflow: hidden;
  background-color: #446CB3;
  border-radius: 0;
  display: inline-block;
  font-size: 16px;
  border: 5px white solid
}
.panel-body {
  color: white;
  position: absolute;
}
<div class="testing-here">
  <div class="panel panel-default">
    <div class="panel-body">
      Basic panel example
    </div>
  </div>
  <div class="panel panel-default">
    <div class="panel-body">
      Basic panel example
    </div>
  </div>
  <div class="panel panel-default">
    <div class="panel-body">
      Basic panel example
    </div>
  </div>
  <div class="panel panel-default">
    <div class="panel-body">
      Basic panel example
    </div>
  </div>
</div>
dippas
  • 58,591
  • 15
  • 114
  • 126
2

add box-sizing: border-box; to the element

Johannes
  • 64,305
  • 18
  • 73
  • 130