Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/38.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
CSS:我能';在DIV元素的中间放置一个按钮_Css_Button - Fatal编程技术网

CSS:我能';在DIV元素的中间放置一个按钮

CSS:我能';在DIV元素的中间放置一个按钮,css,button,Css,Button,我正在使用本教程中的CSS按钮: 我需要在一个div的中间放一个按钮,所以它是居中的。但我不能 以下是按钮的代码: <a class="button" href="#"><span>Bring world peace</span></a> 以下是我尝试使用的代码: <div align="center"><a class="button" href="#"><span>Bring world peace&

我正在使用本教程中的CSS按钮:

我需要在一个div的中间放一个按钮,所以它是居中的。但我不能

以下是按钮的代码:

<a class="button" href="#"><span>Bring world peace</span></a>  
以下是我尝试使用的代码:

<div align="center"><a class="button" href="#"><span>Bring world peace</span></a></div>

a.按钮
浮动到左侧。您可以尝试
float:none在该元素上<代码>边距:0自动对于居中对齐图元也很有用


这有帮助吗?

修改这些属性的按钮类:

.button{
  margin-left:50%;
  margin-right:50%;
  position: relative;
}
并将链接包装在div中,如下所示:

<div align="center">
  <a class="button" href="#"><span>Bring world peace</span></a>  
</div>
.centerize {
    display: block;
    margin: 0 auto;
    text-align: center;
}

不推荐使用div元素的align属性。最好为该div定义一个类,如下所示:

<div class="centerize">
  <a class="button" href="#"><span>Bring world peace</span></a>
</div>
但是请注意,设置文本对齐只会影响div内的内容。div本身(应该)是块元素,并且取决于它在文档结构中的位置,它本身可能不会居中

为了更确定一点,您可以这样做:

<div align="center">
  <a class="button" href="#"><span>Bring world peace</span></a>  
</div>
.centerize {
    display: block;
    margin: 0 auto;
    text-align: center;
}

现在,您可以将“中心化”应用于任何元素,该元素应占据整个浏览器的宽度,并将其内容居中对齐。

谢谢,它仅在有一个单词时才起作用。当有一个以上的单词时,我就得到了世界PEACE@Alex:尝试将
text align:center
添加到
.button
类以及DIV.+1。从按钮上拆下浮子。浮动元素从正常页面布局中删除,因此不受其父元素布局样式的影响。如果有两个按钮,并且我们希望将它们都放在中间,这会起作用吗?我很惊讶;问这个问题所花的时间本来可以用来尝试一下。这里,让我为你做这件事: