html - 将两个按钮放在 HTML 中的同一行

标签 html css

这是我的登录表单:

login page image

如您所见,登录和注册按钮位于不同的行。我希望他们在同一条线上。

我将注册按钮代码放在与登录相同的段落元素中。毫无疑问它出现在同一行但是当我点击注册时它要求我填写用户名和密码。我该如何解决这个问题?

这是我的代码:

<form method="post" > 
    <p><input id="username" type="text" placeholder="Username" style="margin:10px" autofocus required></p>  
    <p><input id="password" type="password" placeholder="Password" style="margin:10px" required></p>
    <p><input class="swd-button" type="submit" value="Sign In"></p>
</form>
<a href="register.html"><button class="swd-button">Register</button></a>

最佳答案

真正的问题是链接中的按钮拦截了点击事件。这就是当您将第二个按钮作为第一个按钮的同级放置时它不起作用的原因。

要解决此问题,我建议您从链接中删除按钮,将链接样式设置为看起来像一个按钮,然后将其移回与“登录”按钮相同的段落中,同时使用设置为具有 display: inline-block

这是 jsFiddle demo .

HTML:

<form method="post" > 
    <p><input id="username" type="text" placeholder="Username" style="margin:10px" autofocus required></p>  
    <p><input id="password" type="password" placeholder="Password" style="margin:10px" required></p>
    <p>
        <button class="swd-button" type="submit">Sign In</button>
        <a class="swd-button" href="register.html">Register</a>
    </p>
</form>

CSS:

.swd-button {
    background: #11c3ff linear-gradient(to bottom, transparent, #009bcf);
    border: 1px solid white;
    border-radius: 5px;
    color: white;
    display: inline-block;
    font: bold 12px Arial, Helvetica, sans-serif;
    padding: 10px 15px;
    text-decoration: none;
    text-transform: uppercase;
}

关于html - 将两个按钮放在 HTML 中的同一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21452259/

相关文章:

javascript - 如何在点击时为另一个选择器切换悬停事件?

php - 一个表单,一个提交按钮,但有两个操作

html - 需要帮助垂直对齐 HTML5 和 CSS3 中的文本

css - Selenium WebDriver 从::before 伪元素上的 CSS 属性 "content"获取文本

html - 将元素放置在彼此之上

css - 将 2 个框对齐,其中一个框的位置为 : fixed;

javascript - Quill 格式化所有文本

javascript - CSS 样式不适用于 ExtJS 按钮

html - 拉伸(stretch)文本以适应 div 的宽度

html - Bootstrap col-md 变大是因为div在里面的绝对位置