在我正在创建的网站上,我想要导航栏和位于其下方的图像,以填充屏幕的整个宽度,没有填充。我使用导航栏的固定位置和工作图像的绝对位置。但是现在我想在图像下面添加一些文字,但它将自己定位在页面的右上角,我需要更改什么才能使文本在图像下方定位?
这是我的CSS:
body{
background-color: rgb(47,47,47);
font-family: "Lucida Grande", "Lucida Sans Unicode", Arial, sans-serif;
letter-spacing: -1px;
color: rgb(230,230,230);
}
ul{
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
text-align: center;
width: 518px;
margin: 0 auto;
}
li{
float: left;
}
li a{
font-size: 24px;
display: block;
width: auto;
padding: 32px 30px;
text-decoration: none;
font-weight: bold;
color: rgb(230,230,230);
}
li a:hover{
background-color: rgb(47,47,47);
}
li a:active {
background-color: rgb(223, 66, 68)
}
nav{
background-color: rgb(6,6,6);
opacity: 0.8;
height: 100px;
position: fixed;
top:0px;
left:0px;
width: 100%;
z-index:1;
-webkit-box-shadow: 0px 4px 5px 0px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 4px 5px 0px rgba(0,0,0,0.75);
box-shadow: 0px 4px 5px 0px rgba(0,0,0,0.75);
}
#logo{
position: absolute;
top: 100px;
left:0px;
width: 100%;
}
HTML:
<body>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Portfolio</a></li>
<li><a href="#">CV</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
<img id="logo" src="images/logo.png"/>
<h1>About me</h1>
</body>
答案 0 :(得分:1)
将图像和文本放在一个div下并给出给图像的css,将它交给新的div。即position:absolute
到新创建的div。
像:
body{
background-color: rgb(47,47,47);
font-family: "Lucida Grande", "Lucida Sans Unicode", Arial, sans-serif;
letter-spacing: -1px;
color: rgb(230,230,230);
}
ul{
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
text-align: center;
width: 518px;
margin: 0 auto;
}
li{
float: left;
}
li a{
font-size: 24px;
display: block;
width: auto;
padding: 32px 30px;
text-decoration: none;
font-weight: bold;
color: rgb(230,230,230);
}
li a:hover{
background-color: rgb(47,47,47);
}
li a:active {
background-color: rgb(223, 66, 68)
}
nav{
background-color: rgb(6,6,6);
opacity: 0.8;
height: 100px;
position: fixed;
top:0px;
left:0px;
width: 100%;
z-index:1;
-webkit-box-shadow: 0px 4px 5px 0px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 4px 5px 0px rgba(0,0,0,0.75);
box-shadow: 0px 4px 5px 0px rgba(0,0,0,0.75);
}
.belowDiv{
position: absolute;
top: 100px;
left:0px;
width: 100%;
}
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Portfolio</a></li>
<li><a href="#">CV</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
<div class="belowDiv">
<img id="logo" src="images/logo.png"/>
<h1>About me</h1>
</div>