AazibCh AazibCh - 4 months ago 9
CSS Question

Why is the size of the <td>s changing when border is added inside it using the box-sizing property?

I'm using the

JQuery method to add
whenever it is clicked.
contains a border and the
property set to

When I click two consecutive
s either horizontally or vertically, their size seems to change. Why is it so?

Here's my code:

<!-- page.html -->

<!DOCTYPE html>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script type="text/javascript" src="script.js"></script>

/* stylesheet.css */

td {
height: 100px;
width: 100px;
background-color: red;

.clicked {
border: 5px solid green;
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;

// script.js

$(document).ready(function () {
$("td").click( function() {

Help shall be appreciated.


Padding (which isn't counted by box-sizing: border-box is messing things up. Your td's have a padding of 1px if you set this to 0 then the weird behaviour goes away.