align text fields to right html form css - css

I am trying to align a form's text fields to the right side of the div in which they are contained. I have this for css:
application.css
#loginform {
width: 400px;
height: 300px;
background: rgba(237,191,92, 1);
margin-left: 0px;
padding: 10px;
}
#usertext, #passtext {
text-align: left;
}
#loginuser, #loginpass {
text-align: right;
}
#submitbutton {
text-align: center;
}
Here is my html:
indexform.php
<div id="loginform">
<form id="login" method="post" action="checklogin.php">
<h1>Member Login</h1>
<div id="usertext">
<p>Username:</p>
</div>
<div id="passtext">
<p>Password:</p>
</div>
<div id="loginuser">
<input name="myusername" type="text" id="myusername">
</div>
<div id="loginpass">
<input name="mypassword" type="password" id="mypassword">
</div>
<div id="submitbutton">
<input type="submit" name="Submit" value="Login">
</div>
</form>
</div>
What happens now:
Username:
Password:
|--username textfield--|
|--password textfield--|
|-login button-|
The text fields should be lined up to the right of the "Username:" and "Password:" labels.

I did this
DEMO
<div id="loginuser">
<input name="myusername" type="text" id="myusername">
</div>
<div id="usertext">
<p>Username:</p>
</div>
<div id="loginpass">
<input name="mypassword" type="password" id="mypassword">
</div>
<div id="passtext">
<p>Password:</p>
</div>
and
#loginuser, #loginpass {
float: right;
}

Related

Select the first div and last div in a class

I would like to modify the first and last child in the class search. Here is my attempt but it doesn't work.
This is my html.
<div id="search">
<form method="GET" action="http://images.google.com/images">
<div>Search</div>
<div><input type="text" name="q" class="searchInput"></div>
<div>
<input type="submit" value="Search Image" class="searchButton">
</div>
<div> Try it </div>
</form>
</div>
Neither of them works
.search div:first-child,
.search div:last-child {
font-size: large;
color: red;
}
.search form>div:first-child,
.search form>div:last-child {
font-size: large;
color: red;
}
May I ask what's the problem thank you.
#search div:first-child,
#search div:last-child {
font-size: 30px;
color: red;
}
<div id="search">
<form method="GET" action="http://images.google.com/images">
<div>Search</div>
<div><input type="text" name="q" class="searchInput"></div>
<div>
<input type="submit" value="Search Image" class="searchButton">
</div>
<div> Try it </div>
</form>
</div>
You are using .search
Instead of that use #search because you are using an id.

How do you make text input borders overlap?

div input:not(:first-of-type){
display: block;
}
#left_side{
width: 40%
}
label{
width:15em;
display: inline-block;
vertical-align: top;
}
input{
width: 23em;
border-style:solid;
border:1px solid black;
}
.group div{
margin-bottom: -1px;
}
.group input {
margin-bottom: -1px;
box-shadow: none;
background-color: antiquewhite;
}
.get{
width:23em;
display: inline-block;
}
<div class="group">
<div>
<label for="first_name">First Name:</label>
<input type="text" id="first_name" class="get">
</div>
<div>
<label for="last_name">First Name:</label>
<input type="text" id="last_name" class="get">
</div>
</div>
<!--Here is some code with grouped boxes:-->
<div>
<label for="address_1_ln_1">Address 1:</label>
<div class="get">
<input type="text" id="address_1_ln_1">
<input type="text" id="address_1_ln_2">
</div>
</div>
<div>
<label for="address_2_ln_1">Address 2:</label>
<div class="get">
<input type="text" id="address_1_ln_1">
<input type="text" id="address_2_ln_2">
</div>
</div>
<div>
<label for="city">City:</label>
<input type="text" id="city" class="get">
</div>
<div>
<label for="state">State:</label>
<input type="text" id="state" class="get">
</div>
<dive>
<label for="zip">Zip:</label>
<input type="text" id="zip" class="get">
</dive>
How do you make text input of forms overlap borders like border: collapse on a table? By default stacking them one on top of the other has them develop a 2px border between adjacent inputs. Ideally both the borders should merge.
You could do
input {
margin-bottom: -1px;
}

Left Align of Text using CSS

Here is the problem, I have a single-page application where I lay out a form:
Due to my novice CSS skill, I have not been able to left align the help text (in blue). Here is my HTML code:
label {
width: 15%;
display: inline-block;
text-align: right;
padding-right: 10px;
}
span.short_help {
font-size: 70%;
color: cornflowerblue;
padding-left: 10px;
}
<form>
<div>
<label for="Authentication">Authentication:</label>
<input type="text" name="Authentication" id="-Authentication" />
<span class="short_help">Authentication type, I, II, or III</span>
</div>
<br/>
<div>
<label for="Branch">Branch:</label>
<input type="text" name="Branch" id="Branch" />
<span class="short_help">Which regional branch.</span>
</div>
<br/>
<div>
<label for="Persistent">Persistent:</label>
<input type="checkbox" name="Persistent" id="Persistent" />
<span class="short_help">Persistent connection</span>
</div>
<br/>
</form>
If I fixed up the input field to make the controls the same width so the help text align, then the check box will be centered:
Here is what I added to the CSS above:
input {
width: 15%;
}
How can I have both the controls and the blue text left aligned?
Instead of setting a width on all input fields, wrap a div arround it with a class. In my example .input
Now you can set the width of the field without affecting the input width.
* {
box-sizing: border-box;
}
form {
max-width: 600px;
}
label, .input, span {
display: inline-block;
vertical-align: middle;
margin-left: -4px;
}
label {
width: 20%;
}
.input {
width: 30%;
}
span {
color: cornflowerblue;
}
<form>
<div>
<label for="Authentication">Authentication:</label>
<div class="input">
<input type="text" name="Authentication" id="-Authentication" />
</div>
<span class="short_help">Authentication type, I, II, or III</span>
</div>
<br/>
<div>
<label for="Branch">Branch:</label>
<div class="input">
<input type="text" name="Branch" id="Branch" />
</div>
<span class="short_help">Which regional branch.</span>
</div>
<br/>
<div>
<label for="Persistent">Persistent:</label>
<div class="input">
<input type="checkbox" name="Persistent" id="Persistent" />
</div>
<span class="short_help">Persistent connection</span>
</div>
<br/>
</form>
Add an element to wrap around the inputs and make them the desired size:
<div>
<label for="Authentication">Authentication:</label>
<span class="spacer">
<input type="text" name="Authentication" id="-Authentication" />
</span>
<span class="short_help">Authentication type, I, II, or III</span>
</div>
<br/>
<div>
<label for="Branch">Branch:</label>
<span class="spacer">
<input type="text" name="Branch" id="Branch" />
</span>
<span class="short_help">Which regional branch.</span>
</div>
<br/>
<div>
<label for="Persistent">Persistent:</label>
<span class="spacer">
<input type="checkbox" name="Persistent" id="Persistent" />
</span>
<span class="short_help">Persistent connection</span>
</div>
And add CSS to format it:
span.spacer {
display: inline-block;
width: 15%;
}
I didn't quite get it, do you only want to align the checkbox or the blue text
To align the checkbox to the left, change
input {
width: 15%;
}
to
input[type="text"] {
width: 15%;
}
the input driver you can align your text to the left so
input
{
text-align: left;
width: 15%;
}
but the tag span can not be proque is an online element for more doubt read this site that talks about the span tag:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span
You can also contain the span in a div and somehow achieve alignment

CSS has formatted itself in a confusing way

Some CSS on my screen seems to be automatically giving itself a margin from the top but not showing it correctly.
Example:
The green box is inside the image.
I have a feeling this is breaking the format I want which is to have the logo too the left and the contact and search bar too the right:
Here is my CSS:
.span6 img {
float: left;
}
img.logo {
float: left;
max-width: 350px;
height: auto;
}
#contact
{
float: left;
font-size: 2em;
color: black;
}
and my HTML:
<div class="row top-header">
<div class="span12" data-motopress-type="dynamic-sidebar" data-motopress-sidebar-id="header-sidebar">
<?php dynamic_sidebar("header-sidebar"); ?>
</div>
</div>
<div class="row">
<div style="" class="span6" data-motopress-type="static" data-motopress-static-file="static/static-logo.php">
<img src="http://bradlyspicer.net/autokentcare/wp-content/uploads/2014/01/logo2.png" class="logo">
<div id="contact"><span style="margin-left:50px; float: left;">01843 123456<br><div style="margin-top:15px; display:inline-block;"><form method="get" id="searchform" action="<?php bloginfo('home'); ?>/">
<div><input type="text" size="12px" name="s" id="s" value="Write your search and hit Enter" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"/>
<input type="submit" id="searchsubmit" value="Search" class="btn""/></span></div>
</div>
</form></span>
</div>
URL: http://www.bradlyspicer.net/autokentcare/
After doing suggested changes this happens when I shrink the window:
You have your logo and search bar inside of a div that has a width set on it to 560 (span6 class) If you remove that class it should work a bit better for you.

css form- issue with margin/padding-- code & image included

I'm having issue with an html/css contact form. Ideally, I'd like the 'label' and 'input' to be level with eachother, with a 1px border-bottom extending from the label to a defined endpoint(not a defined width). Is this possible? What am I missing?
<div id="contact">
<div id="invite">
<h1>Let's Talk.</h1>
<h2 class="postinfo">
<p>Have you got a project needing an eye for detail and a creative touch? <br>I'd love to hear from you. </p>
</h2>
</div><!-- end invite -->
<form action="#" method="post">
<fieldset>
<label for="name"><h1>Name:</h1></label>
<input type="text" id="name" placeholder="" />
<label for="email"><h1>Email:</h1></label>
<input type="text" id="email" placeholder="" />
<label for="subject"><h1>Subject:</h1></label>
<input type="subject" id="subject" placeholder="" />
<label for="message"><h1>Message:</h1></label>
<textarea id="message" placeholder=""></textarea>
<input type="submit" value="Send" />
</fieldset><!-- end fieldset -->
</form><!-- end form -->
</div><!-- end contact -->
#contact {
float: left;
margin-left: 300px;
margin-top: 310px;
width: 533px;
}
#invite .postinfo {
list-style-type: none;
margin-left: ;
width: 150px;
}
#form {
float: right;
margin-top: -85px;
margin-left: 230px;
}
#form fieldset {
border-style: none;
margin-left: -50px;
margin-top: -25px;
}
#form fieldset label {
padding-right: 50px;
}
#form fieldset input {
width: 300px;
}
http://i.stack.imgur.com/B6wF8.png
I played around with your code a bit and this is what I came up with:
Here is your HTML:
<contact>
<form action="#" method="post">
<fieldset>
<div class="clear">
<label for="name"><h1>Name:</h1></label>
<input type="text" id="name" placeholder="" />
</div>
<div class="clear">
<label for="email"><h1>Email:</h1></label>
<input type="text" id="email" placeholder="" />
</div>
<div class="clear">
<label for="subject"><h1>Subject:</h1></label>
<input type="subject" id="subject" placeholder="" />
</div>
<div class="clear">
<label for="message"><h1>Message:</h1></label>
<textarea id="message" placeholder=""></textarea>
</div>
<div class="clear">
<input type="submit" value="Send" />
</div>
</fieldset><!-- end fieldset -->
</form><!-- end form -->
</contact><!-- end contact -->
and here is your CSS:
body { font-family:arial,helvetica,sans-serif ;
font-size:14px ;
font-weight:bold ;
}
h1 { font-size:16px ;
margin:0 ;
padding:0 ;
}
contact {
float: left;
margin-left: 300px;
margin-top: 310px;
width: 533px;
}
contact invite .postinfo {
list-style-type: none;
margin-left: ;
width: 150px;
}
contact form {
float: right;
margin-top: -85px;
margin-left: 230px;
}
contact form fieldset {
border-style: none;
margin-left: -50px;
margin-top: -25px;
}
contact form fieldset label { width:100px ;
float:left }
contact form fieldset input {
width: 200px;
float:right ;
}
.clear { clear:both ;
line-height:30px ;
}
You'll need to play with your label and input widths depending on the font size you use.
Best,
Cynthia

Resources