for example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
padding: 0;
}
ul{
width: 400px;
height: 300px;
background-color: #ccc;
}
ul>li{
width: 100px;
height: 100px;
background-color: red;
list-style: none;
}
</style>
</head>
<body>
<ul>
<li></li>
</ul>
</body>
</html>
results as shown in the figure below,
method:
makes ul relatively positioned and li absolutely positioned, in two ways
ul{
position: relative;
}
ul>li{
position: absolute;
/*1*/
margin: auto;
top: 0;
right: 0;
bottom: 0;
left: 0;
/*2、 或者直接使用如下top和left */
top:100px;/*父元素高度减子元素的高度的一半*/
left: 150px;/*父元素宽度减子元素的宽度的一半*/
}
results as shown below
Set ul display:flex
ul{
display: flex;
justify-content: center;
align-items: center;
}
div>
Read More:
- CSS: several ways to center the box vertically and horizontally
- Several ways to center elements horizontally and vertically
- How to center your HTML button itself? ——Use the align attribute of center or Div
- Invalidation of margin top property of nested box in CSS style box
- How to use JavaScript in HTML
- How to restrict input field to only input pure numbers in HTML
- Latex: How to Set text Center
- Three methods of how to remove the flashback of running result box in VS
- How to use dangerously set inner HTML in react
- Box mount Cody_ How to listen to Pandora in Cody
- Three solutions to flash back of program running result box under vs
- Vscode HTML file auto supplement HTML skeleton failure
- Introduction to total phase data center
- 11. Center text
- The solution to frequently pop up “cannot find a valid baseurl for repo” error prompt box in CentOS 6.7
- To solve the problem of failed to load: data in HTML5 game running rmmv locally/ actors.json problem
- Error debug in box2d createfixture Error:R6025 pure Virtual function call solution
- The problem of black box flash away in vs2019 debugging
- Error in pyinstall package Python program: jinja2.exceptions.templatenotfound: Chart_ Solution to component.html
- Has HTML webpack plugin been installed, or error: cannot find module ‘HTML webpack plugin’