鍍金池/ 問答/HTML5  HTML/ html浮動

html浮動

html
<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="UTF-8">
<title>Title</title>
<link href="../css/base.css" rel='stylesheet' type='text/css' />

</head>
<body>

  <div class="top_1">
         用戶名:<input type="text">
         密碼:  <input type="password">
         <a href="#">登錄</a>  <a href="#">注冊</a>
  </div>
  <div style="clear:both"></div>

</body>
</html>

css
body {

margin:0;
padding: 0;

}
a {

text-decoration:none;

}
.top_1 {

height: 50px;
background: lightgreen;
float: right;

}

top_1不設(shè)置寬度(我是想要頂層寬度占滿)雖然右邊浮動,但是沒有占滿頂層。設(shè)置寬度100%后,他就不浮動了 請問怎么解決? 我希望頂層寬度100%,同事右邊浮動

回答
編輯回答
久礙你

<!DOCTYPE html>
<html lang="en">

<style>
    body {
        margin: 0;
        padding: 0;
    }
    
    a {
        text-decoration: none;
    }
    
    .top_1 {
        
        width: 100%;
        height: 50px;
        background: lightgreen;
        float: right;
        overflow: hidden;
    }
    .right{
        float: right;
    }
</style>

<head>

    <meta charset="UTF-8">
    <title>Title</title>
    <link href="../css/base.css" rel='stylesheet' type='text/css' />
</head>

<body>
    
        <div class="top_1">
            <div class="right">
                用戶名:<input type="text"> 密碼: <input type="password">
                <a href="#">登錄</a>
                <a href="#">注冊</a>
            </div>
        </div>
    
    <div style="clear:both"></div>
</body>

</html>

2017年10月21日 02:00