Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.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/7/css/36.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_Center - Fatal编程技术网

Html CSS:如何水平居中?

Html CSS:如何水平居中?,html,css,center,Html,Css,Center,我再一次遇到了中心元素的问题。我有这个HTML/CSS: <section class="btmfix"> <div class="menurow"> <div class="col"> <a class="sml-btn" href="index.html">HOME</a> </div>

我再一次遇到了中心元素的问题。我有这个HTML/CSS:

<section class="btmfix">
  <div class="menurow">
    <div class="col">
      <a class="sml-btn" href="index.html">HOME</a>
    </div>
    <div class="col">
      <a class="sml-btn" href="about.html">ABOUT</a>
    </div>
    <div class="col">
      <a class="sml-btn" href="product.html">PRODUCT</a>
    </div>
    <div class="col">
      <a class="sml-btn" href="request.php">REQUEST</a>
    </div>
    <div class="col">
      <a class="sml-btn" href="contact.html">CONTACT</a>
    </div>
  </div>
</section>

我希望链接居中,但我不知道如何。我尝试了边距:0自动;方法,这在几乎每个教程中都可以找到,但在这里不起作用。你知道为什么吗?你能帮我吗


Thx提前

如果要将所有菜单组置于中间
文本对齐:中间就足够了

  .btmfix {
    display: block;
    padding-bottom: 0px;
    width: 100%;
    text-align:center;
  }
.col {
    padding: 0px;
    display: block;
    float:left;
  }
如果您还想水平显示菜单,则
float:left就足够了

  .btmfix {
    display: block;
    padding-bottom: 0px;
    width: 100%;
    text-align:center;
  }
.col {
    padding: 0px;
    display: block;
    float:left;
  }

您被赋予
宽度:0
menurow
这就是问题所在,并将列添加到
text align:center

.menurow {
  width: 100%;
}
.col {
  text-align: center;
}

要水平居中菜单,您需要应用
文本对齐:居中
.col
类上

以下是工作示例:

.menurow{}
.btmfix{
显示:块;
垫底:0px;
}
上校{
填充:0px;
文本对齐:居中;
}
.sml btn{
颜色:#000;
文字装饰:无;
背景色:#444;
保证金:3倍;
宽度:180px!重要;
填充:.3rem1rem;
字体大小:1.25rem;
线高:1.5;
边界半径:.3rem;
显示:内联块;
文本对齐:居中;
垂直对齐:中间对齐;
边框:1px实心#fff;
光标:指针;
文本转换:大写;
文本阴影:1px0px#fff;
}