2

a {
    display: block;
    padding: 0 10px;
    /* background: rgba(0,0,0,0.5); */
    height: 100%;
    border-left: 1px solid rgba(0,0,0,0.1);
    text-decoration: none;
    color: white;
    background-color:rgba(0,0,0,0.5);
    height:100px;
}

img {
    max-height: 72px;
    max-width: 598;
    margin: 0;
    padding: 0;
        vertical-align: middle;
            width: 40px;
    height: 40px;
        border-radius: 50%;

}

.img_frame {
    display: inline-block;
    vertical-align: middle;
    height: 100%;
        background-color: black;

}
<a href="">
  <span class="img_frame"></span>
  <img class="size-40X40 img-round" src="https://yt3.ggpht.com/-zvxnrUIYjg8/AAAAAAAAAAI/AAAAAAAAAAA/vnVVaPAvxOE/s900-c-k-no-mo-rj-c0xffffff/photo.jpg">  
</a>

If I am removing span tag, image is not coming to center, and if I replace span with any other tag like p tag, then also same problem...

Please explain about these properties... Thanks in advance

SimpleBeat
  • 731
  • 1
  • 10
  • 20
Abhishek
  • 339
  • 3
  • 15

2 Answers2

2

vertical-align on inline / inline-block element, images, text... align element together, not with parent.,
You can use flexbox for this, check updated snippet below..

a{
    display: block;
    padding: 0 10px;
    /* background: rgba(0,0,0,0.5); */
    height: 100%;
    border-left: 1px solid rgba(0,0,0,0.1);
    text-decoration: none;
    color: white;
    background-color:rgba(0,0,0,0.5);
    height:100px;
    display: flex;
    align-items: center;
}
img{
    max-height: 72px;
    max-width: 598;
    margin: 0;
    padding: 0;
        vertical-align: middle;
            width: 40px;
    height: 40px;
        border-radius: 50%;

}

.img_frame {
    display: inline-block;
    vertical-align: middle;
    height: 100%;
        background-color: black;

}
<a href="">
  
  <img class="size-40X40 img-round" src="https://yt3.ggpht.com/-zvxnrUIYjg8/AAAAAAAAAAI/AAAAAAAAAAA/vnVVaPAvxOE/s900-c-k-no-mo-rj-c0xffffff/photo.jpg">  
</a>
Super User
  • 8,642
  • 3
  • 24
  • 43
1

The vertical-align property in CSS controls how elements set next to each other on a line are lined up. In order for this to work, the elements need to be set along a baseline. As in, inline (e.g. , ) or inline-block (e.g. as set by the display property) elements.

Read More :https://css-tricks.com/almanac/properties/v/vertical-align/

In simple terms ,vertical-align property Specifies how be position inline(or inline-block) Elements relation to each other.

you have one image and need a other element like span with height: 100%;. Span element have role a Helper.

span {vertical-align: middle;} and img {vertical-align: middle;} say : Center both elements must be on the same line.

a {
    display: block;
    padding: 0 10px;
    /* background: rgba(0,0,0,0.5); */
    height: 100%;
    border-left: 1px solid rgba(0,0,0,0.1);
    text-decoration: none;
    color: white;
    background-color:rgba(0,0,0,0.5);
    height:100px;
}

img {

    max-height: 72px;
    max-width: 598;
    margin: 0;
    padding: 0;
    vertical-align: middle;
    width: 40px;
    height: 40px;
    border-radius: 50%;

}

.helper {

    display: inline-block;
    height: 100%;
    vertical-align: middle;
}
<a href="#">

    <span class="helper"></span>
    
    <img class="size-40X40 img-round" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRSJoLHGrCss93oyQO7wXQr02WZbL83EiJFxza5pe-gN3o_jaK7jw">
    
</a>
Ehsan
  • 11,709
  • 3
  • 20
  • 40