开发者

Position div boxes with css

I want to achieve this:

Position div boxes with css

I want to display boxes, one main box and below each box a smaller box as you can see in the picture. I define this with the following html structure:

<div class='content'>
   <div class='box'>
       <a>test</a>
       <div class='money'><div id='maxnumber'>
           <h3 id='max'>max</h3><h3 id='digit'>0000</h3>
       </div></div>
       <div id='numbereuro'><h3 id='digit2'></h3>
           <h3 id='euro'></h3>
       </div>
   </div>           
   <div class='utility'>test</div>
</div>

Here is a working example that shows the re开发者_如何学运维sult without the smaller box: http://jsfiddle.net/

.box names the bigger box and .utility the smaller box below bot wrapped in .content. I use the following css:http://jsfiddle.net/76fXa/

.content {
    margin: 5px;
    padding: 5px;
    font-size: 11px;
    float: left;
}

.utility{
    position:relative;
    height:50px; width:100px; background:red;
}

.box {
    margin: 5px;
    padding: 5px;
    background: #BBE3A8;
    font-size: 11px;
    float: left;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
}

.box {
    position: relative;
    padding: 5px;
    width: 180px; height:auto;
    cursor:pointer;
}

and I get the following result: http://jsfiddle.net/76fXa/1/

Position div boxes with css

any ideas?


How about this quick fiddle I just made for you.

http://www.jsfiddle.net/ozzy/F3K8k/


Both .box and .utility should be put in another floated div so that they both are constrained within. Just a simplified example

<div id="content">
  <div class="section">
   <div class="box">
     Large content area
   </div>
   <div class="utility">
     Small content area
   </div>
  </div>
  <div class="section">
   <div class="box">
     Large content area
   </div>
   <div class="utility">
     Small content area
   </div>
  </div>
</div>

(attempting to preserve your class names where practical)

You could then set the inner divs to display block so that they fill the constrained area and set a fixed width to section (I will use 50% for demo purposes)

.section
{float:left; width:50%;}

.box
{display:block;}

.utility
{display:block;}

Set the other style properties as needed, and remember the box model when adjusting padding and margins. Sometimes applying too much or too little of either can break off to a newline if something is set wrong.

From what you provided I can't see why position relative would be necessary. If it was intended as an attempt to make the layout you demonstrated then I'd suggest removing it, unless for some reason you are absolutely positioning something within that div relative to it.

EDIT: Didn't realize you had two content divs and a fiddle posted.

http://jsfiddle.net/76fXa/2/


@ArtWorkAD: Is this is how you want it?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title></title>

<style type="text/css">
.content {
    float: left;
    font-size: 11px;
    margin: 5px;
    padding: 5px;
}

.utility {
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    background: red;
    border-radius: 5px;
    clear: left;
    cursor:pointer;
    float: left;
    font-size: 11px;
    height: auto;
    margin: 5px;
    padding: 5px;
    width: 180px;
}

.box {
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    background: #BBE3A8;
    border-radius: 5px;
    cursor:pointer;
    float: left;
    font-size: 11px;
    height: auto;
    margin: 5px;
    padding: 5px;
    width: 180px;
}
</style>
</head>

<body>

<div class="content">
    <div class="box">
        <a>test</a>
        <div class="money">
            <div id="maxnumber">
                <h3 id="max">max</h3><h3 id="digit">0000</h3>
            </div>
        </div>
        <div id="numbereuro"><h3 id="digit2"></h3>
            <h3 id="euro"></h3>
        </div>
    </div>

    <div class="utility">test</div>
</div>

</body>
</html>

http://jsfiddle.net/9Ugww/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜