search
HomeWeb Front-endHTML Tutorialinput输入框不能右对齐,怎么办?_html/css_WEB-ITnose

input不能右对齐,怎么办?

原本照着书学习javascript的,以前也是这样对齐的,但有今天有提示文字,就无法对齐了,看着太难受了。 

请问应该如何解决呢?




请问如何右对齐,而且把提示文字空格出来呢?





<html> <head>  <meta charset="UTF-8">  <title>验证</title><style type="text/css">body {  font:14px arial;  text-align:center;  margin:0 auto;}form {  margin-top:15px;  width:440px;   margin:0 auto;}div.field {  text-align:right;}div.heading {  margin-bottom:25px;}div.field {  margin-bottom:5px;  text-align:right;}span.help {  color:#660000;  font-style:italic;}</style>  <script type="text/javascript">  <!--     	 function validateRegEx(regex,input,helpText,helpMessage){	    if(!regex.test(input)){				if (helpText != null)            helpText.innerHTML = helpMessage;          return false;		}else{				 if (helpText != null)            helpText.innerHTML = "";          return true;				}	 	 }	  function validateNonEmpty(inputField, helpText) {        // See if the input value contains any text        return validateRegEx(/.+/,          inputField.value, helpText,          "请输入内容.");      }		 function validateLength(minLength, maxLength, inputField, helpText) {        // See if the input value contains at least minLength but no more than maxLength characters         if (!validateNonEmpty(inputField, helpText))          return false;         return validateRegEx(new RegExp("^.{" + minLength + "," + maxLength + "}$"),          inputField.value, helpText,          "请输入 " + minLength + " 到 " + maxLength +          " 个字符.");      }	   function validateZipCode(inputField, helpText) {        // First see if the input value contains data        if (!validateNonEmpty(inputField, helpText))          return false;        // Then see if the input value is a ZIP code        return validateRegEx(/^\d{5}$/,          inputField.value, helpText,          "请输入5位数字的邮编.");      }	   function validateDate(inputField, helpText) {        // First see if the input value contains data        if (!validateNonEmpty(inputField, helpText))          return false;        // Then see if the input value is a date        return validateRegEx(/^\d{2}\/\d{2}\/(\d{2}|\d{4})$/,          inputField.value, helpText,          "请输入日期 (格式为, <b>01/14/1975</b>).");      }	   function validatePhone(inputField, helpText) {        // First see if the input value contains data		        if (!validateNonEmpty(inputField, helpText))           return false;        // Then see if the input value is a phone number        return validateRegEx(/^\d{3}-\d{3}-\d{5}$/,          inputField.value, helpText,          "请输入电话号码 (例如, 123-456-07890).");      }	   function validateEmail(inputField, helpText) {        // First see if the input value contains data        if (!validateNonEmpty(inputField, helpText))          return false;        // Then see if the input value is an email address        return validateRegEx(/^[\w\.-_\+]+@[\w-]+(\.\w{2,3})+$/,          inputField.value, helpText,          "请输入正确的邮箱 例如, johndoe@acme.com).");      }  //-->  </script> </head> <body>  <form name="orderform" action="bannerocity.php" method="POST">   	<div class="field">       详细家庭地址:        <input id="message" name="message" type="text" 		onblur="validateLength(6, 10, this, document.getElementById('message_help'))"           /> 		   <span id="message_help" class="help"></span>	</div>	<div class="field">        邮政编码:        <input id="zipcode" name="zipcode" type="text"           onblur="validateZipCode(this, document.getElementById('zipcode_help'))" />		  <span id="zipcode_help" class="help"></span>      </div>	   <div class="field">      当前日期:        <input id="date" name="date" type="text"          onblur="validateDate(this, document.getElementById('date_help'))" />		  <span id="date_help" class="help"></span>      </div>	  <div class="field">        电话:        <input id="phone" name="phone" type="text"           onblur="validatePhone(this, document.getElementById('phone_help'))" />		  <span id="phone_help" class="help"></span>      </div>     	  <div class="field">	   邮箱:   <input id="email" name="email" type="text"          onblur="validateEmail(this, document.getElementById('email_help'))" />		  <span id="email_help" class="help"></span>    </div>  </form>   </body></html>



回复讨论(解决方案)

你是说邮箱那个不能靠右边吗?你把错误信息挪到下面一行就可以了。
style="float:right"        text-align:right  试试

.field .field {    position: relative;}.field .help {    position: absolute;    width: 300px;    text-align: left;    padding-left: 12px;}

解决方案:
1、像这种表单布局,个人推荐用table
2、像你这种不右对齐,其实是因为你没给提示信息一个固定的块存放
3、把提示信息做相对定位,这样就解决就不会因没分配空间,而把左边的元素挤过去了。

.field .field {    position: relative;}.field .help {    position: absolute;    width: 300px;    text-align: left;    padding-left: 12px;}



嗯,好了,谢谢你。但我还有些不明白。
可以解释一下这两句的作用吗

.field .field {
    position: relative;
}
.field .help {
    position: absolute;

提示用  placehold   你懂得


.field .field {    position: relative;}.field .help {    position: absolute;    width: 300px;    text-align: left;    padding-left: 12px;}



嗯,好了,谢谢你。但我还有些不明白。
可以解释一下这两句的作用吗

.field .field {
    position: relative;
}
.field .help {
    position: absolute;


上层指定relative, 下面所包含的元素,指定 absolute,则下层相对上层定位
relative 是相对定位,absolute是绝对定位。

所以说下层的位置是相对于上层来说是绝对的

text-ailgn:right  试试

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Future of HTML, CSS, and JavaScript: Web Development TrendsThe Future of HTML, CSS, and JavaScript: Web Development TrendsApr 19, 2025 am 12:02 AM

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

HTML: The Structure, CSS: The Style, JavaScript: The BehaviorHTML: The Structure, CSS: The Style, JavaScript: The BehaviorApr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The Future of HTML: Evolution and Trends in Web DesignThe Future of HTML: Evolution and Trends in Web DesignApr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

HTML vs. CSS vs. JavaScript: A Comparative OverviewHTML vs. CSS vs. JavaScript: A Comparative OverviewApr 16, 2025 am 12:04 AM

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTML: Is It a Programming Language or Something Else?HTML: Is It a Programming Language or Something Else?Apr 15, 2025 am 12:13 AM

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML: Building the Structure of Web PagesHTML: Building the Structure of Web PagesApr 14, 2025 am 12:14 AM

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

From Text to Websites: The Power of HTMLFrom Text to Websites: The Power of HTMLApr 13, 2025 am 12:07 AM

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

Understanding HTML, CSS, and JavaScript: A Beginner's GuideUnderstanding HTML, CSS, and JavaScript: A Beginner's GuideApr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)