HTML CSS 按钮文本对齐不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10737473/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 00:37:25  来源:igfitidea点击:

HTML CSS button text alignment isn't working

htmlcss

提问by Sasha

I have code like this:

我有这样的代码:

 <button class="prikazi_pretragu">Napredna Pretraga</button>?

and CSS:

和 CSS:

button {
  display:inline;
  font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif; 
  float: right; 
  clear: both; 
  padding: 0 50px 5px 5px; 
  text-align: left; 
  margin: 0 0 10px 0; 
  border: none; 
  background: url('../img/resursi/advsearch_plus.png') no-repeat 0 -28px rgba(0,0,0,.09);
  font-size: 14px; 
  height: 28px;
  text-align: right
}?

text-alignis not working. What is the problem?

text-align不管用。问题是什么?

http://jsfiddle.net/KjGBW/1/

http://jsfiddle.net/KjGBW/1/

回答by Ana

It is working. It is aligned to the right (quite pointlessly, since you haven't explicitly set a width). It's just that you have a 50px padding on the right and that's why it seemsto be aligned to the left.

这是工作。它向右对齐(毫无意义,因为您没有明确设置宽度)。只是你的右边有一个 50px 的填充,这就是为什么它似乎与左边对齐。

padding: 0 50px 5px 5px;

Values are for top right bottom left, in this order.

值按此顺序用于右上左下。

Set it to padding: 0 5px 5px 5px;

将其设置为 padding: 0 5px 5px 5px;

Also, if you set a width of let's say 300px you will see it clearly aligned to the right.

此外,如果您设置的宽度为 300 像素,您会看到它清楚地向右对齐。

See http://jsfiddle.net/thebabydino/KjGBW/5/- I have changed the padding and added a width. Now you can see clearly that it is aligned to the right.

请参阅http://jsfiddle.net/thebabydino/KjGBW/5/- 我已经更改了填充并添加了宽度。现在您可以清楚地看到它向右对齐。