html - 调整网页上的 float 元素

标签 html css css-float html-lists

我正在努力实现以下结果:

                                              Email               Password
                                              [Email box]         [Password Box] [Log In]
                                              []keep me logged in Forgot Password?

我已经成功地实现了前两行(Email ... [Log In])但无法塑造最后一行。 这是代码。

<ul>
<li>
<label for="mail">Email: </label><br>
<input type="email" name="mail" /><br>
<input type="checkbox" name="stayLoggedIn" />
    <small>Keep me signed in</small>
</li>
<li>
<label for="paswrd">Password: </label><br>
<input type="password" name="paswrd" /><br>
<small>Forgot  Password?</small>
</li>
<li><button type="button" name="login">Log In</button></li><br><p> </p>
</ul>

CSS代码如下。

header ul {float: right;}
    header ul li {
        display: inline-block;
        color: #FFEBCD;
        font-family: "Maiandra GD";
    }
header small {float: right;}

最佳答案

你需要用两个 div 来做到这一点,一个向左浮动,第二个向右浮动

查看 example

<div class="left_div">
   <label for="mail">Email: </label><br>
   <input type="email" name="mail" /><br>
   <input type="checkbox" name="stayLoggedIn" />
    <small>Keep me signed in</small>
</div>
<div class="right_div">
  <label for="paswrd">Password: </label><br>
  <input type="password" name="paswrd" /><br>
  <small>Forgot  Password?</small>
</div>

CSS代码

.left_div {
   float: left;
   width: 300px;    
 }

.right_div {
   float: right;
   width: 300px;    
 }

关于html - 调整网页上的 float 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12656720/

相关文章:

html - 为什么我的主要内容 div 没有扩展以适应其中的子 div?

HTML5 磁贴引擎

html - 在两个嵌套的 div 之间插入垂直分隔线,而不是全高

html - div定位正在改变有无边框

javascript - 如何使用位置:fixed; and slideDown() together

html - 适合所有屏幕的百分比定位

php - 带有变量的 Ajax 函数

css - 想在这段代码中加入 "icons"

jquery - 图像映射 : show different images on hover

CSS - float 和调整窗口大小