Home > Web Front-end > CSS Tutorial > Code for display: flex attribute in css to implement vertical centering of elements

Code for display: flex attribute in css to implement vertical centering of elements

不言
Release: 2018-08-06 17:00:56
Original
2976 people have browsed it

This article introduces to you the display: flex attribute in CSS to implement the code for vertical centering of elements. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Before this, I used absolute positioning absolute or fixed positioning fixed

How to use flex to vertically center elements, the parent includes the child

<div  class=&#39;itemBox&#39;>
    <div>boxboxboxboxboxboxboxboxboxboxbox</div>
</div>
 
.itemBox{
display: flex;
justify-content: center;
align-items: center;
background: #588cfe;
width: 100%;
height: 100vh;
}
.itemBox p{
background: #ffffff;
width: 200px;
height: 200px;
word-break: break-all;//英文超出盒子不换行问题
}
Copy after login

Recommended related articles:

Code for text-transform attribute in CSS to implement string conversion

Two ways to use tables in CSS (examples)

The above is the detailed content of Code for display: flex attribute in css to implement vertical centering of elements. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template