我正在学习CSS和HTML5,但我无法弄清楚如何做一些基本的东西。我正在使用谷歌浏览器,并试图为页面创建一个顶部栏,基本上是一个矩形,延伸到页面的每个边缘,并在栏中有一个简单的标志,允许用户点击它返回家。无论我做什么,我总是在我的背景周围有空白,也使用附件属性和滚动值我得到一个非滚动的背景。
继承我的代码:
img#logo {
width: 10%;
height: auto;
max-width: 100%;
}
#topbar {
background-color: #0000FF;
width: 100%;
height: 10%;
margin: 0px;
padding: 0px;
background-attachment: scroll;
}
<body>
<!-- Our displayed logo/hyperlink to home page -->
<header id="topbar">
<a href="home.html"><img id="logo" src="logo.png" alt="Your company
logo" /></a>
</header>
</body>
答案 0 :(得分:0)
导致此行为是因为浏览器具有不同的默认样式行为。我建议在样式表的顶部包含CSS重置,以在设置自己的样式之前重置浏览器的默认样式行为。
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}