2

我这里有个小问题。我想将红色 div 居中并让两个绿色 div 向右浮动。两个正确的 div 似乎下降了?

http://jsbin.com/ewihuh/1/edit

HTML

<div class="headertop">
 <div class="centerblock">Centered</div>
 <div class="right1">right 1</div>
 <div class="right2">right 2</div> 
</div>

CSS

.headertop {
 width:100%;
 height:30px;
 background:black;
}

.centerblock {
 color:white;
 text-align:center;
 background:red;
 width: 200px;
 margin: 0px auto;
}

.right1, .right2 {
 color:white;
 float:right; 
 width:100px;
 background:green;
}
4

2 回答 2

3

现场演示

嗨,现在更改your html code并更改为css

CSS

  .headertop {
    width:100%;
    background:black;
    text-align:center;
}
.centerblock {
    color:white;
    text-align:center;
    background:red;
    width: 200px;
    margin:0 auto;
}
.right1, .right2{
    color:white;
    float:right;
    width:100px;
    background:green;
}

HTML

<div class="headertop">
    <div class="right1">right 1</div>  
    <div class="right2">right 2</div>
    <div class="centerblock">Centered</div>
</div>
于 2012-10-31T04:23:45.807 回答
1

HTML

<div class="headertop">
  <div class="centerblock">Centered</div>
  <div class="rights">
    <div class="right1">right 1</div>
    <div class="right2">right 2</div> 
 </div>
</div>

CSS

 .headertop {
  width:100%;
  height:30px;
  background:black;
  text-align:center;
  position:relative;
  }

 .centerblock {
  color:white;
  text-align:center;
  background:red;
  width: 200px;
  margin: 0 auto;
 }

.rights {
 position:absolute;
 right:0;
 top:0;
 width:100px;
}

.right1, .right2 {
 color:white;
 width:50px;
 background:green;
 float:left;
 }

演示:http: //jsbin.com/ewihuh/7/edit

于 2012-10-31T04:23:50.797 回答