2

Re: http://jsfiddle.net/WdGdd/3/

Is it possible to center a position:absolute div in its parent position:relative div?

The idea is to make a button whose text is one of two values. Its width stays the length of the whichever value is longer. When the shorter of the two values is being displayed, the text is centered in the button. I don't want to specify any widths in px.

4

1 回答 1

4

您不能将#op2 的CSS 更改为:

#op2 {
  position: absolute;
  top: 0;
  width:100%;
  text-align:center;
}

jsFiddle 示例

于 2012-05-11T16:54:22.550 回答