How to align text vertically centered together with inline-block elements [duplicate]

StackOverflow https://stackoverflow.com/questions/22988319

  •  01-07-2023
  •  | 
  •  

Pergunta

I have the following code:

JS Fiddle


HTML

<a href="#">
    text
    <ins></ins>
</a>

CSS

a {
    display:inline-block;
    height:50px;
    //vertical-align: middle; (does not change anything...)
}
ins {
    display:inline-block;
    height:50px;
    width:50px;
    background:blue;
}

Now, it looks like this:

enter image description here


But it should look like this:

enter image description here


How can I achieve this desired vertical alignment of the text?

Foi útil?

Solução

Add vertical-align: middle; to ins:

ins {
    display:inline-block;
    height:50px;
    width:50px;
    background:blue;
    vertical-align: middle;
}

JS Fiddle

Outras dicas

Get your text in a <span> and style like that

<a href="#">
    <span>text</span>
    <ins></ins>
</a>

span{
    float:left;
    margin-top:15px;
    margin-right:5px;
}

a {
    display:inline-block;
    height:50px;

}
ins {
    display:inline-block;
    height:50px;
    width:50px;
    background:blue;
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top