我正在练习HTML和CSS。我有一个与以下代码相关的问题 -
.outer_class{
position: absolute;
width: 50%;
height: 30%;
top: 35%;
left: 25%;
background-color: red;
}
.inner_class{
position: relative;
width: 50%;
height: 50%;
top: 25%;
left: 25%;
background-color: yellow;
}
.div_input{
position: relative;
width: 70%;
height: 50%;
top: 25%;
left: 15%;
background-color: blue;
}
input[type="text"]{
box-sizing: border-box;
width: 100%;
height: 100%;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Align_Textbox_To_Div_Center</title>
<!--++++++++++++++++++++++Bootstrap CDN(Content Delivery Network)++++++++++++++++++++++++++++++-->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
<div class="outer_class">
<div class="inner_class">
<div class="div_input">
<input type="text" name="username">
</div>
</div>
</div>
</body>
</html>
现在,当我将浏览器窗口的大小调整到最小时,会显示一点蓝色div。为什么这样,我该如何解决?
提前致谢!
答案 0 :(得分:1)
添加
输入[类型= “文本”] {
位置:绝对的;
边界:无;
}
.outer_class{
position: absolute;
width: 50%;
height: 30%;
top: 35%;
left: 25%;
background-color: red;
}
.inner_class{
position: relative;
width: 50%;
height: 50%;
top: 25%;
left: 25%;
background-color: yellow;
}
.div_input{
position: relative;
width: 70%;
height: 50%;
top: 25%;
left: 15%;
background:blue;
}
input[type="text"]{
box-sizing: border-box;
width: 100%;
height: 100%;
position:absolute;
border:none;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Align_Textbox_To_Div_Center</title>
<!--++++++++++++++++++++++Bootstrap CDN(Content Delivery Network)++++++++++++++++++++++++++++++-->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
<div class="outer_class">
<div class="inner_class">
<div class="div_input">
<input type="text" name="username">
</div>
</div>
</div>
</body>
</html>