2016-09-23 99 views
0

如何將標籤放置在輸入標籤的頂部,默認情況下,它位於輸入標籤內部,當我點擊它時,它跳到輸入標籤的頂部,在輸入標籤頂部放置一個標籤

這是我的嘗試:

input { 
 
    font-size: 18px; 
 
    padding: 10px 10px 10px 5px; 
 
    -webkit-appearance: none; 
 
    display: block; 
 
    background: #fafafa; 
 
    color: #636363; 
 
    width: 100%; 
 
    border: none; 
 
    border-radius: 0; 
 
    border-bottom: 1px solid #757575; 
 
} 
 
input:focus { 
 
    outline: none; 
 
} 
 
/* Label */ 
 

 
label { 
 
    color: #999; 
 
    font-size: 18px; 
 
    font-weight: normal; 
 
    position: absolute; 
 
    pointer-events: none; 
 
    left: 5px; 
 
    top: 10px; 
 
    -webkit-transition: all 0.2s ease; 
 
    transition: all 0.2s ease; 
 
} 
 
/* active */ 
 

 
input:focus ~ label, 
 
input.used ~ label { 
 
    top: -20px; 
 
    -webkit-transform: scale(.75); 
 
    transform: scale(.75); 
 
    left: -2px; 
 
    /* font-size: 14px; */ 
 
    color: #000; 
 
} 
 
/* Underline */ 
 

 
.bar { 
 
    position: relative; 
 
    display: block; 
 
    width: 100%; 
 
} 
 
.bar:before, 
 
.bar:after { 
 
    content: ''; 
 
    height: 2px; 
 
    width: 0; 
 
    bottom: 1px; 
 
    position: absolute; 
 
    background: #4a89dc; 
 
    -webkit-transition: all 0.2s ease; 
 
    transition: all 0.2s ease; 
 
} 
 
.bar:before { 
 
    left: 50%; 
 
} 
 
.bar:after { 
 
    right: 50%; 
 
} 
 
/* active */ 
 

 
input:focus ~ .bar:before, 
 
input:focus ~ .bar:after { 
 
    width: 50%; 
 
} 
 
/* Highlight */ 
 

 
.highlight { 
 
    position: absolute; 
 
    height: 60%; 
 
    width: 100px; 
 
    top: 25%; 
 
    left: 0; 
 
    pointer-events: none; 
 
    opacity: 0.5; 
 
} 
 
/* active */ 
 

 
input:focus ~ .highlight { 
 
    -webkit-animation: inputHighlighter 0.3s ease; 
 
    animation: inputHighlighter 0.3s ease; 
 
}
<div class="group"> 
 
    <input type="text" name="name" placeholder="" readonly> 
 
    <span class="highlight"> 
 
     </span><span class="bar"></span> 
 
    <label>FULLNAME</label> 
 
</div>

請我如何可以將標籤上的輸入標籤的頂部永久。在它被放置在輸入標籤並點擊它的那一刻,就跳轉到標記的頂部

回答

1

你可以嘗試像

<form name="message" method="post"> 
 
    <section> 
 
    <div> 
 
     <label for="name">Name</label> 
 
     <input id="name" type="text" value="" name="name"> 
 
    </div> 
 
    <div> 
 
     <label for="email">Email</label> 
 
     <input id="email" type="text" value="" name="email"> 
 
    </div> 
 
    </section> 
 
    <section> 
 
    <div> 
 
     <label for="subject">Subject</label> 
 
     <input id="subject" type="text" value="" name="subject"> 
 
    </div> 
 
    <div class="full"> 
 
     <label for="message">Message</label> 
 
     <input id="message" type="text" value="" name="message"> 
 
    </div> 
 
    </section> 
 
</form>