1

我需要css代码来创建以下框:

带标题的框

这是我的方法:

.content-box-gray {
margin: 0 0 0px;
overflow: hidden;
padding: 10px;
height: 15px;
font-size: 15px;
border-radius: 5px;
border: 1px solid gray;
color: #3385FF;
}

现在我需要编码标题..

问候,

4

2 回答 2

2

演示

标记:

<figure></figure>

风格:

figure{
    width:400px;
    height:220px;
    border-radius:4px;
    border:2px solid #ccc;
    position:relative;
}

figure:before{
    content:'';
    position:absolute;
    top:40px;
    left:0;
    width:100%;
    height:2px;
    background:#ccc;
}

结果:

处理图形元素

更新@petermeissner

如果要添加标题和正文,可以使用content: attr(data-title);

figure{
    width:400px;
    height:220px;
    border-radius:4px;
    border:2px solid #ccc;
    position:relative;
    padding:48px 10px 10px
}

figure:before {
    content: attr(data-title);
    position: absolute;
    top: 0px;
    left: 0;
    width: 100%;
    height: 40px;
    line-height: 40px;
    text-indent: 10px;
    border-bottom: 2px solid #ccc;
}
<figure data-title="Butter Cookies!">
  <figcaption>
    Homemade vanilla Danish butter cookies are the perfect cookie to share!         <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/figure">find out more about this Figure</a>
  </figcaption>
</figure>

结果:

在此处输入图像描述

于 2014-09-07T07:08:38.497 回答
2

请检查这个。检查这个[小提琴]:http: //jsfiddle.net/8L6ucojp/1/

.content-box-gray .content {
    overflow: hidden;
    padding: 10px;
    font-size: 15px;
    border-bottom-left-radius: 5px;
    border-bottom-right-radius: 5px;
    border: 1px solid gray;
    color: #3385FF;
}
.content-box-gray .title {
    height:30px;
    line-height:30px;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
    background:gray;
    font-size:18px;
    font-weight:bold;
    font-family:verdana;
    display:block;
    color:white;
    display:block;
    padding:10px;
    border: 1px solid gray;
    border-bottom:none;
}

和html如下

<div class="content-box-gray ">
    <div class="title">This is heading.</div>

    <div class="content">this is content . lots of content.</div>
</div>
于 2014-09-07T07:34:54.470 回答