Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

html - aligning multiple items in center for all devices

I am trying to align the items in the center of the screen horizontally and vertically. However, it doesn't work without specifying width and height so that creates a problem for mobile and desktop view. How do I make it responsive so that it looks to be in the center of the screen in every kind of devices?

.parent-container{
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100vw;
  height: 100vh;
}
<div class="parent-container">
    <button>
    </button>
    <button>
    </button>
    <button>
    </button>
  </div>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can set a min-height. When the content ist larger than the device's height, the .parent-container goes beyond.

.parent-container{
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      width: 100vw;
      min-height: 100vh;
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...