I'm creating a webpage for my internship and i need a login and password form. I animated the text boxes like this:
input[type=text] {
z-index: 10;
width: 30px;
position: absolute;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background-color: white;
background-position: 10px 10px;
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
height: 30px;
display: block;
}
input[type=text]:focus {
width: 130px;
}
<input type="text" name="username" placeholder="User.." size="30" />
And then I inserted the table in a div and did the same thing to the password
#login {
position: absolute;
font-family: "Times New Roman", Times, serif;
font-weight: bold;
text-align: left;
right:350px;
bottom:5px;
height: 200px;
width:200px;
}
input[type=text] {
z-index: 10;
width: 30px;
position: absolute;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background-color: white;
background-position: 10px 10px;
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
height: 30px;
display: block;
}
input[type=text]:focus {
width: 130px;
}
input[type=password] {
z-index: 10;
width: 30px;
position: absolute;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background-color: white;
background-image: url('searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
display: block;
height: 30px;
}
input[type=password]:focus {
width: 130px;
}
<div id="login">
<form name="frmLogin" method="post" action="">
<br><br>
<table width="100" align="center">
<tr>
<td>Username:</td>
<td><input type="text" name="username" placeholder="User.." size="30" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" placeholder="Pass.." size="30" /></td>
</tr>
</table>
<input type="hidden" name="acao" value="login" />
</form>
So now you can see my problem in the snippet, the login and password forms are overlaying each other and i want to have a little space between them.
#login {
/*position: absolute;*/
font-family: "Times New Roman", Times, serif;
font-weight: bold;
text-align: left;
right:350px;
bottom:5px;
height: 200px;
width:200px;
}
input[type=text] {
z-index: 10;
width: 30px;
/*position: absolute;*/
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background-color: white;
background-position: 10px 10px;
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
height: 30px;
display: block;
}
input[type=text]:focus {
width: 130px;
}
input[type=password] {
z-index: 10;
width: 30px;
/*position: absolute;*/
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background-color: white;
background-image: url('searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
display: block;
height: 30px;
}
input[type=password]:focus {
width: 130px;
}
<div id="login">
<form name="frmLogin" method="post" action="">
<br><br>
<table width="100" align="center">
<tr>
<td>Username:</td>
<td><input type="text" name="username" placeholder="User.." size="30" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" placeholder="Pass.." size="30" /></td>
</tr>
</table>
<input type="hidden" name="acao" value="login" />
</form>
The problem here is position:absolute. Depending on your usage, you can make it work with position absolute as well, But you will have to declare height. For now, I've just removed the position. Hope this helps.
Remove position absolute from both input css
#login {
position: absolute;
font-family: "Times New Roman", Times, serif;
font-weight: bold;
text-align: left;
right:350px;
bottom:5px;
height: 200px;
width:200px;
}
input[type=text] {
z-index: 10;
width: 30px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background-color: white;
background-position: 10px 10px;
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
height: 30px;
display: block;
}
input[type=text]:focus {
width: 130px;
}
input[type=password] {
z-index: 10;
width: 30px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background-color: white;
background-image: url('searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
display: block;
height: 30px;
}
input[type=password]:focus {
width: 130px;
}
<div id="login">
<form name="frmLogin" method="post" action="">
<br><br>
<table width="100" align="center">
<tr>
<td>Username:</td>
<td><input type="text" name="username" placeholder="User.." size="30" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" placeholder="Pass.." size="30" /></td>
</tr>
</table>
<input type="hidden" name="acao" value="login" />
</form>
You can either remove the position:absolute, position:absolute makes your elements get out of the normal positioning on the page. In this case it removed the spacing between them and placed the input boxes lower than the table lables.
If you want that, you can fix this by changing the margin of your password field like Keerthana Prabhakaran mentioned in the comment.
Related
Ok, having some weird CSS problems here trying to achieve this, having a warning thing to the right of each horizontally CENTERED input field:
Right now I have the centered inputs, but no matter what I do with float or even transform or translate on the .warning div, I can't achieve this.
.warning {
display: none;
margin-top: 10px;
}
.warning p {
color: #e85748;
display: none;
transform: translateX(105%) translateY(232%);
}
.ico-circle {
width: 40px;
position: absolute;
height: 40px;
border-radius: 50%;
transform: translateX(720%) translateY(22%);
background: #e85748;
}
textarea {
border: 2px solid #a0b3b0;
resize: vertical;
}
.field-wrap {
position: relative;
width: 50%;
float: center;
margin: auto;
margin-bottom: 9px;
}
input,
textarea {
padding: 15px 15px;
display: block;
margin: auto;
width: 200px;
/* height: 100%; */
color: #333333;
border-color: #333333;
border-radius: 15px;
-webkit-transition: border-color .25s ease, box-shadow .25s ease;
transition: border-color .25s ease, box-shadow .25s ease;
border-radius: 30px;
font-size: 16px;
font-weight: 500;
border: 4px solid #333333;
line-height: 1.3;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
text-indent: 13px;
flex: 0 0 160px;
width: 200px;
background-color: transparent;
}
input:focus {
outline: none !important;
border: 4px solid #e85748;
width: 250px;
-webkit-transition: width .25s ease;
transition: width .25s ease;
}
<div class="field-wrap">
<input id="username" type="text" placeholder="Username" required autocomplete="off">
<div class="warning" />
<p>Hello world</p>
<div class="ico-circle">
</div>
</div>
</div>
<div class="field-wrap">
<input type="password" placeholder="Password" required autocomplete="off">
<div class="warning">
<p>Hello world</p>
<div class="ico-circle">
</div>
</input>
</div>
Register
</i>Wait, take me back
What am I doing wrong here?
You can do it with flexbox but i'm not sure how you want it to present when the inputs are wider and/or have the warning beside it. Perhaps this will be sufficient to point you in the right direction:
.warning {
display: none;
}
.warning p {
color: #e85748;
}
.ico-circle {
width: 40px;
height: 40px;
border-radius: 50%;
background: #e85748;
order: -1;
}
textarea {
border: 2px solid #a0b3b0;
resize: vertical;
}
.field-wrap {
display: flex;
position: relative;
margin-bottom: 9px;
}
input,
textarea {
padding: 15px 15px;
margin: auto;
width: 200px;
/* height: 100%; */
color: #333333;
border-color: #333333;
border-radius: 15px;
-webkit-transition: border-color .25s ease, box-shadow .25s ease;
transition: border-color .25s ease, box-shadow .25s ease;
border-radius: 30px;
font-size: 16px;
font-weight: 500;
border: 4px solid #333333;
line-height: 1.3;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
text-indent: 13px;
width: 200px;
background-color: transparent;
}
input:focus {
outline: none !important;
border: 4px solid #e85748;
width: 250px;
-webkit-transition: width .25s ease;
transition: width .25s ease;
}
input:focus:invalid+.warning {
display: flex;
}
<div class="field-wrap">
<input id="username" type="text" placeholder="Username" required autocomplete="off" />
<div class="warning">
<p>Hello world</p>
<div class="ico-circle">
</div>
</div>
</div>
<div class="field-wrap">
<input type="password" placeholder="Password" required autocomplete="off" />
<div class="warning">
<p>Hello world</p>
<div class="ico-circle">
</div>
</div>
</div>
Register
</i>Wait, take me back
I am using following code and code work fine. but i wanna that when user click on search button then search button will also show like stackoverflow search bar has.
HTML :-
<form>
<input type="text" name="search" placeholder="Search..">
</form>
CSS
input[type=text] {
display:block;
margin: 0 0 0 auto;
width: 250px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background-color: white;
background-image: url('/searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
}
input[type=text]:focus {
width: 100%;
}
Follow these steps
Create a button
Place that button on the search bar
set display property of that button to none
now whenever you focus on the search bar, change display property of that button to block
try implementing this code on your own first ...
input[type=text] {
display:block;
margin: 0 0 0 auto;
width: 250px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background-color: white;
background-image: url('/searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
}
input[type=text]:focus {
width: 90%;
}
input[type=text]:focus + .but{
display: block;
}
.but{
cursor:pointer;
width: 100px;
height: 50px;
position: absolute;
right:5px;
top:5px;
display:none;
}
<form>
<input type="text" name="search" placeholder="Search.."><input class="but" type="button" value = "search">
</form>
My box is expanding to the right, how can I make it expand to the left?
input[type=text] {
width: 130px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background-color: white;
background-image: url('searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
}
input[type=text]:focus {
width: 100%;
}
<form>
<input type="text" name="search" placeholder="Search..">
</form>
Just align it to the right of its container element. Either change the display attribute to block and set the right and left margins to 0 and auto, or keep it as an inline element and apply text-align: right to the container block.
input[type=text] {
display:block;
margin: 0 0 0 auto;
width: 130px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background-color: white;
background-image: url('searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
}
input[type=text]:focus {
width: 100%;
}
<form>
<input type="text" name="search" placeholder="Search..">
</form>
so I have a modal on my site and it opens fine and everything but there is one problem ... it opens for a second then closes on page load. How can I fix this? It is powered by CSS and not JavaScript. The button you press to open the modal is included in my navigation bar.
Modal HTML:
<div id="JoinUs" data-toggle="modal" class="modalDialog">
<div>
X
<h4>Join Us!</h4>
<input type="text" id="fieldUser" class="input" required pattern=.*\S.* />
<label for="fieldUser" class="label">Username</label>
<input type="password" id="fieldPassword" class="input" required pattern=.*\S.* />
<label for="fieldPassword" class="label">Password</label>
<button class="btn">Login</button>
</div>
</div>
Modal CSS:
.modalDialog {
position: fixed;
font-family: Arial, Helvetica, sans-serif;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: rgba(0,0,0,0.8);
z-index: 99999;
opacity:0;
-webkit-transition: opacity 400ms ease-in;
-moz-transition: opacity 400ms ease-in;
transition: opacity 400ms ease-in;
pointer-events: none;
}
.modalDialog:target {
opacity:1;
pointer-events: auto;
}
.modalDialog > div {
width: 400px;
position: relative;
margin: 10% auto;
padding: 5px 20px 13px 20px;
border-radius: 10px;
background: #fff;
background-color: #fff;
}
.close {
background: #606061;
color: #FFFFFF;
line-height: 25px;
position: absolute;
right: -12px;
text-align: center;
top: -10px;
width: 24px;
text-decoration: none;
font-weight: bold;
-webkit-border-radius: 12px;
-moz-border-radius: 12px;
border-radius: 12px;
-moz-box-shadow: 1px 1px 3px #000;
-webkit-box-shadow: 1px 1px 3px #000;
box-shadow: 1px 1px 3px #000;
}
.close:hover { background: #2ecc71; }
input[type=text] {
margin-left: 63%;
margin-top: -100%;
width: 130px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background-color: black;
background-image: url('searchicon.png');
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
}
input[type=text]:focus {
width: 150px;
}
<form>
<input type="text" name="search" placeholder="Search..">
</form>
even after puttin margin-top -100% the search box is not going up. it stopped going up after -10%. Any help would be highly appreciated. Thanks in advance. :)
Use "position:relative" and "top:-100px". It will move your search box to move up. You can increase the 'top' value as you need.
input[type=text] {
margin-left: 63%;
width: 130px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background-color: black;
background-image: url('searchicon.png');
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
position: relative;
top: -100px;
}
input[type=text]:focus {
width: 150px;
}