带有标题的CSS Box

时间:2014-09-07 06:57:17

标签: css header box

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

box with header

这是我的方法:

.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;
}

现在我需要编写标题代码..

此致

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分:1)

DEMO

MARKUP:

<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;
}

结果:

Dealing with FIGURE element

更新@petermeissner

如果你想添加一个小体和一个身体,你可以使用content: attr(data-title);

&#13;
&#13;
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;
}
&#13;
<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>
&#13;
&#13;
&#13;

结果:

enter image description here