如何将图像和文本放在这样的div框中?

时间:2012-10-29 23:47:41

标签: css html5 css3 html

我有一个看起来像这样的div框:

.productholder
{
width: 954px;
margin-left: 175px;
margin-bottom: 30px;
background-color: white; 
border-style:solid;
border-width: 1px;
border-color: #d2d2d2;

/* gradients */
background: -webkit-gradient(linear, left top, left bottom, 
color-stop(0%, white), color-stop(50%, white), color-stop(170%, #f6f6f6)); 
background: -moz-linear-gradient(top, white 0%, white 55%, #f6f6f6 150%); 
}

我正试图获得一个文本结构,并像这个示例图片一样:

Divbox

但是我似乎无法像照片那样得到它,任何形式的帮助都会让我感激如何让我的盒子看起来像这个示例图片。

到目前为止我已尝试过这个:

<div class="productholder">  
  <img src="url" alt="" />
  <h2>Titletext</h2> 
  <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer mi. Vivamu. etc</p>       
  <input type="submit" value="More">
  <p>$599</p>
  <input type="submit" value="Buy">                                    
</div>

img{
float:left;
}

h2{
float:left;
font-size: 14px;
}

感谢任何形式的帮助!

3 个答案:

答案 0 :(得分:4)

这是一个想法 - DEMO

HTML

<div class="productholder">  
    <img src="http://lorempixel.com/100/100" alt="" />

    <div class="productinfo">
        <h2>Titletext</h2> 
        <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer mi. Vivamu. etc</p>       
        <input type="submit" value="More">
    </div>

    <div class="productprice">
        <h2>$599</h2>
        <input type="submit" value="Buy">
    </div>        
</div>​

CSS

.productholder {
    width: 954px;
    margin-bottom: 30px;
    background-color: white; 
    border-style:solid;
    border-width: 1px;
    border-color: #d2d2d2;

    /* gradients */
    background: -webkit-gradient(linear, left top, left bottom, 
    color-stop(0%, white), color-stop(50%, white), color-stop(170%, #f6f6f6)); 
    background: -moz-linear-gradient(top, white 0%, white 55%, #f6f6f6 150%); 
}

.productholder img {
    display: inline-block;
    margin: 20px;
}

.productinfo {
    border: 1px solid #ccc;
    display: inline-block;
    margin: 20px 0;
    vertical-align: top;
    width: 500px;
}

.productinfo input {
    float: right;
    margin-top: 20px;
}

.productprice {
    border: 1px solid #ccc;
    width: 150px;
    float: right;
    margin: 20px;
    text-align: center;
}
​

答案 1 :(得分:0)

对于图像,h2和第一个p执行此操作

.productholder{
width: 734px;
padding-left: 220px;
}
.productholder img{
float:left;
margin: 10px;
max-width: 200px;
}

然后给第二个p一个类名,并用margin-right:10px;向右浮动 对于输入:

input{
position: absolute;
bottom: 5px;
right: 10px;
}

这是一个粗略的草图,但它应该是正确的..

答案 2 :(得分:0)

使用简单的代码:

HTML:

<div class="wrapper">

    <div class="box-one">dfgdfg</div>
    <div class="box-two">dfgdfgdfgdfg</div>
    <div class="box-three">dfgdfgdfgdfg</div>
    <div class="clear"></div>

</div>

CSS:

.clear{
    clear:both;
}

.wrapper{
    width:450px;
    background:#A4A4A4;
}

.box-one{
    float:left;
    width:80px;
}

.box-two{
    float:left;
    width:300x;
}

.box-three{
    float:right;
    width:70px;
}

我把骨架听到了。自定义css并使用它。干杯.....