gpt4 book ai didi

html - 如何让一个元素跨越整个div?

转载 作者:行者123 更新时间:2023-11-28 04:17:42 24 4
gpt4 key购买 nike

编辑:感谢你们这些了不起的人,网页终于看起来棒极了!我无法选择最佳答案,因为他们都对我有很大帮助:p这是结果,如果有人感兴趣的话 http://i.imgur.com/RABpT9u.png

我正在尝试制作一个简单的网站,顶部有网站“ Logo ”,左侧有导航栏,中间有内容,底部有一些页脚。

与此同时,我正在尝试使其具有响应性,这显然还不是我的工作:D

我是 html 和 css 的新手,所以任何建议都会有很大帮助!

* { box-sizing: border-box;}

body { padding: 0; margin: 0; height:100%; }

header {
height:100%;
border:0.5vw ridge #888;
background:linear-gradient(to right,#123,#368,#48A,#59B,#48A,#368,#123);

text-align: center;
font-size: 1.4vw;
}
header h1,h2 {
color:#DD5;
font-family: "Helvetica";
margin: 0.5vw;
padding-top: 0.5vw;
line-height: 1.5vw;
text-shadow: 0px 0px 0.5vw #000;
}

main {
position: absolute;
display: flex;
width:100%;
max-height:100%;

background-color:#DDD;
border: 2px solid #F0F;
}

nav {
position: relative;
display:block;
overflow:auto;
z-index: 0;
float:left;
height:100%;
background: linear-gradient(90deg,#5BF,#29E);
border:0.5vw ridge #888;
max-width:100%; /*width 100% just makes the navbar all long and ugly*/
}
nav ul { margin:0; padding:0.5vw; list-style-type:none;}
nav li {
display:block;
width:100%;
padding: 1vw 0.5vw 1vw 0.5vw;
margin: 0.5vw auto;
text-align: center;

border:0.2vw outset white;
border-radius:0.5vw;
background:linear-gradient(180deg,#AAA 60%,#777);
}
nav a {
margin:0vw 1vw;
font-family: "Helvetica";
font-weight: bold;
font-size: 1.5vw;
color: #DDD;
line-height: 0.5;
text-decoration:none;
text-shadow: 0px 0px 0.3vw #000;
}

#content {
position: relative;
display: inline;
float:left;
z-index: 0;
max-width:100%;
background-color:grey;
border: 2px solid green;
}

footer {
width:100%;
margin-top:auto;
border: 2px dashed red;
}
<!doctype html>
<html lang="en">

<head>
<title>titlee</title>
<meta charset="UTF-8"/>
<meta name="keywords" content="keyowrdsssss" />
<meta name="description" content="descriptionnn" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<link rel="icon" href="icon.ico" />
<link rel="stylesheet" type="text/css" href="style.css" />
</head>

<body>

<header>
<h1>Header title!</h1>
<h2>Header description!</h2>
</header>

<main>
<nav>
<ul>
<li><a href="link">LinkToHome</a>
<li><a href="link">link1</a></li>
<li><a href="link">link2</a></li>
<li><a href="link">longlink3</a></li>
<li><a href="link">aboutlink</a></li>
</ul>
</nav>

<center>
<div id="content">
<h1>Content Content Content</h1></br>
<h1>Content Content Content</h1></br>
</div>
</center>

<footer>
<h1>footer</h1>
</footer>

</main>

</body>

</html>

最佳答案

您可以尝试使用;

宽度:100vw;


* { box-sizing: border-box;}

body { padding: 0; margin: 0; height:100%; }

header {
height:100%;
border:0.5vw ridge #888;
background:linear-gradient(to right,#123,#368,#48A,#59B,#48A,#368,#123);

text-align: center;
font-size: 1.4vw;
}
header h1,h2 {
color:#DD5;
font-family: "Helvetica";
margin: 0.5vw;
padding-top: 0.5vw;
line-height: 1.5vw;
text-shadow: 0px 0px 0.5vw #000;
}

main {
position: absolute;
display: flex;
width:100%;
max-height:100%;

background-color:#DDD;
border: 2px solid #F0F;
}

nav {
position: relative;
display:block;
overflow:auto;
z-index: 0;
float:left;
height:100%;
background: linear-gradient(90deg,#5BF,#29E);
border:0.5vw ridge #888;
max-width:100%; /*width 100% just makes the navbar all long and ugly*/
}
nav ul { margin:0; padding:0.5vw; list-style-type:none;}
nav li {
display:block;
width:100%;
padding: 1vw 0.5vw 1vw 0.5vw;
margin: 0.5vw auto;
text-align: center;

border:0.2vw outset white;
border-radius:0.5vw;
background:linear-gradient(180deg,#AAA 60%,#777);
}
nav a {
margin:0vw 1vw;
font-family: "Helvetica";
font-weight: bold;
font-size: 1.5vw;
color: #DDD;
line-height: 0.5;
text-decoration:none;
text-shadow: 0px 0px 0.3vw #000;
}

#content {
position: relative;
display: inline;
float:left;
z-index: 0;
background-color:grey;
border: 2px solid green;
width:86vw;
}

footer {
position: absolute;
width:100%;
border: 2px dashed red;
bottom:0;
}
<!doctype html>
<html lang="en">

<head>
<title>titlee</title>
<meta charset="UTF-8"/>
<meta name="keywords" content="keyowrdsssss" />
<meta name="description" content="descriptionnn" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<link rel="icon" href="icon.ico" />
<link rel="stylesheet" type="text/css" href="style.css" />
</head>

<body>

<header>
<h1>Header title!</h1>
<h2>Header description!</h2>
</header>

<main>
<nav>
<ul>
<li><a href="link">LinkToHome</a>
<li><a href="link">link1</a></li>
<li><a href="link">link2</a></li>
<li><a href="link">longlink3</a></li>
<li><a href="link">aboutlink</a></li>
</ul>
</nav>

<center>
<div id="content">
<h1>Content Content Content</h1></br>
<h1>Content Content Content</h1></br>
</div>
</center>
</main>
<footer>
<h1>footer</h1>
</footer>



</body>

</html>

关于html - 如何让一个元素跨越整个div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37732467/

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