gpt4 book ai didi

javascript - 居中 CSS 框(Html 和 Css)

转载 作者:太空狗 更新时间:2023-10-29 16:40:57 26 4
gpt4 key购买 nike

我试图将这些框水平和垂直居中放置在屏幕中间。另一个问题是,当我缩放页面时,如何让它自动调整大小?

/*-------------------------
Simple reset
--------------------------*/


*{
margin:0;
padding:0;
}


/*-------------------------
General Styles
--------------------------*/


/*----------------------------
Color Themes
-----------------------------*/
.nav-colors{
position: relative;
background: white;
height: 200px;
width: 60%;
margin: 0 auto;
padding: 20px;
overflow: auto;
}

.home-link{
background-color:#00c08b;
width: 15%;
height: 80px;
display: inline-block;
margin-left: 10%;
}
.portfolio-link{
background-color:#ea5080;
width: 15%;
height: 80px;
display: inline-block;

}
.social-link{
background-color:#53bfe2;
width: 15%;
height: 80px;
display: inline-block;

}
.contact-link{
background-color:#f8c54d;
width: 15%;
height: 80px;
display: inline-block;

}
.blog-link{
background-color:#df6dc2;
width: 15%;
height: 80px;
display: inline-block;

}
<!DOCTYPE html>
<html>
<head>
<title>Neiko Anglin | Front-End Develper </title>

<!-- Our CSS stylesheet file -->
<link rel="stylesheet" href="css/styles.css" />

<!-- Font Awesome Stylesheet -->
<link rel="stylesheet" href="font-awesome/css/font-awesome.css" />


</head>

<body>
<div class="nav-colors">
<div class="home-link">
</div>
<div class="portfolio-link">
</div>
<div class="social-link">
</div>
<div class="contact-link">
</div>
<div class="blog-link">
</div>

</div>
</body>
</html>

最佳答案

您可以在容器上使用绝对定位来垂直和水平居中:

/*-------------------------
Simple reset
--------------------------*/
* {
margin:0;
padding:0;
}
/*-------------------------
General Styles
--------------------------*/

/*----------------------------
Color Themes
-----------------------------*/
.nav-colors {
position: absolute;
background: white;
height: 84px;
width: 60%;
margin: auto;
padding: 20px;
overflow: auto;
top:0;
right:0;
bottom:0;
left:0;
}
.home-link {
background-color:#00c08b;
width: 15%;
height: 80px;
display: inline-block;
margin-left: 10%;
}
.portfolio-link {
background-color:#ea5080;
width: 15%;
height: 80px;
display: inline-block;
}
.social-link {
background-color:#53bfe2;
width: 15%;
height: 80px;
display: inline-block;
}
.contact-link {
background-color:#f8c54d;
width: 15%;
height: 80px;
display: inline-block;
}
.blog-link {
background-color:#df6dc2;
width: 15%;
height: 80px;
display: inline-block;
}
<div class="nav-colors">
<div class="home-link"></div>
<div class="portfolio-link"></div>
<div class="social-link"></div>
<div class="contact-link"></div>
<div class="blog-link"></div>
</div>

关于javascript - 居中 CSS 框(Html 和 Css),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27511195/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com