How to align icon to the left and text to the center by using flex?

Jin Ho Bryan Lee

I know flex is very useful these days and I'm also a fan of using flex.

For my project, I'm trying to align icon to the left and text to the center by using flex but it's not working.

How to align center for the text when putting icon to the left?

.window-recommendation {
  background-color: #262931;
  width:100%;
  height:100vh;
  overflow:auto;
  position:relative;
  transform:translateX(0);
  transition:all 0.3s;
}


.top-recommendation {
  display: flex;
  height:50px;
  align-items: center;
  justify-content: space-between;
}

.top-artist {
  background-color: #FFF;

}
 <!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Omnibag Project</title>
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
  <link href="assets/css/style.css" rel="stylesheet">
  <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
</head>
<body>
<div class="window-recommendation">
  <div class="top-recommendation top-artist">
          <i class="material-icons main-left-arrow-artist">keyboard_arrow_left</i>
          <div class="grid-item-artist">Profile</div>
  </div>
        
</div>

heyitsjhu

I don't think you can do it easily with flex-box. You can, however, position the element in the center.

#text {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

Where #text is the element with the word 'Profile'. You change the id or use a class name, if you want.

.window-recommendation {
  background-color: #262931;
  width:100%;
  height:100vh;
  overflow:auto;
  position:relative;
  transform:translateX(0);
  transition:all 0.3s;
}


.top-recommendation {
  display: flex;
  height:50px;
  align-items: center;
  justify-content: space-between;
}

.top-artist {
  background-color: #FFF;

}

#text {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}
 <!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Omnibag Project</title>
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
  <link href="assets/css/style.css" rel="stylesheet">
  <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
</head>
<body>
<div class="window-recommendation">
  <div class="top-recommendation top-artist">
          <i class="material-icons main-left-arrow-artist">keyboard_arrow_left</i>
          <div class="grid-item-artist" id="text">Profile</div>
  </div>
        
</div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Align icon to left and text to center in react native

From Dev

How to align left, in center the text?

From Java

How to center a flex container but left-align flex items

From Dev

Qt: Align Text Center and Left using StyleSheet

From Dev

Qt: Align Text Center and Left using StyleSheet

From Dev

How to align icon to the left with text to the right?

From Dev

How can align text in a center in left position?

From Dev

How to get text align center with block but align left?

From Dev

CSS flex - Align items to left, and container to center

From Dev

How to align text in center using jspdf

From Dev

How to make Icon and Text align Left side on JButton

From Dev

CSS: How to align text to the center of the image (left side)

From Dev

How to center text in the div horizontally with an image at left with vertical align middle

From Dev

<td> center body of text but text left align

From Dev

Using flex align-items center to vertically center text inside div

From Dev

Center align text inside a element in a flex row

From Dev

how to align text to the left?

From Dev

how to align text to the left?

From Dev

Center an icon and text with flex-box

From Dev

Align icon vertically to the center of the first line of text

From Dev

FPDF align text LEFT, Center and Right

From Dev

Center text and have icon aligned left

From Dev

Center text and have icon aligned left

From Dev

Flex item should align left, not center, when it wraps

From Dev

Vertically center and left-align a column of flex items

From Dev

Align text and icon-font icon in span at center of parent div

From Dev

How to align the items to the start and center the flex container?

From Dev

How to center align Alert.show() in flex

From Dev

How to center align a grid of divs in a flex container?

Related Related

  1. 1

    Align icon to left and text to center in react native

  2. 2

    How to align left, in center the text?

  3. 3

    How to center a flex container but left-align flex items

  4. 4

    Qt: Align Text Center and Left using StyleSheet

  5. 5

    Qt: Align Text Center and Left using StyleSheet

  6. 6

    How to align icon to the left with text to the right?

  7. 7

    How can align text in a center in left position?

  8. 8

    How to get text align center with block but align left?

  9. 9

    CSS flex - Align items to left, and container to center

  10. 10

    How to align text in center using jspdf

  11. 11

    How to make Icon and Text align Left side on JButton

  12. 12

    CSS: How to align text to the center of the image (left side)

  13. 13

    How to center text in the div horizontally with an image at left with vertical align middle

  14. 14

    <td> center body of text but text left align

  15. 15

    Using flex align-items center to vertically center text inside div

  16. 16

    Center align text inside a element in a flex row

  17. 17

    how to align text to the left?

  18. 18

    how to align text to the left?

  19. 19

    Center an icon and text with flex-box

  20. 20

    Align icon vertically to the center of the first line of text

  21. 21

    FPDF align text LEFT, Center and Right

  22. 22

    Center text and have icon aligned left

  23. 23

    Center text and have icon aligned left

  24. 24

    Flex item should align left, not center, when it wraps

  25. 25

    Vertically center and left-align a column of flex items

  26. 26

    Align text and icon-font icon in span at center of parent div

  27. 27

    How to align the items to the start and center the flex container?

  28. 28

    How to center align Alert.show() in flex

  29. 29

    How to center align a grid of divs in a flex container?

HotTag

Archive