-1

I have structure:

    .itemWrapper{
        position: relative;
        width: 100%;
        display: inline-block;
        height: 20%;
    }
    .itemNumber{
        position: relative;
        float:left;
        height: 100%;
        width: 20%;
    }
    .itemName{
        height: 100%;
        width: 20%;
        position: relative;
        float:left
    }
    <div class = "itemWrapper">
       <div class = "itemNumber">2</div>
       <div class = "itemName"> name </div<
    </div>

I need to center the text inside .itemNumber and .itemName vertically, how can I do that? I know about line-height trick, however the height of the container is in %, what is the way to do it?

Johnyb
  • 980
  • 1
  • 12
  • 27

3 Answers3

1

Add display flex and align items:

.itemNumber, .itemName {
    display: flex;
    align-items: center;
}
Roberto Zvjerković
  • 9,657
  • 4
  • 26
  • 47
1

You can achieve this using Flex:

.itemWrapper{
    height: 500px;
    width: 100%;
    display: flex;
    background-color: silver;
}
.itemNumber{
    width: 20%;
    align-self: center;
}
.itemName{
   width: 20%;
   align-self: center;
}
Thanveer Shah
  • 3,250
  • 2
  • 15
  • 31
0

Add the following css code

.itemNumber, .itemName {
          display: flex;
          align-items: center;
          justify-content: center
 }