CSS box-sizing border-box still adding border size to element width

0 votes

The following sample exemplifies the issue I'm having.

So, if I have a container with a width of 200 pixels,

In the container, I add a 200px wide row (will add lots of rows)

I'd like to add 200px wide divs to the row (different each row)

Everything works perfectly until I add a 1px solid edge to the.cont div.

Why isn't the.cont boundary taken into account for box-sizing?

*,
*:before,
*:after {
  -webkit-box-sizing: border-box !important;
  -moz-box-sizing: border-box !important;
  -ms-box-sizing: border-box !important;
  box-sizing: border-box !important;
}

.cont {
  position: absolute;
  background-color: white;
  font-size: 12px;
  overflow: hidden;
  border: solid;
  /* Remove this and it works */
  border-color: purple;
  border-width: 1px;
  height: 200px;
  width: 200px;
  margin: 0;
  padding: 0;
}

.h_row {
  display: block;
  width: 100%;
  height: 22px;
  line-height: 22px;
  background-color: red;
  overflow: hidden;
  border-bottom: solid;
  border-bottom-color: orange;
  border-width: 1px;
  margin: 0;
  padding: 0;
}

.cell {
  display: block;
  float: left;
  font-size: 11px;
  height: 20px;
  line-height: 20px;
  text-align: left;
  text-indent: 2px;
  overflow: hidden;
  margin: 0;
  padding: 0;
}

.h_row>.cell {
  font-size: 12px;
  text-align: center;
  height: 22px;
  line-height: 22px;
  border-right: solid;
  border-right-color: pink;
  border-right-width: 1px;
  background-color: green;
}

.h_row>.cell:last-child {
  border-right: none;
}

.w50 {
  width: 50px;
}

.w100 {
  width: 100px;
}
<div class="cont">
  <div class="h_row">
    <div class="cell w100">100</div>
    <div class="cell w50">50</div>
    <div class="cell w50">50</div>
  </div>
</div>
Jun 9 in CSS by Edureka
• 7,940 points
10 views

1 answer to this question.

0 votes
Instead of using a border, you could use a box-shadow but place it inside your box, resulting in a 1px border inside the container.

Another option is to avoid using pixels altogether and instead use percentages for width, such as 50% or 10%.
answered Jun 13 by Edureka
• 8,460 points

Related Questions In CSS

0 votes
0 answers
0 votes
0 answers
0 votes
1 answer

Is there any way to colorize a white PNG image with CSS only?

Filters can be used with -webkit-filter and ...READ MORE

answered May 27 in CSS by Edureka
• 8,460 points
24 views
0 votes
1 answer

How to set Bullet colors in UL/LI html lists via CSS without using any images or span tags

I use jQuery for this: jQuery('li').wrapInner('<span class="li_content" />'); & ...READ MORE

answered May 27 in CSS by Edureka
• 8,460 points
29 views
0 votes
2 answers

Define a SQL query? What is the difference between SELECT and UPDATE Query? How do you use SQL in SAS?

HI.. SQL is Structured Query Language, which is ...READ MORE

answered Aug 8, 2020 in PHP by anonymous
4,469 views
0 votes
1 answer

Using/Handling colon inside a JSF generated HTML element ID in CSS selector

Yes, you can.  Just Backslash (\) the colon.  Like ...READ MORE

answered Nov 14, 2018 in Others by DataKing99
• 8,240 points
1,650 views
0 votes
1 answer

What is a css selector and where is it used?

CSS Selector is a combination of element ...READ MORE

answered Nov 21, 2018 in Data Analytics by Kalgi
• 52,350 points
266 views
0 votes
1 answer

What is the difference between span and div?

The div should be used to wrap sections of ...READ MORE

answered Jan 16, 2020 in Web Development by Niraj

edited Jan 21, 2020 by Niroj 2,243 views
0 votes
1 answer

How to add border in my clip-path: polygon(); CSS style

Using an SVG Dilation Filter to Add ...READ MORE

answered Jun 21 in CSS by Edureka
• 8,460 points
7 views
0 votes
1 answer

CSS to set A4 paper size

I looked into it further, and the ...READ MORE

answered Jun 21 in CSS by Edureka
• 8,460 points
13 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP