How to prevent the border from affecting child elements

1

How can I add border to a img correctly because I'm adding the border in img and it seems to be bigger than the others. I'm adding by click using jquery when I click on the% frame with it with a green border of 2px as I do so it does not happen to add the border and the img does not increase?

$('input[type=checkbox]').on('change', function () {
    var total = $('input[type=checkbox]:checked').length;
   	$("#count").text("Fotos selecionadas: " + total);
   	$(this).closest('.hovereffect').toggleClass('clic');
});
.hovereffect {
    width:100%;
    height:100%;
    float:left;
    overflow:hidden;
    position:relative;
    margin-bottom: 25px;
    text-align:center;
    cursor:default;
    box-shadow: 0px 0px 5px 1px rgba(0,0,0,.2);
}

.hovereffect .overlay {
    width:100%;
    height:100%;
    position:absolute;
    overflow:hidden;
    top:0;
    padding: 15px;
    left:0;
    opacity:0;
    background-color:rgba(0,0,0,0.5);
    -webkit-transition:all .4s ease-in-out;
    transition:all .4s ease-in-out
}

.hovereffect img {
    display:block;
    position:relative;
    -webkit-transition:all .4s linear;
    transition:all .4s linear;
}

.hovereffect h2 {
    /*text-transform:uppercase;*/
    color:#fff;
    text-align:center;
    position:relative;
    font-size:22px;
    /*background:rgba(0,0,0,0.6);*/
    -webkit-transform:translatey(-100px);
    -ms-transform:translatey(-100px);
    transform:translatey(-100px);
    -webkit-transition:all .2s ease-in-out;
    transition:all .2s ease-in-out;
    padding:10px;
}

.hovereffect a.info {
    text-decoration:none;
    display:inline-block;
    text-transform:uppercase;
    color:#fff;
    /*border:1px solid #fff;*/
    background-color:transparent;
    opacity:0;
    filter:alpha(opacity=0);
    -webkit-transition:all .2s ease-in-out;
    transition:all .2s ease-in-out;
    margin:0 0 0;
    padding:7px 14px;
}

.hovereffect a.info:hover {
/*box-shadow:0 0 5px #fff;*/
}

.hovereffect:hover img {
    -ms-transform:scale(1.2);
    -webkit-transform:scale(1.2);
    transform:scale(1.2);
}

.hovereffect:hover .overlay {
    opacity:1;
    filter:alpha(opacity=100);
}

.hovereffect:hover h2,.hovereffect:hover a.info {
    opacity:1;
    filter:alpha(opacity=100);
    -ms-transform:translatey(0);
    -webkit-transform:translatey(0);
    transform:translatey(0);
}

.hovereffect:hover a.info {
    -webkit-transition-delay:.2s;
    transition-delay:.2s;
}

.col-lg-3{
    width: 30%;
}

.bloco{
    background-color: rgba(0,0,0,0.67);
    width: 100%;
    height: 100%;
    opacity: 0;
    position: absolute;
    padding: 17px;
    top: 0;
    -webkit-transition: all .4s ease-out;
}

h2{
    font-family: 'Courgette', cursive;
}

.corr{
    background-color: #2ecc71;
    width: 40px;
    height: 40px;
    border-radius: 30px;
    position: absolute;
    padding: 10px;
    margin-top: -10px;
    /* margin: 0 auto; */
    left: 0;
    /* top: 50%; */
}

.btn-group, .btn-group-vertical{
    position: absolute;
    top: 50px;
    left: 50%;
    margin-left: -43px;
}

.clic{
    border: 3px solid #1abc9c;
}
#count{
    font-family: 'Courgette', cursive;
}
.sweet-alert{
    border-radius: 0px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script><linkhref="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>

<div class="container">
    <div class="row">
        <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12">
            <div class="hovereffect">
                <img class="img-responsive" src="http://guanambiacontece.com/wp-content/uploads/2016/01/iron-man-rep-300x200.jpg"><divclass="overlay">
                    <div class="pad">
                        <h2></h2>
                        <div class="btn-group" data-toggle="buttons">
                            <label class="check btn btn-primary">
                                <input type="checkbox" name="ck[]">Selecionar</label>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

link

    
asked by anonymous 11.02.2016 / 19:19

3 answers

1

The effect is exactly the same, either with box-sizing: border-box; or not, because it is not the image that received the border but a parent element and this affects the image.

The solution is to not use border, maybe use box-shadow solve (in case the image was over in the test, I'll update the answer later and put an example with box-shadow) or else you can create one more element put position:absolute on it also, remove this:

And then add this:

.border-overlay {
    position: absolute;
    z-index: 9999;
    border: 3px solid #1abc9c;
    opacity: 0;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    transition: opacity .4s ease-out;
}
.clic .border-overlay {
  opacity: 1;
  display: block;
}

And the html should look like this:

<div class="container">
    <div class="row">
        <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12">
            <div class="hovereffect">
                <img class="img-responsive" src="http://guanambiacontece.com/wp-content/uploads/2016/01/iron-man-rep-300x200.jpg"><divclass="border-overlay"></div>
                <div class="overlay">
                    <div class="pad">
                        <h2></h2>
                        <div class="btn-group" data-toggle="buttons">
                            <label class="check btn btn-primary">
                                <input type="checkbox" name="ck[]">Selecionar</label>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
  

NOTE: change all -webkit-transition: to transition: only, as this will work on browsers like Firefox (if you want compatibility for older browsers keep both -webkit-transition and transition / p>

    
11.02.2016 / 20:54
3

Use box-sizing with property border-box

So the border will stay inside and not out.

div {
        box-sizing: border-box;
        -moz-box-sizing: border-box;
        -webkit-box-sizing: border-box;
        width: 100px;
        height: 100px;
        border: 20px solid #f00;
        background: #00f;
        margin: 10px;
    }

div + div {
border: 10px solid red;
}
<div>Olá</div>
<div>Olá</div>
    
11.02.2016 / 19:27
2

This is because the border is added out by default.

To resolve, set the attribute box-sizing

This will bring the border into the element.

.out, .in {

    width: 200px;
    height: 200px;
    border: 10px solid #ff0000;
    margin: 0px;
    padding: 0px;
}
.in {
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
}
<div class="in">border in</div>
<div class="out">border out</div>
    
11.02.2016 / 19:30