-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
  • 701
  • 1
  • 7
  • 18

3 Answers3

1

Add display flex and align items:

.itemNumber, .itemName {
    display: flex;
    align-items: center;
}
Roberto Zvjerković
  • 8,622
  • 4
  • 23
  • 42
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,065
  • 2
  • 12
  • 28
0

Add the following css code

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