我正在尝试创建一个简单的图片库,有人告诉我使用“float: left”,但是当我这样做时,页脚中的所有文本都会射到第一张图像。我已经搜索了大约一个小时试图找到解决方案,但我找不到任何东西。我尝试过使用边距、边框、不同的对齐方式和各种不同的小东西,但没有任何效果。这是网站代码:
header.php
<!DOCTYPE html>
<html>
<head>
<style type="text/css" media="all">@import "./includes/layout.css";</style>
</head>
<body>
<a href="index.html" class="logo"> <img src="includes/images/mockwebsitelogo.png" alt="Logo" width="427" height="172" /></a>
<div id="nav">
<a href=index.php class="navBarLink">Home</a>
<a href=about.php class="navBarLink">About</a>
<a href=gallery.php class="navBarLink">Gallery</a>
<a href=programs.php class="navBarLink">Programs</a>
</div>
画廊.php
<?php
include('includes/header.php');
?>
<div id="txt1">
<h1>Gallery</h1>
<p>This is the gallery. Enter pictures or screenshots for the user to view</p>
<p class="image"><a href="includes/images/mwt.png">
<img src="includes/images/mwt.png" alt="tst" title="tst" width="175" height="175" /></a></p>
<p class="image"><a href="includes/images/mwt.png">
<img src="includes/images/mwt.png" alt="tst" title="tst" width="175" height="175" /></a></p>
<p class="image"><a href="includes/images/mwt.png">
<img src="includes/images/mwt.png" alt="tst" title="tst" width="175" height="175" /></a></p>
<p class="image"><a href="includes/images/mwt.png">
<img src="includes/images/mwt.png" alt="tst" title="tst" width="175" height="175" /></a></p>
<p class="image"><a href="includes/images/mwt.png">
<img src="includes/images/mwt.png" alt="tst" title="tst" width="175" height="175" /></a></p>
</div>
<?php
include('includes/footer.php');
?>
页脚.php
<div id="footer">
<p>Mock Website created on 12th November 2013</p>
</div>
</body>
布局.css
body
{
background-color: #e1e1e1;
background-image:url('/includes/images/mwbb.png');
background-repeat: no-repeat;
background-position: 50%;
}
#nav
{
border: 1px solid;
border-radius: 25px;
border-color: #e1e1e1;
background-color: #e1e1e1;
border-color: #000;
margin-left: auto;
margin-right: auto;
text-align: center;
width: 850px;
}
#footer
{
border-top: 1px solid;
margin-left: auto;
margin-right: auto;
width: 700px;
padding-top: 10px;
padding-bottom: 10px;
text-align: center;
white-space: nowrap;
}
#txt1
{
width: 750px;
margin-left: auto;
margin-right: auto;
}
.navBarLink
{
margin-left: 50px;
margin-right: 50px;
color: #000;
text-decoration: none;
}
.navBarLink:hover
{
color: #878787;
}
.logo
{
display: block;
text-align: center;
}
.image
{
margin: 5px 5px 5px 5px;
border: 1px solid #000;
padding: 5px 5px 5px 5px;
width: 175px;
height: 175px;
text-align: center;
float: left;
background-color: #323232;
display: inline;
}
.image:hover
{
background-color: #4d4d4d;
}
我认为这是初学者经常犯的错误,但我找不到任何可以解决它的方法,感谢任何试图提供帮助的人。
浮动元素会将其带出页面的“流程”。您的页脚会向上弹出,因为它没有注意到浮动元素。这是哪里clear https://developer.mozilla.org/en-US/docs/Web/CSS/clear进来时,它指定该元素是否可以位于浮动元素旁边(或与其对齐)。添加clear:both
到你的页脚,你应该得到你想要的结果:
#footer {
border-top: 1px solid;
margin-left: auto;
margin-right: auto;
width: 700px;
padding-top: 10px;
padding-bottom: 10px;
text-align: center;
white-space: nowrap;
clear:both;
}
JSFiddle http://jsfiddle.net/kL6PQ/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)