在div中移动文本而不移动div [英] Moving text around in a div without moving the div

查看:87
本文介绍了在div中移动文本而不移动div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个div,在div内是一个看起来像按钮的背景图像,并且div中有文字说"Home".默认情况下,文本被对齐到顶部,并且看起来不正确.如何在不移动div的情况下在div中移动文本?

I have a div, inside the div is a background image that looks like a button and I have text in the div saying "Home". By default the text is snapped to the top and does not look right. How could I move the text around in the div without moving the div?

css文件: http://pastebin.com/xrAFMVDd

html文件: http://pastebin.com/b5Fubte0

推荐答案

一种方法是将文本包装在< p> 标记中并使用CSS属性 top left position:relative 来指定文本相对于div左上角的位置.

One way of doing this is to wrap your text in a <p> tag and use CSS attributes top and left with position: relative to specify the position of the text relative to the top left of the div.

在此处查看示例: http://jsfiddle.net/zvMKH/

这篇关于在div中移动文本而不移动div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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