无法在同一行上放置文本和复选框

问题描述 投票:0回答:1

我是Web开发的初学者,我有一个注册表格,其中有一个复选框可以单击以记住您的帐户。但是,我的复选框位于“记住我的文字”下方,而不是旁边。显然这是我尚未发现的CCS问题。我的提交和取消按钮在表单中也超出了范围,这可能是由于复选框问题。谢谢您在指导我解决这个问题上所提供的帮助。先感谢您 。我的代码:

.form-area{

position:absolute;
top:50%;
left:50%;
transform:translate(-50%,-50%);
width:500px;
height:600px;
box-sizing:border-box;	
background:rgb(0,0,0,0.5);
padding:40px;	
	
	
}

.imgcontainer img{
    height: 100px; /* set a default height*/
    margin-top: -75px; /* move image up fo 75px */
    border: 1px solid black; /* define a border */
    border-radius: 50%; /* make the image rounded, this works only with square images*/
	
}

.imgcontainer{
    display: flex; /* change display */
    justify-content:center;/* align to the center the image */
    /* NOTE : there is a lot of other way to align the image to the center, you can use the one that you prefer*/
}



h1{

margin:0;
padding:0 0 20px;
font-weight:bold;
color:#ffffff;
		
}	

.form-area p {

margin:0;
padding:0;
font-weight:bold;
color:#ffffff;
		
}	

.form-area input,select{

margin-bottom:20px;
width:100%;	
	
	
}	

.form area input[type=text], .form-area input[type="password"]
{

border:none;
border-bottom:1px solid #ccc;
background-color:transparent;	
outline:none;
height:40px;
color:#ffffff;
display:16px;
	
	
}	


/* Add Zoom Animation */
.animate {
  -webkit-animation: animatezoom 0.6s;
  animation: animatezoom 0.6s
}

@-webkit-keyframes animatezoom {
  from {-webkit-transform: scale(0)}
  to {-webkit-transform: scale(1)}
}

@keyframes animatezoom {
  from {transform: scale(0)}
  to {transform: scale(1)}
} 



span{

color:white;	
	
}	

::placeholder{
	
color:#ffffff	
	
}	



.form-area select{
	
margin-top:20px;
padding:10px 0;
	
	
}	


.signupbtn{

border:none;
height:40px;
outline:none;
color:#ffffff;
font-size:15px;
background-color:#4CAF50;
cursor:pointer;	
border-radius:20px;	
	
	
}	


.cancelbtn{

border:none;
height:40px;
outline:none;
color:#ffffff;
font-size:15px;
background-color:tomato;
cursor:pointer;	
border-radius:20px;	
	
	
}	



button:hover{
	
opacity:0.7;	
	
	
}	
//my full form 
<div class="form-area">

 <form action="Start_page.html" class = "sign-form animate" onsubmit="return validateform()" method = "post">
 
    <div class="imgcontainer">
       <img src="IMAGES/circleman.png" alt ="avatar" class = "Avatar">    
    </div>
 
   <div class="container">
     <h1>Sign Up</h1>
     <p>Please fill in this form to create an account.</p>
     <hr>
	 
	 
    <label for="name" ><b><span>Name<span></b></label>
    <input type="text" placeholder="Enter Name" name="onoma" id = "myname" required>
	
	
    <label for="surname" ><b><span>Surname<span></b></label>
    <input type="text" placeholder="Enter Surname" name="epith" id = "mysurname" required>

    <label for="email" ><b><span>Email<span></b></label>
    <input type="text" placeholder="Enter Email" name="email" id = "mailID" required>

    <label for="psw"><b><span>Password</span></b></label>
    <input type="password" placeholder="Enter Password" name="psw" id = "pass" required>

    <label for="psw-repeat"><b><span>Repeat Password</span></b></label>
    <input type="password" placeholder="Repeat Password" name="psw-repeat"  id = "passagain" required>
    
    //this is the issue 
    
    <label for "checkbox"><span>Remember me</span> </label>
    <input type="checkbox" value="remember-me" id="remember_me">

    <p>By creating an account you agree to our <a href="#" style="color:dodgerblue">Terms & Privacy</a>.</p>

    <div class="clearfix">
      <button type="button" class="cancelbtn" onclick = "window.location.href='Start_page.html'">Cancel</button>
      <button type="submit" class="signupbtn">Sign Up</button>
    </div>
	
   </div>
   
 </form>

 </div>
html css button checkbox
1个回答
0
投票

出现错误,因为所有标签的宽度均为100%。我为复选框类添加了具有自动宽度的新类CSS。

input#remember_me{
width:auto;
}

.form-area{

position:absolute;
top:50%;
left:50%;
transform:translate(-50%,-50%);
width:500px;
height:600px;
box-sizing:border-box;	
background:rgb(0,0,0,0.5);
padding:40px;	
	
	
}

.imgcontainer img{
    height: 100px; /* set a default height*/
    margin-top: -75px; /* move image up fo 75px */
    border: 1px solid black; /* define a border */
    border-radius: 50%; /* make the image rounded, this works only with square images*/
	
}

.imgcontainer{
    display: flex; /* change display */
    justify-content:center;/* align to the center the image */
    /* NOTE : there is a lot of other way to align the image to the center, you can use the one that you prefer*/
}



h1{

margin:0;
padding:0 0 20px;
font-weight:bold;
color:#ffffff;
		
}	

.form-area p {

margin:0;
padding:0;
font-weight:bold;
color:#ffffff;
		
}	

.form-area input,select{

margin-bottom:20px;
width:100%;	
	
	
}	

.form area input[type=text], .form-area input[type="password"]
{

border:none;
border-bottom:1px solid #ccc;
background-color:transparent;	
outline:none;
height:40px;
color:#ffffff;
display:16px;
	
	
}	


/* Add Zoom Animation */
.animate {
  -webkit-animation: animatezoom 0.6s;
  animation: animatezoom 0.6s
}

@-webkit-keyframes animatezoom {
  from {-webkit-transform: scale(0)}
  to {-webkit-transform: scale(1)}
}

@keyframes animatezoom {
  from {transform: scale(0)}
  to {transform: scale(1)}
} 



span{

color:white;	
	
}	

::placeholder{
	
color:#ffffff	
	
}	



.form-area select{
	
margin-top:20px;
padding:10px 0;
	
	
}	


.signupbtn{

border:none;
height:40px;
outline:none;
color:#ffffff;
font-size:15px;
background-color:#4CAF50;
cursor:pointer;	
border-radius:20px;	
	
	
}	


.cancelbtn{

border:none;
height:40px;
outline:none;
color:#ffffff;
font-size:15px;
background-color:tomato;
cursor:pointer;	
border-radius:20px;	
	
	
}	



button:hover{
	
opacity:0.7;	
	
	
}

input#remember_me{
width:auto;

}
//my full form 
<div class="form-area">

 <form action="Start_page.html" class = "sign-form animate" onsubmit="return validateform()" method = "post">
 
    <div class="imgcontainer">
       <img src="IMAGES/circleman.png" alt ="avatar" class = "Avatar">    
    </div>
 
   <div class="container">
     <h1>Sign Up</h1>
     <p>Please fill in this form to create an account.</p>
     <hr>
	 
	 
    <label for="name" ><b><span>Name<span></b></label>
    <input type="text" placeholder="Enter Name" name="onoma" id = "myname" required>
	
	
    <label for="surname" ><b><span>Surname<span></b></label>
    <input type="text" placeholder="Enter Surname" name="epith" id = "mysurname" required>

    <label for="email" ><b><span>Email<span></b></label>
    <input type="text" placeholder="Enter Email" name="email" id = "mailID" required>

    <label for="psw"><b><span>Password</span></b></label>
    <input type="password" placeholder="Enter Password" name="psw" id = "pass" required>

    <label for="psw-repeat"><b><span>Repeat Password</span></b></label>
    <input type="password" placeholder="Repeat Password" name="psw-repeat"  id = "passagain" required>
    

    <div>
    <label for "checkbox"><span>Remember me</span> </label>
    <input type="checkbox" value="remember-me" id="remember_me">
    </div>
    <p>By creating an account you agree to our <a href="#" style="color:dodgerblue">Terms & Privacy</a>.</p>

    <div class="clearfix">
      <button type="button" class="cancelbtn" onclick = "window.location.href='Start_page.html'">Cancel</button>
      <button type="submit" class="signupbtn">Sign Up</button>
    </div>
	
   </div>
   
 </form>

 </div>
© www.soinside.com 2019 - 2024. All rights reserved.