Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 在CSS中对齐文本_Html_Css - Fatal编程技术网

Html 在CSS中对齐文本

Html 在CSS中对齐文本,html,css,Html,Css,在css中对齐文本很容易!使用文本对齐:居中; 但我只是做了这个 .readmore { width: 80px; height: 30px; background: #000000; text-align: center; border-radius: 3px; float: center; color: #fff; font-family: 'Rambla', sans-serif; -webkit-transition

在css中对齐文本很容易!使用文本对齐:居中; 但我只是做了这个

.readmore {
    width: 80px;
    height: 30px;
    background: #000000;
    text-align: center;
    border-radius: 3px;
    float: center;
    color: #fff;
    font-family: 'Rambla', sans-serif;
    -webkit-transition: background-color 1s;
    -o-transition: background-color 1s;
    -moz-transition: background-color 1s;
    transition: background-color 1s;
}

.readmore:hover {
    background-color: #F79100;
    cursor: pointer;
    color: #000;
    font-family: 'Rambla', sans-serif;
}
和在HTML上

<div id="readmore">Read More</div>
阅读更多

我的问题是,当我看到按钮时,按钮内的文本(阅读更多内容)并没有从左上到右下完全对齐。我该怎么做

左边距:自动
右边距:自动
应将您制作的div id框居中对齐:)

哦,还有,你应该用#而不是。说到身份证。 这些圆点是用来上课的

垂直和水平对齐:

可以使用以下命令垂直对齐div 只需确保同时使用%指定宽度和高度,并从左侧百分比中删除元素的宽度,然后对高度执行相同的操作

position: absolute;
top: 50%;
left: 50%;`
首先,您使用
id=“readmore”
属性,但您的CSS是
.readmore
。相反,请使用其中一个

  • id=“readmore”
    #readmore
  • class=“readmore”
    。readmore
要使长方体水平居中(相对于其父对象),可以使用

.readmore {
    margin: 0 auto;
}

此外,如果要垂直居中(相对于框),请使用


在css中,将
.readmore
更改为
#readmore

前缀表示类名,而
#
前缀表示id


基本上,使用
.class
#Id

请为此提供一个提琴器。您给了您的div一个Id。在css中,Id是用
#
引用的,
是用于类的。@user2948424那么,您想将框居中(相对于窗口、文档、其父对象,…)或者您想将方框的文本相对于方框居中吗?@arkascha@MarcelGwerder谢谢!)Oriol我希望将框的文本相对于框居中。但问题解决了。谢谢:)为了简单起见,
margin:0 auto
。是的,另一种可能性:)嗯,是的,It中心。但很抱歉,我忘了在问题中提到,我也希望它在中心。从左上到右下等边距!正如你所说,左边距:自动;右边距:自动;我试过页边空白:自动;页边距底部:自动;但不起作用:使其垂直居中会带来另一个问题。这真的取决于你希望垂直居中什么…我添加了一种垂直对齐元素的替代方法。好的,谢谢,我现在将使用ID:D,我在我的问题中做了一些更改,你可以看到,mm完成了,再次感谢:)
.readmore {
    height: 30px;
    line-height: 30px; /* same as height */
}