简体   繁体   English

如何在图像的正中间对齐文本

[英]How do I align text in exact middle of my image

I have a style that includes both a background and text. 我的风格既包含背景又包含文本。 I want to align the text in the exact middle of the background. 我想在背景的正中间对齐文本。

Currently there is more space below the text than above. 当前,文本下方的空间比上方的空间大。

How would I do that? 我该怎么做?

Check out my jsfiddle: http://jsfiddle.net/vc256tgL/10/ 看看我的jsfiddle: http : //jsfiddle.net/vc256tgL/10/

Here's my code: 这是我的代码:

    <p class="form-title white">
    Download White Paper</p>

Here's my css: 这是我的CSS:

.form-title {
font-family:Arial, Helvetica, sans-serif;
font-size: 18px;
font-weight: bold;
}

.form-title {
    vertical-align: middle;
    height: 55px;
    margin: 0 0 0 0;
    background-image: url('http://www.hapadesign.com/assets/img/bkgd_form_top.png');
    background-repeat: no-repeat;
}

.white { color: #ffffff !important;}

add these lines to form-title class please 将这些行添加到form-title类中

line-height:40px;
text-align:center;
background-position:center;

Demo 演示

UPDATE 1 : 更新1:

Updated Demo 更新的演示

If you want a little bit more flexibility, you can emulate that style using just CSS: 如果您想要更多的灵活性,可以仅使用CSS来模仿该样式:

CSS CSS

.tooltip {
   position: relative;
   display: inline-block;
   padding: 10px 25px;
   color: #fff;
   background: blue;
}
.tooltip:after {
   content: '';
   position: absolute;
   top: 100%;
   right: 0;
   left: 0;
   width: 0;
   height: 0;
   margin: 0 auto;
   border-width: 10px;
   border-style: solid;
   border-color: blue transparent transparent;
}

HTML HTML

<p class="tooltip">Here's Some Text</p>

The tooltip arrow is created using a border on an element with no height or width, so it makes the angle you're looking for. 工具提示箭头是使用没有高度或宽度的元素上的边框创建的,因此可以确定您要寻找的角度。

Example: http://codepen.io/a_double/pen/XJjKRg 示例: http//codepen.io/a_double/pen/XJjKRg

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM