gpt4 book ai didi

css - 页眉未延伸到浏览器的顶部/侧边。不能使用绝对位置

转载 作者:太空宇宙 更新时间:2023-11-03 20:38:18 26 4
gpt4 key购买 nike

我正在创建自己的网站。使用无序列表制作我自己的标题 + 导航栏。

我遇到的问题是标题没有延伸到浏览器的边缘。唯一可行的方法是在 css“header”中使用。

position:absolute;

我不希望使用绝对定位,但希望将标题保持在最顶部。

这是由于浏览器默认设置导致标题沿“填充”吗? (CSS 重置可以修复它吗?)

HTML:

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
<link href="certscss.css" rel="stylesheet" type="text/css">
</head>




<body>
<header>
<h2>My website!</h2>
<ul>
<li> <a href="aboutme.html">About Me </a></li>
<li> <a href="accomplishments.html">Accomplishments </a></li>
<li class="activemenutab"> <a href="certs.html">Certifications and Skills </a></li>
<li> <a href="extra.html">Extracirriculars </a></li>
<li> <a href="portfolio.html">Portfolio </a></li>
<li> <a href="contact.html">Contact </a></li>
</ul>
</header>

<h3>Certifications and Skills</h3>




<footer>
&copy; Mywebsite 2015
</footer>


</body>
</html>

CSS:

@charset "UTF-8";



html {
background-color:#B5B5B5
}

header {
left:0;
right:0;
margin:0;
top:0;
}

h2 {
background-color:#000000;
color:#d9d9d9;
text-align:center;
font-size: 2.8em;
margin:0;
}

ul {
list-style-type:none; /* takes symbols away from unordered list */
margin:0; /* shifts ul up against h2, and shifts it up in the header box */
background-color:#d9d9d9;
font-family:Baskerville, serif;
text-transform:uppercase;
left:0;
right:0;
text-align:center; /* centers nav bar */
font-size:0; /* this takes away the default white spaces at the end of the <li>...have to resize font in li */
}

li {
display:inline-block; /* makes nav go horizontal */
font-size:14px; /* size of navbar text ... !important has to be in px because ul has font size = 0*/
}

li:hover {
background:#000000; /* changes tab to black */
color:#E09635; /* changes text to color */
transition-duration: 0.3s; /* response time on navbar icon hover */
transition-timing-function: ease;
transition-delay: 0; /* zero delay to have transtion occur */
}

a {
text-decoration:none; /*removes underline from a links */
color:inherit; /* takes color from parent, in this case, li */
display:block; /* makes the a box relatable to li */
padding: 10px; /* creates padding around a box for navbar and adds to clickable region because of anchor */
}

.activemenutab { /* this is the class used to make the one you are on highlighted ... needs to be swithched in html */
background-color:#EDEDED;
color:#E09635;
}

/* ---------- body below */

h3 {
text-align:center;
font-family:Baskerville, serif;
text-transform:uppercase;
font-size:30px;
font-weight: 600;
letter-spacing: 0.2em;
word-spacing: 0.5em;
}

/* ---------- footer below */

footer {
text-align:center;
background-color:#000000;
color:#EDEDED;
left:0;
right:0;
bottom:0;
margin:0;
position:absolute;
padding:.2em;
}

结论!:如何让我的标题扩展到浏览器的边缘(在顶部、左侧和右侧),类似于我的页脚,而不使用绝对定位。提前致谢。

最佳答案

body 元素有一个默认边距,您需要去掉它:

body {
margin:0;
}

jsFiddle example

关于css - 页眉未延伸到浏览器的顶部/侧边。不能使用绝对位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29886307/

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