页脚div文本不会排队

时间:2014-11-02 15:03:02

标签: html css

我想要做的是排队页脚中的3个div。但我似乎无法让他们正确排队。当我尝试使用浮动时,其中只有两个将排成一行,而第三个将在它们之下。有谁知道发生了什么?

body{
	background-color: rgb(240, 240, 240);
}

#pageFooter{
	margin-top: 10px;
	background-color: red;
	height: 200px;
	border-top-left-radius: 5px;
	border-top-right-radius: 5px;
	box-shadow: 1px 1px 1px 1px #888888;
}

#pageFooter p{
	color: white;
	padding-left: 1em;
	font-family: sans-serif;
	vertical-align: middle;
	line-height: 40px;
	font-weight: bold;
}

#leftFooter{
	text-align: left;
	float: left;
	position: relative;
}

#midFooter{
	text-align: center;
	float: center;
	position: relative;
}

#rightFooter{
	text-align: right;
	float: right;
	position: relative;
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Oppgave 1</title>

<link rel="stylesheet" type="text/css" href="css/meyersReset.css">
<link rel="stylesheet" type="text/css" href="css/mainStyle.css">

</head>

<body>

<div id="container">
      <footer id="pageFooter">
    	<div id="leftFooter">
    		<p>Lorem Ipsum</p>
    		<p>Lorem Ipsum</p>
    		<p>Lorem Ipsum</p>
    		<p>Lorem Ipsum</p>
    		<p>Lorem Ipsum</p>
    	</div>
    
    	<div id="midFooter">
	    	<p>Lorem Ipsum</p>
	    	<p>Lorem Ipsum</p>
	    	<p>Lorem Ipsum</p>
	    	<p>Lorem Ipsum</p>
	    	<p>Lorem Ipsum</p>
       	</div>
    
    	<div id="rightFooter">
	    	<p>Lorem Ipsum</p>
	    	<p>Lorem Ipsum</p>
	    	<p>Lorem Ipsum</p>
	    	<p>Lorem Ipsum</p>
	    	<p>Lorem Ipsum</p>
	    </div>
    </footer>

</div>

</body>
</html>

2 个答案:

答案 0 :(得分:4)

我认为display: table技术适合您的情况:

&#13;
&#13;
body {
  background-color: rgb(240, 240, 240);
}
#pageFooter {
  margin-top: 10px;
  background-color: red;
  height: 200px;
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;
  box-shadow: 1px 1px 1px 1px #888888;
  display: table;/*Add display table*/
  width: 100%;
}
#pageFooter p {
  color: white;
  padding-left: 1em;
  font-family: sans-serif;
  vertical-align: middle;
  line-height: 40px;
  font-weight: bold;
}
#leftFooter {
  text-align: left;
  display: table-cell;/*add display table-cell*/
  position: relative;
}
#midFooter {
  text-align: center;
  display: table-cell;/*add display table-cell*/
  position: relative;
}
#rightFooter {
  text-align: right;
  display: table-cell;/*add display table-cell*/
  position: relative;
}
&#13;
<body>
  <div id="container">
    <footer id="pageFooter">
      <div id="leftFooter">
        <p>Lorem Ipsum</p>
        <p>Lorem Ipsum</p>
        <p>Lorem Ipsum</p>
        <p>Lorem Ipsum</p>
        <p>Lorem Ipsum</p>
      </div>
      <div id="midFooter">
        <p>Lorem Ipsum</p>
        <p>Lorem Ipsum</p>
        <p>Lorem Ipsum</p>
        <p>Lorem Ipsum</p>
        <p>Lorem Ipsum</p>
      </div>
      <div id="rightFooter">
        <p>Lorem Ipsum</p>
        <p>Lorem Ipsum</p>
        <p>Lorem Ipsum</p>
        <p>Lorem Ipsum</p>
        <p>Lorem Ipsum</p>
      </div>
    </footer>
  </div>
</body>
&#13;
&#13;
&#13;

答案 1 :(得分:2)

没有float: center属性。

您必须float div left并添加宽度才能使它们正确对齐。

body{
	background-color: rgb(240, 240, 240);
}

#pageFooter{
	margin-top: 10px;
	background-color: red;
	height: 200px;
	border-top-left-radius: 5px;
	border-top-right-radius: 5px;
	box-shadow: 1px 1px 1px 1px #888888;
}

#pageFooter p{
	color: white;
	padding-left: 1em;
	font-family: sans-serif;
	vertical-align: middle;
	line-height: 40px;
	font-weight: bold;
}

#leftFooter, #midFooter, #rightFooter{
	float: left;
	position: relative;
	width: 33%;
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Oppgave 1</title>

<link rel="stylesheet" type="text/css" href="css/meyersReset.css">
<link rel="stylesheet" type="text/css" href="css/mainStyle.css">

</head>

<body>

<div id="container">
      <footer id="pageFooter">
    	<div id="leftFooter">
    		<p>Lorem Ipsum</p>
    		<p>Lorem Ipsum</p>
    		<p>Lorem Ipsum</p>
    		<p>Lorem Ipsum</p>
    		<p>Lorem Ipsum</p>
    	</div>
    
    	<div id="midFooter">
	    	<p>Lorem Ipsum</p>
	    	<p>Lorem Ipsum</p>
	    	<p>Lorem Ipsum</p>
	    	<p>Lorem Ipsum</p>
	    	<p>Lorem Ipsum</p>
       	</div>
    
    	<div id="rightFooter">
	    	<p>Lorem Ipsum</p>
	    	<p>Lorem Ipsum</p>
	    	<p>Lorem Ipsum</p>
	    	<p>Lorem Ipsum</p>
	    	<p>Lorem Ipsum</p>
	    </div>
    </footer>

</div>

</body>
</html>

相关问题