nishikori
nishikori

Reputation: 63

Input field effect

I would like to make effect on my input fields like in this example:

https://colorlib.com/etc/cf/ContactFrom_v17/index.html

I see in this example that there is a span which "wraps"(+2px) an input field and they are doing effect on that span, but I'm failing to make that span to wrap input field.

This is my contact form: https://codepen.io/anon/pen/xWwEvm

HTML:

<div id="contactDiv">

        <div id="innerContact">
            <div class="rightDiv">
                <div class="innerRightDiv">
                    <form method="post" action="contact.php">

                        <h3 id="customH3" class="lang" key="send">Send Us A Mail</h3>

                        <div class="lblDiv">
                            <label for="name" class="lang" key="name">Name</label>
                        </div>
                        <input required="" type="text" id="name" name="name" placeholder="Your name.."><input required="" type="text" id="lastName" name="name" placeholder="Last name..">
                        <div class="lblDiv">
                            <label for="email" class="lang" key="email">Email</label>
                        </div>
                        <div>
                            <input required="" type="email" id="email" name="email" placeholder="Your email..">
                            <div style="/* width:  100%; */height: 100%;"></div>
                        </div>
                        <div class="lblDiv">
                            <label for="message" class="lang" key="message">Message</label>
                        </div>
                        <textarea required="" id="message" name="message" placeholder="Write something.."></textarea>
                        <!--
-->
                        <div class="submitDiv">
                            <input id="submit" name="submit" type="submit" value="Submit">
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

CSS:

    input[type=text], select, textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #ccc;
    box-sizing: border-box;
    margin-bottom: 16px;
    resize: vertical;
}

input[type=email], select, textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #ccc;
    box-sizing: border-box;
    margin-bottom: 16px;
    resize: vertical;
}

input[type=submit] {
    background-color: #3FA9F5;
    color: white;
    padding: 12px 20px;
    border: none;
    cursor: pointer;
}

input[type=submit]:hover {
    background-color: #45a049;
}

#contactDiv {
    height: 800px;
    margin-bottom: 5%;
}

.contacth2 {
    margin-top: 10%;
    margin-bottom: 5%;
}

#innerContact {
    width: 70%;
    height: 100%;
    margin: auto;
}

.rightDiv {
    background-color: white;
    padding: 20px;
    width: 50%;
    float: left;
    height: 100%
}

.lblDiv {
    border: 1px solid #ccc;
    padding: 12px;
}

.innerRightDiv {
    width: 80%;
    margin: auto;
}

.submitDiv {
    text-align: center;
}

.innerDivs {
    height: 100%;
    display: table-cell;
    vertical-align: middle;
    text-align: center;
}

.innerDiv {
    text-align: left;
    padding-top: 30px;
    padding-bottom: 30px;
    color: white;
}
.bold {
    font-weight: bold;
}

h3 {
    font-size: 20px;
    font-weight: bold;
    padding: 5px;
}


.wrapperDiv {
    padding-left: 30%;
    padding-top: 30px;
    padding-bottom: 30px;
}

textarea {
    resize: none;
    font: 400 13.3333px Arial;
    font-size: 1.6rem;
    height: 150px;
    margin-top: -1px;
}

#lastName, #name {
    width: 50%;
}

Upvotes: 0

Views: 312

Answers (1)

Stanislas
Stanislas

Reputation: 2020

There's a container, with an input which is followed by a span. The span has transition effects but is invisible by default. When the input is focused, the span is modified using a selector like: input:focus + span.

The rest of the code is a matter of positioning and styling. Note: the position of the span is set to absolute to position it over the input, because of this, the container needs to have a relative position.

I've left out some of the details of the CSS, but this snippet demonstrates the general idea.

.container {
  position: relative;
  width: 100px;
}

input {
  width: 100%;
}

.inputeffect {
  position: absolute;
  display: block;
  width: 100%;
  height: 100%;
  top: 0;
  border: 1px solid green;
  visibility: hidden;
  -webkit-transition: all 0.4s;
  -o-transition: all 0.4s;
  -moz-transition: all 0.4s;
  transition: all 0.4s;
  -webkit-transform: scale(1.3);
  -moz-transform: scale(1.3);
  -ms-transform: scale(1.3);
  -o-transform: scale(1.3);
  transform: scale(1.3);
}

input:focus + .inputeffect {
    visibility: visible;
    opacity: 1;
    -webkit-transform: scale(1);
    -moz-transform: scale(1);
    -ms-transform: scale(1);
    -o-transform: scale(1);
    transform: scale(1);
}
<div class="container">
  <input type="text"/>
  <span class="inputeffect"></span>
</div>

Sidenote: please don't just copy the effect though, use your own inspiration! If you do want to use the same effect, you should consider contacting the author.

Upvotes: 1

Related Questions