gpt4 book ai didi

html - 空间和中心框

转载 作者:行者123 更新时间:2023-11-28 00:41:45 25 4
gpt4 key购买 nike

嘿,我如何将它们放在中心并在它们之间留出更多空间?我在网上找不到任何东西,我看了很多。如果你愿意,那么你也可以优化它,因为我的标题和框之间也没有空间

这是我的 HTML:

    <!DOCTYPE html>
<html>
<head>

<meta charset="UTF-8">
<meta name="description" content="Still developing">
<link rel="stylesheet" type="text/css" href="css/main.css">
<meta name="theme-color" content="#5b0c0c" />
<!-- Titlen -->
<title>Preview</title>

</head>
<body>
<!-- navbar -->
<ul>
<li><a class="active" href="#home">Home</a></li>
<li><a href="#news">News</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#">About</a></li>
</ul>

<!-- under navbar-->
<div class="header">

<div id="container">
<div id="context">
<!--<div id="header-image"> -->
</div>
</div>
</div>
<br>
<br>
<br>

<section id="textbox">
<div>Text box 1</div>
<div>Text box 2</div>
<div>Text box 3</div>
</section>

<!-- footer -->
<div class="footer">
<p>Copyrights reserved to &copy realmymonsterdk| Contact information: <a href="mymonsterdk@gmail.com">
mymonsterdk@gmail.com</a>.</p>
</div>
</body>
</html>


<!DOCTYPE html>
<html>
<head>

<meta charset="UTF-8">
<meta name="description" content="Still developing">
<link rel="stylesheet" type="text/css" href="css/main.css">
<meta name="theme-color" content="#5b0c0c" />
<!-- Titlen -->
<title>Preview</title>

</head>
<body>
<!-- navbar -->
<ul>
<li><a class="active" href="#home">Home</a></li>
<li><a href="#news">News</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#">About</a></li>
</ul>

<!-- under navbar-->
<div class="header">

<div id="container">
<div id="context">
<!--<div id="header-image"> -->
</div>
</div>
</div>
<br>
<br>
<br>

<section id="textbox">
<div>Text box 1</div>
<div>Text box 2</div>
<div>Text box 3</div>
</section>

<!-- footer -->
<div class="footer">
<p>Copyrights reserved to &copy realmymonsterdk| Contact information: <a href="mymonsterdk@gmail.com">
mymonsterdk@gmail.com</a>.</p>
</div>
</body>
</html>

这是我当前的 CSS:

        html, body {
width: 100%;
margin: 0;
}
body {
font-family: "Lato", sans-serif;
background-color: #353535;

}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover:not(.active) {
background-color: #931010;
}
.active {
background-color: #931010;
}
.header{
width: 100%;
height: 550px;
background-image: url("https://static-cdn.jtvnw.net/jtv_user_pictures/b76051a5-b2e6-4fbb-b53d-f41f62410905-profile_banner-480.png");
background-repeat: no-repeat;
background-size: cover;
}
.footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
color: white;
text-align: center;
}

#textbox {
white-space: nowrap;
align-items: center;
}

#textbox div {
display: inline-block;
width: 250px;
height: 250px;
margin: auto;
background: red;
overflow: hidden;
}


#container {
color: white;
width: 400px;
height: 260px;
}

#context {
width: 250px;
margin-left: auto;
margin-right: -700px;
position: relative;
top: 60%;
transform: translateY(10%);
}

#white {
color: white;
}

#header-image {
color: white;
background-image: url("https://static-cdn.jtvnw.net/jtv_user_pictures/b76051a5-b2e6-4fbb-b53d-f41f62410905-profile_banner-480.png");
width: 750px;
height: 260px;
position: relative;
top: 30%;
transform: translateY(10%);

}

最佳答案

为了使其居中,我在 div 的 CSS 中使用了 text-align: center;。为了在框之间留出空间,我在 CSS 中使用了 border: 30px solid #353535; 使边框与背景颜色相同。这是最终代码:

     html, body {
width: 100%;
margin: 0;
}
body {
font-family: "Lato", sans-serif;
background-color: #353535;

}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover:not(.active) {
background-color: #931010;
}
.active {
background-color: #931010;
}
.header{
width: 100%;
height: 550px;
background-image: url("https://static-cdn.jtvnw.net/jtv_user_pictures/b76051a5-b2e6-4fbb-b53d-f41f62410905-profile_banner-480.png");
background-repeat: no-repeat;
background-size: cover;
}
.footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
color: white;
text-align: center;
}

#textbox {
white-space: nowrap;
align-items: center;
text-align: center;
}

#textbox div {
display: inline-block;
width: 250px;
height: 250px;
margin: auto;
background: red;
overflow: hidden;
}


#container {
color: white;
width: 400px;
height: 260px;
}

#context {
width: 250px;
margin-left: auto;
margin-right: -700px;
position: relative;
top: 60%;
transform: translateY(10%);
}

#white {
color: white;
}

#header-image {
color: white;
background-image: url("https://static-cdn.jtvnw.net/jtv_user_pictures/b76051a5-b2e6-4fbb-b53d-f41f62410905-profile_banner-480.png");
width: 750px;
height: 260px;
position: relative;
top: 30%;
transform: translateY(10%);

}
#box {
border: 30px solid #353535;
text-align: left;
}
<!DOCTYPE html>
<html>
<head>

<meta charset="UTF-8">
<meta name="description" content="Still developing">
<link rel="stylesheet" type="text/css" href="css/main.css">
<meta name="theme-color" content="#5b0c0c" />
<!-- Titlen -->
<title>Preview</title>

</head>
<body>
<!-- navbar -->
<ul>
<li><a class="active" href="#home">Home</a></li>
<li><a href="#news">News</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#">About</a></li>
</ul>

<!-- under navbar-->
<div class="header">

<div id="container">
<div id="context">
<!--<div id="header-image"> -->
</div>
</div>
</div>
<br>
<br>
<br>

<section id="textbox">
<div id="box">Text box 1</div>
<div id="box">Text box 2</div>
<div id="box">Text box 3</div>
</section>

<!-- footer -->
<div class="footer">
<p>Copyrights reserved to &copy realmymonsterdk| Contact information: <a href="mymonsterdk@gmail.com">
mymonsterdk@gmail.com</a>.</p>
</div>
</body>
</html>


顺便说一句,我会全屏显示很小的代码片段。

关于html - 空间和中心框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53792393/

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