HTML+CSS : How do I put this 2 buttons at the same level vertically

标签 html css

我想将这两个按钮(登录和注册器)对齐在同一级别,但由于它们的形式不同,“注册器”按钮被放置在“下一行”。

这是视觉上的问题: enter image description here

代码如下:

HTML

<section class="header_form_login">
    <form action="index2.html" method="GET">
        <label for="user">Usuario:<br></label>
        <input type="text" id="user" name="user_input">
        <label for="pass"><br>Contraseña:<br></label>
        <input type="text" id="pass" name="pass">
        <input type="submit" id="login" value="Login">
    </form>
    <form action="registro.html" method="GET">
        <input type="submit" id="register" value="Registrar">
    </form>
</section>

CSS:

header > section.header_form_login{
    font-weight: 500;
    align-items: right;
    padding: 5px;
    margin: auto;
    margin-right: 20px;
}

header > section.header_form_login > form > input#user{
    width: 200px;
    height: 24px;
    border: 1px solid lightgray;
}

header > section.header_form_login > form > input#pass{
    width: 200px;
    height: 24px;
    border: 1px solid lightgray;
}

    /* BUTTONS */
    header > section.header_form_login > form > input#login{
        border: none;
        background-color: #CAB99F;
        color: black;
        font-weight: 500;
        font-family: 'Roboto';
        font-size: 15px;
        text-decoration: none;
        padding: 10px 20px;
        cursor: pointer;
        display: block;
        margin-top: 10px;
    }

    header > section.header_form_login > form > input#register{
        border: none;
        background-color: #CAB99F;
        color: black;
        font-weight: 500;
        font-family: 'Roboto';
        font-size: 15px;
        text-decoration: none;
        padding: 10px 30px;
        cursor: pointer;
        display: flex;
        float: right;
        margin-top: 10px;
    }

非常感谢!!!

PD:请随意给我建议,我对 html 和 css 编码有点陌生。

我需要 html 和 css 方面的帮助,特别是将按钮垂直放置在同一水平但来自不同的形式

最佳答案

更新:重构 CSS 以共享样式。

我会重组您的 HTML 并修复您的 CSS 以使一切正常运行。此外,在使用 id 时,它们应该是唯一的,因此不需要像这样的长查找查询:

header > section.header_form_login > form > input#login { … }

就用

#login { … }

为了使“button”对齐,我将寄存器 input 设为链接。这是非常标准的。然后我添加了一些 CSS 以将这些元素对齐在同一行上。

.form-buttons {
  display: flex;
  flex-wrap: nowrap;
}

以下是我如何重构您的标记和样式。

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

.header_form_login {
  font-weight: 500;
  padding: 5px;
  margin: auto;
  width: 250px;
  max-width: 100%;
}

#user,
#pass {
  width: 100%;
  padding: 5px;
  border: 1px solid lightgray;
}

/* BUTTONS */

#login,
#register {
  border: none;
  background-color: #CAB99F;
  color: black;
  font-weight: 500;
  font-family: 'Roboto';
  font-size: 15px;  
  text-decoration: none;
  padding: 10px 20px;
  cursor: pointer;  
  text-align: center;
  flex: 1;  
}

#login {
  margin-right: 2.5px;  
}

#register {
  margin-left: 2.5px;
}

.form-buttons {
  padding-top: 10px;
  display: flex;
  flex-wrap: nowrap;
}
<section class="header_form_login">
  <form action="index2.html" method="GET">
    <label for="user">Usuario:<br></label>
    <input type="text" id="user" name="user_input">
    <label for="pass">Contraseña:</label>
    <input type="text" id="pass" name="pass">
    <div class="form-buttons">
      <input type="submit" id="login" value="Login">
      <a href="registro.html" id="register">Register</a>
    </div>
  </form>
</section>

jsFiddle

关于HTML+CSS : How do I put this 2 buttons at the same level vertically,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55307771/

相关文章:

html - CSS最小宽度和最大宽度以及灵活的布局

javascript - 单击时向右和向左滑动 div

html - 如何设置进度条数字计数器的样式

html - 如何使我的 CSS 包装器的宽度相对于显示器的大小?

javascript - 无法增加视频元素宽度

php - 我如何获得运行 Php 脚本的链接?

javascript - Wordpress 点击子菜单关闭当前子菜单

javascript - 构建动态且响应迅速的图像拼贴

html - div 底部奇怪的额外空间

css - 在自定义样式组件模板字符串上运行 stylelint