Hover effects on Form Placeholder Text - html

I am trying to change the color of the placeholder text of a contact form when hovering over it. Is this possible using only html/CSS or is javascript necessary?
You will see in the code below that I have put each input field of the contact form within its own div in order structure it properly on the page, which results in some long and messy code. But otherwise it has worked well. I have the background of the input fields set to change when hovering.
What I don't understand is why using the hover selector on the form to make the text bold works on BOTH the placeholder text and the input text; however, changing the color on hover works ONLY on the input text and NOT to placeholder.
I tried nesting the ::placeholder selector (as well as its counterparts for various web browsers) inside the hover selector in the SCSS document to change the color when hovering but with no luck.
Does anyone have any advice for how to make this placeholder text color change when hovering?
I included some images of the site and my code below.
Thanks!
Contact form as is.
Contact form on hover; placeholder text color not changing.
HTML & CSS CODE
.contact-form {
text-align: center;
justify-content: center;
position: relative;
}
.name {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 40vw;
padding: 0;
}
.first {
float:left;
width: 50%;
padding: 0.5em;
padding-left: 0;
margin: 0;
}
.form-control-first {
color: #878F93;
background-color: white;
border: none;
border-radius: 1em;
box-shadow: rgba(0, 0, 0, 0.1) 0em 0em 1em 0em;
padding: 1em;
font-family: Circe;
font-weight: 300;
font-size: 1em;
margin-top: 1em;
margin-bottom: 1em;
width: 100%;
}
.form-control-first:hover {
color: white;
font-weight: 600;
background-color: #AEBDB2;
cursor: pointer;
}
.form-control-first:focus {
outline: none;
pointer-events: none;
}
.last {
float:left;
width: 50%;
padding: 0.5em;
padding-right: 0;
margin: 0;
}
.form-control-last {
background-color: white;
color: #878F93;
border: none;
border-radius: 1em;
box-shadow: rgba(0, 0, 0, 0.1) 0em 0em 1em 0em;
padding: 1em;
font-family: Circe;
font-weight: 300;
font-size: 1em;
margin-top: 1em;
margin-bottom: 1em;
width: 100%;
}
.form-control-last:hover {
color: white;
font-weight: 600;
background-color: #AEBDB2;
cursor: pointer;
}
.form-control-last:focus {
outline: none;
pointer-events: none;
}
.email-message {
position: relative;
top: 5.5em;
bottom: 0;
left: 0;
right: 0;
padding-top: 0em;
margin: auto;
width: 40vw;
}
.form-control-email {
background-color: white;
color: #878F93;
border: none;
border-radius: 1em;
box-shadow: rgba(0, 0, 0, 0.1) 0em 0em 1em 0em;
padding: 1em;
font-family: Circe;
font-weight: 300;
font-size: 1em;
margin: 0;
margin-top: 0.5em;
margin-bottom: 0.5em;
width: 100%;
}
.form-control-email:hover {
color: white;
font-weight: 600;
background-color: #AEBDB2;
cursor: pointer;
}
.form-control-email:focus {
outline: none;
pointer-events: none;
}
.form-control-message {
background-color: white;
color: #878F93;
border: none;
border-radius: 1em;
box-shadow: rgba(0, 0, 0, 0.1) 0em 0em 1em 0em;
padding: 1em;
text-align: left;
font-family: Circe;
font-weight: 300;
font-size: 1em;
margin: 0;
margin-top: 0.5em;
margin-bottom: 0.5em;
width: 100%;
height: 30vh;
max-width: 100%;
max-height: 30vh;
}
.form-control-message:hover {
color: white;
font-weight: 600;
background-color: #AEBDB2;
cursor: pointer;
}
.form-control-message:focus {
outline: none;
pointer-events: none;
}
.form-control-submit {
justify-content: center;
align-items: center;
padding: 0.75em;
padding-left: 2em;
padding-right: 2em;
font-family: Circe;
font-weight: bold;
font-size: 0.75em;
text-transform: uppercase;
color:white;
border-radius: 2em;
background-color: #207CB4;
border: none;
display: inline-block;
margin: 0px, 2px;
text-decoration: none;
}
.form-control-submit:hover {
color: #174456;
background-color: #FFE98E;
cursor: pointer;
}
::-webkit-input-placeholder { /* WebKit, Blink, Edge */
color: #878F93;
}
:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
color: #878F93;
opacity: 1;
}
::-moz-placeholder { /* Mozilla Firefox 19+ */
color: #878F93;
opacity: 1;
}
:-ms-input-placeholder { /* Internet Explorer 10-11 */
color: #878F93;
}
::-ms-input-placeholder { /* Microsoft Edge */
color: #878F93;
}
::placeholder { /* Most modern browsers support this now. */
color: #878F93;
}
<div class="contact-form">
<form id="contact-form" method="post">
<div class="name">
<div class="first">
<input name="first-name" type="text" class="form-control-first" placeholder="First Name" required>
</div>
<div class="last">
<input name="last-name" type="text" class="form-control-last" placeholder="Last Name" required>
</div>
<br>
</div>
<div class="email-message">
<input name="email" type="text" class="form-control-email" placeholder="Email" required>
<br>
<textarea name="message" class="form-control-message" placeholder="Type your message here." row="4" required></textarea>
<br>
<input type="submit" class="form-control-submit" value="Submit"></div>
</form>
</div>

This worked for me!
.input {
}
.input::placeholder {
color: red;
}
.input:hover::placeholder {
color: blue;
}

Related

How to change the layout of a sign-up page

I'm trying to change my sign-up page so that the avatar is to the left and the username, password boxes etc are to the right. I've tried using split divs but this doesn't seem to work. I've also tried positioning the avatar to the left but that also hasn't worked. Here is my style and body code.
body {
font-family: Arial, Helvetica, sans-serif;
}
form {
border: 3px solid #f1f1f1;
}
* {
margin: 0;
padding: 0;
}
#logo {
float: left;
display: inline-block;
object-fit: none;
background: transparent;
padding-bottom: 0;
padding-top: 0;
padding-left: 10px;
}
.navbar {
overflow: hidden;
background-color: #D47ACE;
position: fixed;
top: 0;
width: 100%;
z-index: 1001;
}
.navbar-logo {
font-size: 25px;
word-spacing: 0px;
}
.navbar a {
float: left;
display: block;
color: white;
text-align: center;
padding: 15px 18px;
text-decoration: none;
font-size: 23px;
font-style: normal;
font-family: "Rockwell", Monaco, monospace;
letter-spacing: 0px;
word-spacing: 5px;
font-weight: 700;
}
#nav li {
display: inline;
padding-right: 30px;
}
.navbar a:hover {
color: #ffffff;
}
#demoFont {
font-family: "Lucida Console", Monaco, monospace;
font-size: 29px;
letter-spacing: 5.2px;
word-spacing: 2px;
color: #000000;
font-weight: 700;
text-decoration: none;
font-style: normal;
font-variant: normal;
text-transform: uppercase;
}
input[type=text],
input[type=password] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
}
button {
background-color: pink;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
width: 100%;
}
button:hover {
opacity: 0.8;
}
.cancelbtn {
width: auto;
padding: 10px 18px;
background-color: #f44336;
}
.imgcontainer {
text-align: center;
margin: 24px 0 12px 0;
}
img.avatar {
width: 40%;
border-radius: 50%;
padding-top: 10vh;
padding-bottom: 0vh;
}
.container {
padding: 16px;
}
span.psw {
float: right;
padding-top: 16px;
}
.button {
background-color: pink;
}
/* Change styles for span and cancel button on extra small screens */
#media screen and (max-width: 300px) {
span.psw {
display: block;
float: none;
}
.cancelbtn {
width: 100%;
}
}
<form action="/action_page.php" method="post">
<div class="imgcontainer">
<img src="https://via.placeholder.com/568" alt="Avatar" class="avatar">
</div>
<div class="container">
<label for="uname"><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="uname" required>
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>
<button type="submit">Enter</button>
<label>
<input type="checkbox" checked="checked" name="remember"> Remember me
</label>
</div>
<div class="container" style="background-color:#f1f1f1">
<button type="button" class="cancelbtn">Cancel</button>
<span class="psw">Forgot password?</span>
</div>
</form>
Any help would be great.
You can use display: flex; property as shown in the below sample.
body {
font-family: Arial, Helvetica, sans-serif;
}
form {
border: 3px solid #f1f1f1;
}
* {
margin: 0;
padding: 0;
}
.d-flex{
display: flex;
flex-wrap: wrap;
align-items: center;
}
.img-container, .input-container {
width: 50%;
}
.img-container {
text-align: center;
}
#logo {
display: inline-block;
object-fit: none;
background: transparent;
padding-bottom: 0;
padding-top: 0;
padding-left: 10px;
}
.navbar {
overflow: hidden;
background-color: #D47ACE;
position: fixed;
top: 0;
width: 100%;
z-index: 1001;
}
.navbar-logo {
font-size: 25px;
word-spacing: 0px;
}
.navbar a {
float: left;
display: block;
color: white;
text-align: center;
padding: 15px 18px;
text-decoration: none;
font-size: 23px;
font-style: normal;
font-family: "Rockwell", Monaco, monospace;
letter-spacing: 0px;
word-spacing: 5px;
font-weight: 700;
}
#nav li {
display: inline;
padding-right: 30px;
}
.navbar a:hover {
color: #ffffff;
}
#demoFont {
font-family: "Lucida Console", Monaco, monospace;
font-size: 29px;
letter-spacing: 5.2px;
word-spacing: 2px;
color: #000000;
font-weight: 700;
text-decoration: none;
font-style: normal;
font-variant: normal;
text-transform: uppercase;
}
input[type=text],
input[type=password] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
}
button {
background-color: pink;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
width: 100%;
}
button:hover {
opacity: 0.8;
}
.cancelbtn {
width: auto;
padding: 10px 18px;
background-color: #f44336;
}
.imgcontainer {
text-align: center;
margin: 24px 0 12px 0;
}
img.avatar {
width: 40%;
border-radius: 50%;
padding-top: 10vh;
padding-bottom: 0vh;
}
.container {
padding: 16px;
}
span.psw {
float: right;
padding-top: 16px;
}
.button {
background-color: pink;
}
/* Change styles for span and cancel button on extra small screens */
#media screen and (max-width: 300px) {
span.psw {
display: block;
float: none;
}
.cancelbtn {
width: 100%;
}
}
<form action="/action_page.php" method="post" class="d-flex">
<div class="img-container">
<img src="https://via.placeholder.com/140x100" alt="Avatar" class="avatar">
</div>
<div class="input-container">
<div class="container">
<label for="uname"><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="uname" required>
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>
<button type="submit">Enter</button>
<label>
<input type="checkbox" checked="checked" name="remember"> Remember me
</label>
</div>
<div class="container" style="background-color:#f1f1f1">
<button type="button" class="cancelbtn">Cancel</button>
<span class="psw">Forgot password?</span>
</div>
</div>
</form>
One thing you can do is add a display: flex on the form, setting its contents to wrap when there is no more available space on the line. Then you can set a width of 100% on the last .container which is housing the cancel button and forgotten password link, forcing it to a new line.
Here is that new CSS:
form {
display: flex;
flex-wrap: wrap;
align-items: center;
}
.imgcontainer .avatar {
padding-top: 0;
}
/* .imgcontainer+.container means the .container adjacent to `.imgcontainer */
.imgcontainer,
.imgcontainer+.container {
flex: 1;
}
/* .container+.container means the last .container in your case */
.container+.container {
width: 100%;
}
Which produces:
Demo
form {
display: flex;
flex-wrap: wrap;
align-items: center;
}
.imgcontainer,
.imgcontainer+.container {
flex: 1;
}
.imgcontainer .avatar {
padding-top: 0;
}
.container+.container {
width: 100%;
}
body {
font-family: Arial, Helvetica, sans-serif;
}
form {
border: 3px solid #f1f1f1;
}
* {
margin: 0;
padding: 0;
}
#logo {
float: left;
display: inline-block;
object-fit: none;
background: transparent;
padding-bottom: 0;
padding-top: 0;
padding-left: 10px;
}
.navbar {
overflow: hidden;
background-color: #D47ACE;
position: fixed;
top: 0;
width: 100%;
z-index: 1001;
}
.navbar-logo {
font-size: 25px;
word-spacing: 0px;
}
.navbar a {
float: left;
display: block;
color: white;
text-align: center;
padding: 15px 18px;
text-decoration: none;
font-size: 23px;
font-style: normal;
font-family: "Rockwell", Monaco, monospace;
letter-spacing: 0px;
word-spacing: 5px;
font-weight: 700;
}
#nav li {
display: inline;
padding-right: 30px;
}
.navbar a:hover {
color: #ffffff;
}
#demoFont {
font-family: "Lucida Console", Monaco, monospace;
font-size: 29px;
letter-spacing: 5.2px;
word-spacing: 2px;
color: #000000;
font-weight: 700;
text-decoration: none;
font-style: normal;
font-variant: normal;
text-transform: uppercase;
}
input[type=text],
input[type=password] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
}
button {
background-color: pink;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
width: 100%;
}
button:hover {
opacity: 0.8;
}
.cancelbtn {
width: auto;
padding: 10px 18px;
background-color: #f44336;
}
.imgcontainer {
text-align: center;
margin: 24px 0 12px 0;
}
img.avatar {
width: 40%;
border-radius: 50%;
padding-top: 10vh;
padding-bottom: 0vh;
}
.container {
padding: 16px;
}
span.psw {
float: right;
padding-top: 16px;
}
.button {
background-color: pink;
}
/* Change styles for span and cancel button on extra small screens */
#media screen and (max-width: 300px) {
span.psw {
display: block;
float: none;
}
.cancelbtn {
width: 100%;
}
}
<form action="/action_page.php" method="post">
<div class="imgcontainer">
<img src="https://via.placeholder.com/568" alt="Avatar" class="avatar">
</div>
<div class="container">
<label for="uname"><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="uname" required>
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>
<button type="submit">Enter</button>
<label>
<input type="checkbox" checked="checked" name="remember"> Remember me
</label>
</div>
<div class="container" style="background-color:#f1f1f1">
<button type="button" class="cancelbtn">Cancel</button>
<span class="psw">Forgot password?</span>
</div>
</form>

CSS: Fix positioning of input in Log-In form

I'm trying fix the Log-In & registration form. When you click on "Register" on my menu, you can see that the labels are perfectly formatted in the form but the input box are offset. I tried to fix it with float:left but it didn't work out too well. If somebody could help me with that, that would be awesome.
var popup = document.getElementById('id01');
var popupreg = document.getElementById('id02');
window.onclick = function(event) {
if (event.target == popup) {
popup.style.display = "none";
}
if (event.target == popupreg) {
popupreg.style.display = "none";
}
}
body {
margin: 0 auto;
background: #fff;
}
div.container {
text-align: center;
box-sizing: border-box;
margin: 0 auto;
padding: 5px;
background-color: #000;
}
a.nounderline span {
color: #00B200;
}
.main-menu {
width: 200px;
margin: 0 auto;
right: 26px;
position: fixed;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
height: 35%;
}
.floating-sidebar li {
text-decoration: none;
outline: none;
line-height: 2em;
display: block;
border-radius: auto;
position: relative;
top: 10px;
-webkit-transition: none;
-o-transition: none;
transition: none;
}
.floating-sidebar li a {
background-color: #fff;
color: #444950;
display: block;
padding: 7px;
text-decoration: none;
font-family: Arial, sans-serif;
font-size: 18;
font-weight: bold;
border-radius: 9px;
}
.floating-sidebar li a:hover {
background-color: #eee;
color: #00B200;
}
.floating-sidebar li a.active {
background-color: #eee;
color: #00B200;
}
.floating-sidebar:hover li a.register-link {
color: #b5e7a0;
background: #fff;
}
.floating-sidebar li a.active:hover {
background-color: #00B200;
color: #fff;
}
.topnav input[type=text] {
float: left;
padding: 4.5px;
padding-left: 28px;
width: 305px;
border: 2px solid #00B200;
border-radius: 18px;
outline: inherit;
margin-top: 80px;
margin-left: 115px;
font-family: Arial, sans-serif;
font-weight: bold;
font-size: 18px;
direction: inherit;
}
input::placeholder {
color: #BEBEBE;
}
span.topnav {
right: 50px;
}
.sortby-box {
padding-top: 124px;
padding-left: 44;
margin: 0 auto;
position: fixed;
}
.select-opt {
padding: 4px;
width: 120px;
border-radius: 8px;
outline: none;
border: 1px solid #00B200;
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
}
.select-opt option {
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
}
.popup,
.popupreg {
display: none;
position: fixed;
/* Stay in place */
z-index: 1;
/* Sit on top */
left: 0;
top: 0;
width: 100%;
/* Full width */
height: 100%;
/* Full height */
overflow: auto;
/* Enable scroll if needed */
background-color: rgb(0, 0, 0);
/* Fallback color */
background-color: rgba(0, 0, 0, 0.8);
/* Black w/ opacity */
padding-top: 60px;
}
.popup-content,
.popupreg-content {
float: left;
position: fixed;
background-color: rgb(245, 245, 245);
width: 600px;
height: 400px;
border-radius: 39px;
left: 666px;
top: 210px;
border: 2px solid rgb(109, 196, 109);
}
.popup,
.popupreg label {
font-family: Arial, Helvetica, sans-serif;
}
.popup [type=text],
[type=password] {
padding: 6px 8px;
width: 250px;
border-radius: 12px;
border: 1px solid gray;
outline: none;
margin: 10px 0;
margin-left: 15px;
box-sizing: border-box;
}
.popupreg [type=text],
[type=password] {
padding: 6px 8px;
width: 250px;
border-radius: 12px;
border: 1px solid gray;
outline: none;
margin: 10px 0;
margin-left: 15px;
box-sizing: border-box;
}
.popup input[type=submit] {
padding: 8px;
border-radius: 12px;
border: 1px solid gray;
outline: none;
}
.popupreg input[type=submit] {
padding: 8px;
border-radius: 12px;
border: 1px solid gray;
outline: none;
}
.popup [type=submit] {
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
background-color: #fff;
color: #00B200;
font-size: 22px;
padding: 180px;
margin-left: 88px;
margin-top: 5px;
width: 250px;
height: 60px;
}
.popupreg [type=submit] {
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
background-color: #fff;
color: #00B200;
font-size: 22px;
padding: 180px;
margin-left: 88px;
margin-top: 5px;
width: 250px;
height: 60px;
}
.popup .submit-log:hover {
color: #fff;
background-color: #00B200;
cursor: pointer;
}
.popupreg .submit-log:hover {
color: #fff;
background-color: #00B200;
cursor: pointer;
}
.cancel {
text-align: right;
position: relative;
cursor: pointer;
}
.close {
position: absolute;
right: 25px;
top: 0;
color: #000;
font-size: 35px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: red;
cursor: pointer;
}
.username-section,
.reg-section {
padding: 32px;
margin-left: 75px;
margin-top: 20px;
}
span.psswrd {
float: right;
padding-top: 16px;
}
#media screen and (max-width: 300px) {
span.psw {
display: block;
float: none;
}
.cancelbtn {
width: 100%;
}
}
<header>
<div class="container">
Hello
</div>
</header>
<main>
<aside>
</aside>
</main>
<sidebar>
<div class="main-menu">
<ul class="floating-sidebar">
<li>Log In</li>
<li>Register</li>
<li>About</li>
<li>Language</li>
</ul>
</div>
</sidebar>
<div class="sortby-box">
<select class="select-opt">
<option>Newest</option>
<option>Popularity</option>
<option>Recommended</option>
</select>
</div>
<div class="topnav">
<input style="position:relative;" type="text" name: "searchText" placeholder="Search here.." maxlength="18">
<span style="position:absolute; left: 126px; top: 119px;" class="fa fa-search icon"></span>
</div>
<div id="id01" class="popup">
<form class="popup-content" action="/action_page.php" method="get">
<div class="cancel">
<span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">×</span>
</div>
<div class="username-section">
<label for="usrname">Username</label>
<input type="text" id="usrname" name="usrname" minlength="6" maxlength="20"><br><br>
<label for="psswrd">Password</label>
<input type="password" id="passwrd" name="psswrd" minlength="6" maxlength="20"><br><br>
<input type="submit" class="submit-log" value="Log In">
</div>
</form>
</div>
<div id="id02" class="popupreg">
<form class="popupreg-content" action="/action_page.php" method="get">
<div class="cancel">
<span onclick="document.getElementById('id02').style.display='none'" class="close" title="Close Modal">×</span>
</div>
<div class="reg-section">
<label for="usrname">Username</label>
<input type="text" id="usrname" name="usrname" minlength="6" maxlength="20"><br><br>
<label for="usrname">Mail</label>
<input type="text" id="mail" name="mail" minlength="6" maxlength="20"><br><br>
<label for="psswrd">Password</label>
<input type="password" id="passwrd" name="psswrd" minlength="6" maxlength="20"><br><br>
<input type="submit" class="submit-log" value="Register">
</div>
</form>
</div>
<script src="index.js"></script>
<footer>
</footer>
A simple fix would be to give the label elements a display: inline-block; and give them a defined width such as width: 100px;.
I quickly created a JSFiddle to illustrate.
Hope this helped.

text field and button in same line

I want to put text field and button on the same line.
I used display: inline; but it's not working. Where am i making a mistake?
.listBar {
position: absolute;
left: 40px;
top: 210px;
box-sizing: border-box;
}
#input {
width: 100%;
font-size: 16px;
border: none;
background-color: aliceblue;
padding: 14px;
float: left;
}
#add {
color: whitesmoke;
border: none;
background-color: inherit;
padding: 14px 20px;
font-size: 16px;
cursor: pointer;
float: left;
}
#add,
#input {
display: inline;
}
<div class='listBar'>
<h2 class='header' style='margin:5px'> List </h2>
<input type='text' id='input' placeholder="Title">
<button id='add'> Add </button>
</div>
it's because you have width: 100% on the input. It makes it take all the place and there is none left for your button. It will work if you remove the width there or set it to auto. Also, be careful with the second float, that one should be right, not left.
.listBar{
position: absolute;
left: 40px;
top: 210px;
box-sizing: border-box;}
#input{
font-size: 16px;
border: none;
background-color: aliceblue;
padding: 14px;
float: left;}
#add{
color: whitesmoke;
border: none;
background-color: inherit;
padding: 14px 20px;
font-size: 16px;
cursor: pointer;
float: right;}
#add, #input{
display: inline;}
You don't need the floats to do that, your input has a width of 100% that's why display inline didn't work, And the h2 is also block by default so you need to set it's display to inline or inline-block as well
.listBar {
position: absolute;
left: 40px;
top: 210px;
box-sizing: border-box;
}
#input {
font-size: 16px;
border: none;
background-color: aliceblue;
padding: 14px;
}
#add {
color: black;
border: none;
background-color: lightgrey;
padding: 14px 20px;
font-size: 16px;
cursor: pointer;
}
#add, #input {
display: inline;
}
<div class='listBar'>
<h2 class='header' style='margin:5px'> List </h2>
<input type='text' id='input' placeholder="Title">
<button id='add'> Add </button>
It was right that if the input text field takes 100% of the parent's width, there will be no room for the button. In addition, there is no need of display: inline. You can put the text field and a button in the same line just by adding the float: left in both elements classes and by increasing the width of the main div class element :) .....
.listBar{
position: absolute;
left: 40px;
top: 210px;
width: 30%;
box-sizing: border-box;
}
.header {
color: whitesmoke;
text-align: left;
}
/* add button */
#add{
color: whitesmoke;
border: none;
background-color: inherit;
padding: 14px 20px;
font-size: 16px;
cursor: pointer;
float: left;
}
#add:hover{
background-color: rgb(85, 78, 78);
}
/* input text field */
#input{
width: 75%;
font-size: 16px;
border: none;
background-color: aliceblue;
padding: 14px;
float: left;
}
here is snippet
The problem here is that input takes width: 100%; of its parent. So there is no more room for a button on its side.
Here is a working snippet with comments:
(That's how I'll do to correct the problem if it was for myself)
body { /* Added only for snippet */
background: #ddd;
}
.listBar {
position: absolute;
background: #bbb; /* Added only for snippet */
left: 40px;
top: 20px; /* Modified only for snippet */
box-sizing: border-box;
}
#input {
width: auto; /* Modified, you could also simply remove this line */
font-size: 16px;
border: none;
background-color: aliceblue;
padding: 14px;
float: left;
}
#add {
color: whitesmoke;
border: none;
background-color: inherit;
padding: 14px 20px;
font-size: 16px;
cursor: pointer;
float: right; /* Floating on the right */
}
<div class='listBar'>
<h2 class='header' style='margin:5px'> List </h2>
<input type='text' id='input' placeholder="Title">
<button id='add'> Add </button>
</div>
Second proposal after comments:
(That's not what I'll do, but that's funny anyway!)
You could play with the transform property to move the element:
body {
background-color: #ddd; /* Added only for snippet */
}
.listBar {
position: absolute;
background: #bbb; /* Added only for snippet */
left: 40px;
top: 20px; /* Modified only for snippet */
box-sizing: border-box;
}
#input {
width: 100%;
font-size: 16px;
border: none;
background-color: aliceblue;
padding: 14px;
float: left;
}
#add {
color: whitesmoke;
border: none;
background-color: inherit;
padding: 14px 20px;
font-size: 16px;
cursor: pointer;
float: right; /* Floating on the right */
transform: translate(100%, -50%); /* Added with funny values, just for demo. Waiting for your answer to my comment. :) */
}
<div class='listBar'>
<h2 class='header' style='margin:5px'> List </h2>
<input type='text' id='input' placeholder="Title">
<button id='add'> Add </button>
</div>
Note that currently, because of the padding of the input, the input goes outside of its parent.
You may want to correct that.
Documentation about transform: https://www.w3schools.com/css/css3_2dtransforms.asp
When using translate() with percentages, it takes a percentage of the size of the element.
It's quite handy.
Hope it helps.
Put a wrapper around the input and button and than use display: flex;
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Did this help?
.listBar {
position: absolute;
left: 40px;
box-sizing: border-box;
}
.listBar__forms {
display: flex;
}
#input {
width: 100%;
font-size: 16px;
border: none;
background-color: aliceblue;
padding: 14px;
}
#add {
color: whitesmoke;
border: none;
background-color: inherit;
padding: 14px 20px;
font-size: 16px;
cursor: pointer;
}
<div class='listBar'>
<h2 class='header' style='margin:5px'> List </h2>
<div class="listBar__forms">
<input type='text' id='input' placeholder="Title">
<button id='add'> Add </button>
</div>
</div>

Invisible element being hovered when it shouldn't

I've coded a dropdown login form for my navbar, it works correctly but not entirely, it seems that it also drops down when I hover on the area where the form appears:
The mouse is just hovering on an area where the dropdown appears but it shoudn't do that, it should drop down when I hover ONLY on "ingresar", how can fix this? Also, I don't want my mouse to look like I can click on the form, it should look normal.
.login-box {
width: 350px;
height: 420px;
padding: 80px 40px;
box-sizing: border-box;
background: rgba(0, 0, 0, .8);
position: absolute;
right: 0px;
top: 100%;
opacity: 0;
}
.menu li:hover .login-box {
opacity: 1;
}
h2 {
margin: 0;
padding: 0 0 10px;
color: #efed40;
text-align: center;
}
.login-box p {
margin: 0;
padding: 0;
font-weight: bold;
color: white;
}
.login-box input {
width: 100%;
margin-bottom: 20px;
}
.login-box input[type="text"],
.login-box input[type="password"] {
border: none;
border-bottom: 1px solid #fff;
background: transparent;
outline: none;
height: 40px;
color: #fff;
font-size: 16px;
}
::placeholder {
color: rgba(255, 255, 255, .3);
font-family: sans-serif;
font-weight: bold;
}
.login-box input[type="submit"] {
border: none;
outline: none;
height: 40px;
color: #fff;
font-size: 16px;
background: #ff267e;
cursor: pointer;
border-radius: 20px;
}
.login-box input[type="submit"]:hover {
background: #efed40;
color: #262626;
}
.login-box a {
color: #fff;
font-size: 14px;
font-weight: bold;
text-decoration: none;
}
<ul class="menu">
<li>INICIO</li>
<li class="with-arrow">CONTACTO</li>
<li class="with-arrow">REGISTRATE</li>
<li class="with-arrow">INGRESAR
<div class="login-box">
<h2>Ingresa tus datos</h2>
<form>
<p>CORREO</p>
<input type="text" name="" placeholder="Escribir e-mail">
<p>CONTRASEÑA</p>
<input type="password" name="" placeholder="Escribir Contraseña">
<input type="submit" name="" value="Listo">
¿Contraseña olvidada?
</form>
</div>
</li>
</ul>
You need to set the dropdown to not visible, so no hover event can be applied in it
.login-box{
width: 350px;
height: 420px;
padding: 80px 40px;
box-sizing: border-box;
background: rgba(0, 0, 0, .8);
position: absolute;
right: 0px;
top: 100%;
opacity: 0;
/* === NEW ==== */
visibility: hidden;
}
.menu li:hover .login-box{
opacity: 1;
/* === NEW ==== */
visibility: visible;
}
visibility

List-item starting in the middle of the box

I want to have a margin on the right and left side of the list-items hence why I created the "wrapper", can someone figure out why it starts somewhat on the center and not from left to right?
Here's a jsfiddle for it: http://jsfiddle.net/vd8rb51s/
.add-remove-skills {
position: relative;
float: right;
display: block;
border: 2px solid #d1d9de;
border-radius: 4px;
width: 287px;
height: 394px
}
ul.edit-skills {
}
ul.edit-skills li {
display: block;
margin: 0;
padding: 10px;
text-align: left;
background: #000;
margin-bottom: 15px
}
.skills-wrapper {
width: 267px;
margin: 0 auto
}
h3.manage-skills {
font-weight: 700;
font-size: 16px;
width: 100%;
padding: 15px;
margin-top: 0;
border-bottom: 2px solid #d1d9de
}
input.add-skill {
position: absolute;
font-size: 16px;
bottom: 0;
width: 100%;
height: 40px;
text-indent: 10px;
font-weight: 700;
border: none;
border-top: 2px solid #d1d9de
}
input.add-skill::-webkit-input-placeholder {
/* WebKit browsers */
color: #939fa7;
font-weight: 500
}
input.add-skill:-moz-placeholder {
/* Mozilla Firefox 4 to 18 */
color: #939fa7;
font-weight: 500;
opacity: 1
}
input.add-skill::-moz-placeholder {
/* Mozilla Firefox 19+ */
color: #939fa7;
font-weight: 500;
opacity: 1
}
input.add-skill:-ms-input-placeholder {
/* Internet Explorer 10+ */
color: #939fa7;
font-weight: 500
}
<div class="add-remove-skills">
<h3 class="manage-skills">Manage skills</h3>
<div class="skills-wrapper">
<ul class="edit-skills">
<li>Skill number one</li>
<li>Skill number two</li>
<li>Skill number three</li>
</ul>
</div>
<input class="add-skill" placeholder="Add new skill here" type="text">
</div>
Most browsers add some padding-left to ul elements by default. Just remove it:
.edit-skills {
padding-left: 0;
}
.add-remove-skills {
position: relative;
float: right;
display: block;
border: 2px solid #d1d9de;
border-radius: 4px;
width: 287px;
height: 394px;
}
ul.edit-skills {
padding-left: 0;
}
ul.edit-skills li {
display: block;
margin: 0;
padding: 10px;
text-align: left;
background: #000;
margin-bottom: 15px;
}
.skills-wrapper {
width: 267px;
margin: 0 auto;
}
h3.manage-skills {
font-weight: 700;
font-size: 16px;
width: 100%;
padding: 15px;
margin-top: 0;
border-bottom: 2px solid #d1d9de;
}
input.add-skill {
position: absolute;
font-size: 16px;
bottom: 0;
width: 100%;
height: 40px;
text-indent: 10px;
font-weight: 700;
border: none;
border-top: 2px solid #d1d9de;
}
input.add-skill::-webkit-input-placeholder { /* WebKit browsers */
color: #939fa7;
font-weight: 500;
}
input.add-skill:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
color: #939fa7;
font-weight: 500;
opacity: 1;
}
input.add-skill::-moz-placeholder { /* Mozilla Firefox 19+ */
color: #939fa7;
font-weight: 500;
opacity: 1;
}
input.add-skill:-ms-input-placeholder { /* Internet Explorer 10+ */
color: #939fa7;
font-weight: 500;
}
<div class="add-remove-skills">
<h3 class="manage-skills">Manage skills</h3>
<div class="skills-wrapper">
<ul class="edit-skills">
<li>Skill number one</li>
<li>Skill number two</li>
<li>Skill number three</li>
</ul>
</div>
<input type="text" class="add-skill" placeholder="Add new skill here">
</div>
unordered lists have a default indent/padding so that the bullets will not end up outside the list itself.
Ussually a CSS reset stylesheet would fix this kind of thing. It would contain something like this:
ul { margin: 0; padding: 0; }
or you can apply this in your case
ul.edit-skills { margin: 0; padding: 0; }