html - 在我的横幅和中心放置 2 个按钮 div

标签 html css

我想在横幅和中心放置 2 个按钮 div(注册和登录)。但是我认为我的 html block 已经有问题了??

下面是我网站的概览。

截图:

enter image description here

我的第一个问题是我不能使用 margin-left 或 margin-right 将我的按钮“register”或“login”移到中心。

我的问题可能来自代码 HTML,是我的 block 有问题吗? 这是我的代码 HTML

<div class="my-banner">
    <img class="banner" src="images/slider.jpg"/>
    <div class="transparent"></div> 
    <a href="index.php"><img class="picture-logo" src="images/logo.png"/></a>
    <div class="container">
      <div class="myButtonRegister"><a href="lolo.php">REGISTER</a></div>
      <div class="myButtonLogin"><a href="lolo.php">LOGIN</a></div>
      <div class="topnav">
        <a class="active" href="index.php">HOME</a>
        <a href="#">ABOUT US</a>
        <a href="#">INVESTEMENT PLAN</a>
        <a href="#">NEWS</a>
        <a href="#">FAQS</a>
        <a href="#">RULES</a>
        <a href="#">CONTACT US</a>
      </div>
    </div>
</div>

这是我的代码 CSS

.myButtonRegister{
  margin-top: 342px;
  float: left;
  background-color: #C22312;
  color: white;
  height: 48px;
  width: 168px;
  text-align: center;
  color: white; 
  font-family: 'Pridi', serif;
  font-size: 26px;
  padding-top: 10px; 
  word-spacing: 0px;

}

.myButtonRegister a {
  color: #f2f2f2;
  text-decoration: none;

}

.myButtonLogin{
  margin-top: 342px;
  float: left;
  background-color: black;
  color: white;
  height: 48px;
  width: 168px;
  text-align: center;
  color: white; 
  font-family: 'Pridi', serif;
  font-size: 26px;
  padding-top: 10px; 
  word-spacing: 0px;

}

你有什么想法吗?

最佳答案

只需在您的按钮上添加一个父框,然后使用 flex 来对齐您的按钮。这是一个例子:

.container {
  height: 200px;
  width: 100%;
  background: #eee;
}

.container .subcontainer {
  display: flex;
  height: 100%;
  align-items: center;
  justify-content: center;
}
<div class="container">
  <div class="subcontainer">
    <button>Login</button>
    <button>Register</button>
  </div>
  <!--NAV-->
</div>

关于html - 在我的横幅和中心放置 2 个按钮 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52423075/

相关文章:

javascript - 如果勾选复选框,如何显示每个表行的 div?

html - Z-index 不适用于 :hover for flex elements

html - CSS3模态背景不透明

div 出现时的 CSS3 过渡

html - 与 tabless 布局中页脚上的 clear 属性有关的一些疑问

html - Chrome 边框半径缩放?

php - 从 html 中删除\r\n 和转义字符

html - 如何摆脱 HTML/CSS/Bootstrap 中圆形图像和边框之间的空白?

javascript - 如何正确地将动态输入字段传递到另一个页面进行显示?

html - 根据其中的@media 删除或调整不同 div 的图像大小?