Masood
0
Q:

css flex center

display: flex;
align-items: center;
justify-content: center;
2
/* Answer to: "css flex vertical align" */

.box {
  display: flex;
  align-items: center; /* Vertical */
  justify-content: center; /* Horizontal */
}

.box div {
  width: 100px;
  height: 100px;
}

/*
  For more information go to:
  https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Aligning_Items_in_a_Flex_Container
*/
8
section {
  width: 200px;
  border: 1px solid #2d2d2d;
  display: flex;
  justify-content: center;
}
2
	display: flex;
    width: 60%;
    justify-content: center;
    margin: 0 auto;
0
.primary-nav {
    display:-webkit-flex;
    display:flex;
    list-style-type:none;
    padding:0;
    justify-content:flex-end;
}

.left {
    margin-right:auto;
}
3
.box.flex {
  display: flex;
  justify-content: center;
}
0
align-items: flex-start | flex-end | center | baseline | stretch

.container {
  display: flex;
  align-items: flex-start;
}
2

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Center Flex Item Image</title>
<style>
.box {
   width:80%;
   min-height:80vh;
   margin:auto;
   border:1px solid;
   display: flex;
   align-items: center;
   justify-content: center; /* not really needed with auto margin on img*/
}
.box img {
   display: block;
   width: 80%;
   min-width:100px;
   max-width: 350px; /*actual image width*/
   height: auto; /* maintain aspect ratio*/
   margin: auto; /*optional centering of image*/
}
</style>

</head>
<body>

<div class="box">
   <img src="http://via.placeholder.com/350x250" width="350" height="250" alt="missing image">
</div>

</body>
</html>
0

New to Communities?

Join the community