边框CSS HTML中的文本 [英] Text in Border CSS HTML

查看:152
本文介绍了边框CSS HTML中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个类似这样的div:

I'd like to have a div that looks like this:

这可能与HTML + CSS有关吗?我也将用jQuery动画这个div。

Is this possible to do with HTML + CSS? I will also be animating this div with jQuery. When the div is hidden I would like the title and the top line to show.

推荐答案

你可以这样做,其中您在 h1 (或您使用的任何标题)上设置负值 margin

You can do something like this, where you set a negative margin on the h1 (or whatever header you are using)

div{
    height:100px;
    width:100px;
    border:2px solid black;
}

h1{
    width:30px;
    margin-top:-10px;
    margin-left:5px;
    background:white;
}

注意:您需要设置 code>以及 h1

示例: http://jsfiddle.net/ZgEMM/

EDIT

使用隐藏 div ,你可以使用这样的一些jQuery

To make it work with hiding the div, you could use some jQuery like this

$('a').click(function(){
    var a = $('h1').detach();
    $('div').hide();
    $(a).prependTo('body');    
});

(您需要修改...)

示例2: http://jsfiddle.net/ZgEMM/4/

这篇关于边框CSS HTML中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆