【发布时间】:2016-02-26 10:33:44
【问题描述】:
所以我正在尝试为实验室重新创建以下布局:http://i.imgur.com/T24vvGu.jpg
我从处理导航栏开始。我将位置设置为绝对,所以我可以给它一个顶部:50px;属性将其从顶部向下移动 50px。
然后我尝试将徽标的位置设置为相对,以便相对于导航栏,我可以将其从左侧移动 20px 左右。但是当我使用相对定位时,徽标位于导航栏内部,使导航栏的高度更大。
我认为通过将徽标的位置设置为相对位置,它会将徽标视为不是导航栏的一部分。然而,事实并非如此。所以我所做的就是将徽标的位置设置为绝对位置。这整件事简直是在扼杀我的灵魂。出于某种原因,我无法理解如何做到这一点。
我去了网络档案馆,并查找了 spigot design 的网站。他们所做的是将导航栏的位置设置为固定,并将徽标设置为相对。我也尝试过这样做,但徽标仍会位于导航栏内并扩展其高度。
此外,当浏览器为 768 像素及以下时,我必须将徽标设置为位于导航栏的中间。然后,两个菜单链接位于徽标的左侧,另外两个菜单链接位于徽标的右侧。我完全不知道如何做到这一点。我认为其余的布局不会有问题。只是这个导航栏和标志定位让我发疯。
这是我的代码:http://cryptb.in/v48Y#cf572c29a798b3c6593631d831c8a323
我是否也应该上传带有徽标图片的代码?这可能更容易理解。我不确定最佳做法是什么,因为我是堆栈溢出的新手。
HTML:
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>Lab Eight</title>
<link href="css/styles.css" rel="stylesheet">
</head>
<body>
<!-- navigation bar left -->
<div class="navbar">
<div id="logo"></div>
<div class="container">
<ul class="float-right">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
<li><a href="#">Media</a></li>
</ul>
</div>
</div>
<div class="container">
<div class="row">
<div class="column-twelve">
</div>
<div class="column-twelve">
</div>
</div>
</div>
</body>
</html>
CSS:
@import url(https://fonts.googleapis.com/css?family=Open+Sans:300,400,700);
body {
background: #f3f3f3;
font-family: 'Open Sans', sans-serif;
margin: 0 auto;
}
h1, h2, h3, h4, h5, h6 {
font-weight: 500;
line-height: 1.1;
}
/* Horizontal line to divide content */
hr {
margin-top: 10px;
margin-bottom: 10px;
border: 0;
border-top: 1px solid #332929;
}
#logo {
background: url('images/logo-left.png');
display: block;
width: 250px;
height: 100px;
position: absolute;
left: 15px;
top: -20px;
}
.column-twelve h1, h2, h3, h4, h5, h6 {
color: #f2f2f2;
}
.column-twelve h2 {
font-size: 1.875em;
}
.row .column-twelve p {
color: #f2f2f2;
font-weight: 400;
font-size: 0.875em;
}
.float-left {
float: left;
}
.float-right {
float: right;
}
/* Acts as a container to wrap all the content so it doesn't take up 100% of the page. */
.container {
width: 90%;
padding-right: 10px;
padding-left: 10px;
margin-right: auto;
margin-left: auto;
}
.navbar {
position: absolute;
width: 100%;
min-height: 58px;
top: 50px;
background: #fefefe;
}
.navbar li {
position: relative;
display: inline;
list-style: none;
}
.navbar li a {
color: #333333;
text-decoration: none;
font-size: 0.75em;
font-weight: bold;
padding: 10px 10px;
text-transform: uppercase;
}
/* The row for the columns. */
.row {
margin-right: -15px;
margin-left: -15px;
}
.column-twelve {
width: 100%;
}
.column-eleven {
width: 91.66666667%;
}
.column-ten {
width: 83.33333333%;
}
.column-nine {
width: 75%;
}
.column-eight {
width: 66.66666667%;
}
.column-seven {
width: 58.33333333%;
}
.column-six {
width: 50%;
}
.column-five {
width: 41.66666667%;
}
.column-four {
width: 33.33333333%;
}
.column-three {
width: 25%;
}
.column-two {
width: 16.66666667%;
}
.column-one {
width: 8.33333333%;
}
@media screen and (max-width: 768px) {
#logo {
position: absolute;
margin: 0 auto;
background: url('images/logo-center.png');
height: 146px;
width: 250px;
}
}
【问题讨论】:
-
你应该添加你的代码。
-
好的,我在评论中添加了我的代码。
-
添加你的代码 js fiddle
标签: html css responsive-design position