0

I looked through example at stack overflow whose problem where similar to mine but without success. I do not know what am I doing that is wrong but the div is not going to horizontally middle well so far it only works for certain resolution screen but if I load it to different screen its not in the middle so i use margin: 0 auto; but still didn't work.

HTML

<div class="margin">
    <div class="BoxContainer">
        <a href="https://medium.com/@sudeep_shahi"><div class="box"><img src="img/medium.png" alt="medium" style="width:100%;height:100%;"></div></a>
        <a href="www.linkedin.com/in/sudeep-shahi-92375010a"><div class="box"><img src="img/linkdin.png" alt="linkdin" style="width:100%;height:100%;"></div></a>
        <a href="https://www.instagram.com/westkinz/?hl=en"><div class="box"><img class="effect" src="img/instagram.png" alt="Itragram" style="width:100%;height:100%;"></div></a>
    </div>          
</div>

CSS

.margin{
    margin-left: auto;
    margin-right:auto;
    margin-bottom: 5px;
    background-color: #EBEBEB;
}
.boxContainer {
    display:inline-block;
    border:thick dotted #060;
    margin: 0px auto 10px auto;
    text-align: left;
    background-color:#EBEBEB;
}
.box {
    width: 300px;
    height: 300px;
    background-color:#EBEBEB;
    display: inline-block;
}

.box :hover{
    border-radius: 50%;
    transform: rotate(360deg);
}
WESTKINz
  • 257
  • 1
  • 6
  • 18

2 Answers2

0

To center a <div> using margin: auto you'll need to set the <div>'s width manually, otherwise the default display: block will take 100% of the available space, and you will not be able to center the element.

Give your .margin class width: 300px and it will be centered.

Narxx
  • 7,929
  • 5
  • 26
  • 34
0

to my understanding you are trying to do something like this

<div class="centered">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>

What you have done wrong is you have text-align set to left in the parent node which is followed by all childrens

.centered{
    text-align: center;
}
.box{
    display: inline-block;
    height:100px;
    width: 100px;
    padding: 3px;
    border: 1px solid black;
}

Hope this is the answer you were looking for

Shubham Srivastava
  • 1,807
  • 1
  • 10
  • 17