简体   繁体   English

CSS如何垂直对齐我的文本和文本颜色

[英]CSS how to vertical align my text and text color

This is my output now 这是我的输出

在此输入图像描述

This is the output I want 这是我想要的输出

在此输入图像描述

My coding: 我的编码:

.buttons{
background-image:url("SlicingImage/button_unselect.png");
margin: none;
height: 53px;
width: 180px;
text-transform:uppercase;
text-align:center;
position:relative;
vertical-align:bottom;
}

HTML : HTML:

<li class="buttons">home</li>

But nothing changed :( 但没有改变:(

General tip : if its just a link and not a paragraph, always give line-height equal to div height to align your text vertically in the middle 一般提示 :如果它只是一个链接而不是一个段落,总是给line-height等于div高度,以便在中间垂直对齐文本

here add line-height:53px; 这里添加line-height:53px; to your class 到你的班级

Vertical-align: bottom; works only with table-attributes like Table-cell or Table-Row 仅适用于Table-cellTable-RowTable-cell属性

So: 所以:

.buttons{
   background-image:url("SlicingImage/button_unselect.png");
   margin: 0;
   height: 53px;
   width: 180px;
   text-transform:uppercase;
   text-align:center;
   position:relative;
   vertical-align:bottom;
   display: table-cell
}

You need to play with this; 你需要玩这个; here a explanation about it: http://www.onenaught.com/posts/201/ 这里有一个解释: http//www.onenaught.com/posts/201/

Try this: 尝试这个:

.buttons{
background-image:url("SlicingImage/button_unselect.png");
margin: none;
/*height: 53px;
width: 180px;*/
padding: 30px 30px;
text-transform:uppercase;
text-align:center;
position:relative;
vertical-align:bottom;
}

the vertical align does not work like that for what your'e trying to do. 垂直对齐不会像你想要做的那样工作。

you need to use line-height or padding to resolve this issue. 您需要使用行高或填充来解决此问题。

i would try line-height first 我会首先尝试行高

   .buttons { line-height: 100px; }

and also remove the height: 53px from your code. 并从代码中删除高度:53px。 But adjust line-height accordingly. 但相应地调整线高。

Or you could also try 或者你也可以试试

   .buttons { padding-top: 16px; }

and adjust accordingly 并相应调整

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

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