简体   繁体   English

span css无法正常工作

[英]span css is not working properly

I want to display span tag after input tag. 我想在输入标签后显示span标签。 我想在输入文本后面显示刻度线

But it displays before input tag. 但它在输入标签之前显示。 Here I attached css and html code. 这里我附上了css和html代码。

http://jsfiddle.net/sarurakz/8j3r13ec/ http://jsfiddle.net/sarurakz/8j3r13ec/

CSS: CSS:

 span{
   float:right;
   margin-right:1%;
 }
input {
   display: inline-block;
   float: right;
   margin-right:20%;
}

Html : Html

<p>Password<input type="password" name="pass" id="pass" size=18 maxlength=50 required></p>
<p>Confirm Password<input type="password" name="cpass" id="cpass" size=18 maxlength=50 required><span id='message'></span></p>

validation:
   <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">    </script>
  <script>
   $('#pass, #cpass').on('keyup', function () {
   if ($('#pass').val() == $('#cpass').val()) {
    $('#message').html('<img src="image/tick.png" width=15px height=15/>').css('color', 'green');  
     $("#phone").prop('disabled', false); 
     } 
      else{ $('#message').html('<img src="image/delete1.png" width=15px height=15/>').css('color', 'red'); 
      $("#phone").prop('disabled', true);}
    });
 </script>

I was not having any image so i just placed a random text there in span 我没有任何图像所以我只是在其中放置了一个随机文本

 span{ float:right; margin-right: 8%; margin-left: -17%; } input { display: inline-block; float: right; margin-right:20%;} 
 <p>Password<input type="password" name="pass" id="pass" size=18 maxlength=50 required></p> <p>Confirm Password<span id='message'>asdasd</span><input type="password" name="cpass" id="cpass" size=18 maxlength=50 required></p> 

我希望有一个小提琴,但根据我的理解,你可以尝试添加float: leftinputspan

You cant do the validation and adding the tick image just with HTML and CSS. 您无法进行验证并仅使用HTML和CSS添加刻度图像。 You will need to do the validation in Javascript. 您需要在Javascript中进行验证。

See this working code snippet: 请参阅此工作代码段:

 document.getElementById('pass').addEventListener('blur', function(){ var passwordLength = document.getElementById('pass').value.length; if(passwordLength > 8 && passwordLength < 50){ var image = document.createElement('img'); image.src = 'http://yoozy.com/images/tick-icon.jpg'; this.parentNode.insertBefore(image, document.getElementById('pass')); } }); 
 span{ float:right; margin-right:1%; } input { display: inline-block; float: right; margin-right:20%; } 
 <p>Enter atleast 8 characters in this first password field and focusout to see thie validation working.</p> <p> Password <input type="password" name="pass" id="pass" size=18 maxlength=50 required> </p> <p> Confirm Password <input type="password" name="cpass" id="cpass" size=18 maxlength=50 required> <span id='message'></span> </p> 

use label and padding right and align the span position absolute 使用标签和填充右侧并将跨度位置对齐绝对

using label automatically focuses the input on click of text 使用标签会自动将输入重点放在文本点击上

 label { width: 400px; display: inline-block; padding: 0 30px 0 0; position: relative; margin: 5px 0; } input { float: right; } span.icon { font-size: 14px; color: white; text-align: center; display: block; line-height: 23px; background: rgb(18, 208, 27); border-radius: 50%; width: 20px; height: 20px; right: 0px; position: absolute; top: 0; } 
 <label>username <input type="text" name="pass" id="pass" size=18 maxlength=50 required /> </label> <label>Password <input type="password" name="pass" id="pass" size=18 maxlength=50 required /> <span class="icon">&#10003;</span> </label> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM