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, 2022 in CSS by Edureka
• 12,890 points
416 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, 2022 by Edureka
• 11,450 points

Related Questions In CSS

0 votes
1 answer

I want to create a small square colour filled box in HTML & CSS. And most important - I want to write one line after the box

Try using the square html entity: <div style="color:blue">&a ...READ MORE

answered Jun 28, 2022 in CSS by Edureka
• 11,450 points
1,516 views
0 votes
0 answers

How to make a transparent border using CSS?

Ideally, the border should be translucent. That ...READ MORE

Jul 4, 2022 in CSS by Edureka
• 12,890 points
87 views
0 votes
0 answers

How to do CSS chat messages border radius?

I'm making a list of incoming and ...READ MORE

Jul 8, 2022 in CSS by Edureka
• 12,890 points
232 views
0 votes
0 answers

How to do something like border-top-left-color. [CSS]

Only border-left-color, border-right-color, border-top-color, and border-bottom-color are ...READ MORE

Jul 18, 2022 in CSS by Edureka
• 12,890 points
75 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
5,923 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,876 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
362 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,552 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, 2022 in CSS by Edureka
• 11,450 points
2,461 views
0 votes
1 answer

CSS to set A4 paper size

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

answered Jun 21, 2022 in CSS by Edureka
• 11,450 points
5,511 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP