I have this HTML code:
<div>
<input id="cemail" type="email" name="email" placeholder="Your E-Mail" required>
<span>Proper format "exampel#something.com"</span>
</div>
I've configured 'text-align: center' on the div but unfortunately span text is also centered (see the image below).
I need span to be near it and not centered.
You probably should center your parent element, and not div inside form:
.center-form {
text-align: center;
}
.center-form form {
display: inline-block;
text-align: left;
}
<div class="center-form">
<form action="">
<div>
<input id="cemail" type="email" name="email" placeholder="Your E-Mail" required>
</div>
<div>
<input id="cemail" type="email" name="email" placeholder="Your E-Mail" required>
<span>Proper format "exampel#something.com"</span>
</div>
<div>
<input id="cemail" type="email" name="email" placeholder="Your E-Mail" required>
</div>
<button>Submit</button>
</form>
</div>
Or if you want span not to affect form position, use position: absolute:
.center-form {
text-align: center;
}
.center-form form {
display: inline-block;
text-align: left;
}
.center-form form div {
position: relative;
}
.center-form form div span {
position: absolute;
left: 100%;
top: 0;
/* for demo */
white-space: nowrap;
}
<div class="center-form">
<form action="">
<div>
<input id="cemail" type="email" name="email" placeholder="Your E-Mail" required>
</div>
<div>
<input id="cemail" type="email" name="email" placeholder="Your E-Mail" required>
<span>Proper format "exampel#something.com"</span>
</div>
<div>
<input id="cemail" type="email" name="email" placeholder="Your E-Mail" required>
</div>
<button>Submit</button>
</form>
</div>
You should apply 'text-align: center;' on the input#cemail, not on the div.
What about a nice -
position: absolute
You get a free relative with the div. Then the error will never get in the way of the input box as its absolutely positioned.
Of course you will need to fix the top, left, right, bottom to conform to your design.
You can also do something like this, to allow wrapping of text.
body {
font-family: sans-serif;
}
input {
width: 160px;
position: relative;
left: 50%;
margin-left: -80px;
box-sizing: border-box;
}
p {
clear: right;
}
.legend {
float: right;
width: 50%;
}
.legend small {
background: #ccc;
display: block;
margin-left: 80px;
word-wrap: break-word;
padding: 0.5em;
}
<form>
<p>
<input type="text" placeholder="Your Last Name">
<span class="legend">
<small>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam consectetur libero magna, ultrices vehicula dui hendrerit ut. Mauris dictum urna nec justo tristique, id rutrum sapien blandit. Ut pellentesque, augue ornare pellentesque dictum, sem lectus hendrerit massa, nec gravida elit mauris sit amet lorem.</small>
</span>
</p>
<p>
<input type="text" placeholder="Your User Name">
</p>
<p>
<input type="email" placeholder="Your Email">
<span class="legend">
<small>Proper format "exampel#something.com"</small>
</span>
</p>
<p>
<input type="text" placeholder="Your Password">
</p>
<p>
<input type="submit" value="Add Me Now">
</p>
</form>
<div>
<input id="cemail" type="email" name="email" placeholder="Your E-Mail" required>
<span class="float-right">Proper format "exampel#something.com"</span>
</div>
Related
I'm building a layout with CSS, customizing some 'div' tags. On of them (the div with the id "col3") is with a strange padding-top and I don't know why. I have already tried to use 'padding: 0;', but it's not working. I know I can fix it with the property 'position', but why is it happening with my div? The codes are these:
HTML
<section id="getintouch">
<h3>Get in Touch</h3>
<p>Etiam at mi at quam suscipit auctor a ac urna. Nullam non euismod felis, sed rhoncus risus. Donec erat enim, convallis eu facilisis at, hendrerit sed ligula.</p>
<div id="getintouchlayout">
<div id="col1-2">
<form action="#" method="POST">
<label for="name">Name</label>
<input type="text" name="nome" id="name">
<label for="email">Email</label>
<input type="email" name="email" id="email">
<label for="message">Message</label>
<textarea name="message" id="message"></textarea>
<input type="submit" value="Send Message">
</form>
</div>
<div id="col3">
<address>
<p>
<span>Endereço</span>
1234 Somewhere Rd. Nashville, TN 00000 United States
</p>
<p>
<span>Telefone</span>
000-000-000
</p>
<p>
<span>Email</span>
email#server.com
</p>
</address>
</div>
</div>
</section>
CSS
#getintouchlayout{overflow: auto;}
#col1-2{
width: 63.5%;
margin-right: 5%;
float: left;
}
#col3{
width: 31.5%;
float: right;
}
Obs: I know 'float' is not so used to do that, but I am using it because I am learning about this property in a course and I need to use it in a project.
Remove the <p> margin, that tag has inherent paddding that <label> does not have.
I'm currently styling a WordPress site's contact form. The desired result should look something like this:
Normally, this could be easily achieved with a wrapper div around the text fields. Since this is WordPress, I can't do this without digging into the plugin (which is the last thing I want to do). The HTML WordPress produces looks like this:
<form ...>
<p class="..." data-id="name" data-type="input">
<label ...>Naam Achternaam</label>
<input type="text" ...>
</p>
<p class="..." data-id="company" data-type="input">
<label ...>Bedrijf</label>
<input type="text" ...>
</p>
<p class="..." data-id="email" data-type="input">
<label ...>E-mail</label>
<input type="email" ...>
</p>
<p class="..." data-id="phone" data-type="input">
<label ...>Telefoonnummer</label>
<input type="text" ...>
</p>
<p class="..." data-id="message" data-type="text">
<label ...>Vragen / opmerkingen</label>
<textarea ...></textarea>
</p>
...
</form>
which currently looks like this:
Is it possible to achieve what I'm after with this HTML structure or do I need to find a way to accommodate a wrapper div?
You could use position: absolute on the last p... not the nicest solution but a possible workaround without changing the HTML
form {
background: #00CDD4;
display: flex;
flex-direction: column;
position: relative;
}
form p {
margin: 1em;
display: flex;
flex-direction: column;
width: 45%;
}
form p label {
text-transform: uppercase;
font-family: sans-serif;
opacity: .87;
}
form p input {
border: none;
padding: 1em;
}
form p:last-of-type {
position: absolute;
top: 0;
right: 0;
bottom: 0;
}
form p:last-of-type textarea {
height: 100%;
}
<form>
<p class="..." data-id="name" data-type="input">
<label ...>Naam Achternaam</label>
<input type="text" ...>
</p>
<p class="..." data-id="company" data-type="input">
<label ...>Bedrijf</label>
<input type="text" ...>
</p>
<p class="..." data-id="email" data-type="input">
<label ...>E-mail</label>
<input type="email" ...>
</p>
<p class="..." data-id="phone" data-type="input">
<label ...>Telefoonnummer</label>
<input type="text" ...>
</p>
<p class="..." data-id="message" data-type="text">
<label ...>Vragen / opmerkingen</label>
<textarea ...></textarea>
</p>
</form>
I tried alot but following your requirements it seems only possible through position absolute. Just for fun I tried to make without display: flex;
body {
background-color: #2dccd3;
font-family: 'Montserrat', sans-serif;
}
form.contact{
position: relative;
}
p.contact-field {
width: 45%;
}
p.contact-field input{
width: 100%;
}
input, label {
display:block;
}
p.contact-field:last-child{
margin: 0px;
}
.contact-field:last-child{
position: absolute;
right: 0px;
top: 0px;
width: 50%;
height: 89%;
}
textarea#message{
height: 100%;
}
<form class="contact">
<p class="contact-field" data-id="name" data-type="input">
<label for="name">Naam Achternaam</label>
<input id="name" type="text" name="name">
</p>
<p class="contact-field" data-id="company" data-type="input">
<label for="company">Bedrijf</label>
<input id="company" type="text" name="company">
</p>
<p class="contact-field" data-id="email" data-type="input">
<label for="email">E-mail</label>
<input id="email" type="email" name="email">
</p>
<p class="contact-field" data-id="phone" data-type="input">
<label for="phone">Telefoonnummer</label>
<input id="phone" type="text" name="phone">
</p>
<p class="contact-field" data-id="message" data-type="text">
<label for="message">Vragen / opmerkingen</label>
<textarea id="message" name="message"></textarea>
</p>
</form>
I have some troubles with my html and css structure for this layout on the picture below.
Can you give me some suggestions how to accomplish it properly ? How to separate left section and right section with the form because I want to be able to create this full height black transparent background ?
Here is my code until now.
.enroll-bg { background: linear-gradient( rgba(0, 0, 0, 0.52), rgba(0, 0, 0, 0.52)), url(https://s30.postimg.org/6uy1f1rxd/enroll_bg.jpg) 0 0 no-repeat; background-size: cover; padding: 40px 0 230px 0; width: 100%; }
.form-container { position: relative; }
.form-wrapper { position: absolute; bottom: -230px; right: 0; left: 50%; background: red; width: 539px; height: 520px; }
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<header class="header">
<div class="enroll-bg">
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="enroll-logo">
<div class="logo">
logo
</div>
<!-- logo -->
</div>
<!-- enroll-logo -->
<div class="enroll-content">
<h1>Enroll today and <span>save money & time</span></h1>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor.Com sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.</p>
</div>
<!-- enroll-content -->
</div>
<!-- col-md-6 -->
</div>
<!-- row -->
<div class="form-container">
<form action="#" class="form-wrapper">
<div class="form-content">
<p>
<input type="text" id="fname" name="firstname" placeholder="Full Name..." required="required" class="field">
</p>
<p>
<input type="text" id="fname" name="firstname" placeholder="+44 01 234 5678" required="required" class="field">
</p>
<p>
<input type="email" id="email" name="email" placeholder="Email Address..." required="required" class="field">
</p>
<p>
<input type="email" id="confirm-email" name="confirm-email" placeholder="Confirm Email..." required="required" class="field">
</p>
<p>
<input type="text" id="electric-provider" name="electric-provider" placeholder="Current Electric Provider..." required="required" class="field">
</p>
<p>
<input type="text" id="gas-provider" name="gas-provider" placeholder="Current Gas Provider..." required="required" class="field">
</p>
<div class="form-actions">
<button type="button" class="btn btn-danger">enroll today</button>
</div>
<!-- form-actions -->
</div>
<!-- form-content -->
</form>
<!-- form-wrapper -->
</div>
<!-- form-container -->
</div>
<!-- container -->
</div>
<!-- enroll-bg -->
</header>
<!-- header -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
I've made some minor tweaks to both HTML and CSS - see jsfiddle here.
I've removed position: absolute from the .form-wrapper, wrapped the form in a .col-xs-6, and put in the same .row so that it sits alongside the enroll content.
Each .row can contain any combination of .col-xx-xx or .col-xx-offset-xx, as long as the sum of the numbers is no more than 12. You can read more about this here.
HTML:
<div class="enroll-bg">
<div class="container">
<div class="row">
<div class="col-xs-6">
<div class="enroll-logo">
<div class="logo">
logo
</div>
</div>
<div class="enroll-content">
<h1>Enroll today and <span>save money & time</span></h1>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor.Com sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.</p>
</div>
</div>
<div class="col-xs-6 form-container">
<div class="">
<form action="#" class="form-wrapper">
<div class="form-content">
<p>
<input type="text" id="fname" name="firstname" placeholder="Full Name..." required="required" class="field">
</p>
<p>
<input type="text" id="fname" name="firstname" placeholder="+44 01 234 5678" required="required" class="field">
</p>
<p>
<input type="email" id="email" name="email" placeholder="Email Address..." required="required" class="field">
</p>
<p>
<input type="email" id="confirm-email" name="confirm-email" placeholder="Confirm Email..." required="required" class="field">
</p>
<p>
<input type="text" id="electric-provider" name="electric-provider" placeholder="Current Electric Provider..." required="required" class="field">
</p>
<p>
<input type="text" id="gas-provider" name="gas-provider" placeholder="Current Gas Provider..." required="required" class="field">
</p>
<div class="form-actions">
<button type="button" class="btn btn-danger">enroll today</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
CSS:
.enroll-bg { background: linear-gradient( rgba(0, 0, 0, 0.52), rgba(0, 0, 0, 0.52)), url(https://s30.postimg.org/6uy1f1rxd/enroll_bg.jpg) 0 0 no-repeat;
background-size: cover;
width: 100%; }
.form-container {
height: 100vh;
background: red;
}
Your form must be in the same row as the left column, and in another col-md-6.
if it is for a single page you may not need to use boostrap (class and structure) and relay on the flex model with a few mediaqueries to allow font-size resizing and eventually break into 1 column:
header,
main {
width: 30vw;
min-width: 360px;
height: 100vh;
}
html,
header,
form {
display: flex;
flex-flow: column;
min-height: 100vh;
}
body {
min-height: 100vh;
margin:0;
display: flex;
justify-content: center;
flex-wrap: wrap;
background: linear-gradient(to bottom, #55707B, #677B82, #484926, #685125);
background-size:100% 100%;
color: white;
}
header img {
min-height: 40px;
margin: 1em auto 1em 1em;
}
header h1 {
flex: 1;
display: flex;
flex-flow: column;
justify-content: center;
font-size: 3.5em;
margin: 0;
}
header h1 b {
display: block;
color: #A7FE2B
}
main form {
justify-content: space-around;
align-items: center;
padding: 5vh 3vw;
box-sizing: border-box;
background: rgba(0, 0, 0, 0.25)
}
main form label {
font-size: 5vh;
width: 100%;
position: relative;
}
main form label input:not([type="submit"]) {
width: 100%;
padding-left: 1.5em;
box-sizing: border-box;
}
label:not(:last-of-type):before {
font-family: FontAwesome;
content: "\f007";
position: absolute;
z-index: 1;
left: 0.2em;
top: 0.25em;
color: gray;
}
label:nth-child(2):before {
content: "\f10b";
/* etc ..*/
}
label:last-of-type input {
padding: 0.25em;
color: white;
background: turquoise;
border: none;
}
#media only screen and (max-height: 500px) {
header h1 {
font-size: 20px;
}
main form label {
font-size: 20px;
}
body,
main,
header,
form {
height: auto;
min-height: 100vh
}
}
<link href="//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet"/>
<header>
<img src="http://dummyimage.com/150x40&text=\LOGO/" alt="logo" />
<h1>HTML Ipsum Vestibulum &<b> test me full page too</b></h1>
<p>Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum,
elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui.</p>
</header>
<main>
<form>
<label>
<input placeholder="place holder" />
</label>
<label>
<input placeholder="place holder" />
</label>
<label>
<input placeholder="place holder" />
</label>
<label>
<input placeholder="place holder" />
</label>
<label>
<input placeholder="place holder" />
</label>
<label>
<input placeholder="place holder" />
</label>
<label>
<input type="submit" value="tempus lacus" />
</label>
</form>
</main>
http://codepen.io/gc-nomade/pen/MbBNaO
hello i'm creating a login form .but my check box and term text related to it not positioning correctly .i have add <br> tag but no effect .i tried clearfix it's not work either.here is the fiddle preview.
this is my html code
<div class="mainlog">
<form>
<label class="la" for="xname">Name</label><input name="xname" class="in" value="" type="text"><br>
<label class="la" for="xemail">Email</label><input name="xemail" class="in" value="" type="text"><br>
<label class="la" for="xpass">password</label><input name="xpass" class="in" value="" type="text"><br>
<label class="la" for="xpasscon">confirm</label><input name="xpasscon" class="in" value="" type="text"><br>
<input type="checkbox" name="term"/><label class="lb" for="term" >I have read and agree to the Terms of Use and the Privacy Policy</label><br>
<input type="submit" value="Sign Up" />
</form>
</div>
Wrap the checkbox and text in a div and float it left. Avoid the usage of <center> it will not be supported in HTML5
.mainlog {
width: 450px;
height: 250px;
border: 5px solid #DBDBDB;
border-radius: 5px;
padding: 20px;
}
.in {
padding: 8px;
border: 1px solid #DFDFDF;
width: 250px;
float: left;
margin-bottom: 10px;
border-radius: 5px;
}
.la {
width: 120px;
float: left;
text-align: left;
text-transform: uppercase;
color: #6B6B6B;
clear: both;
}
.lb {} .checkbox {
float: left;
}
}
<center>
<div class="mainlog">
<form>
<label class="la" for="xname">Name</label>
<input name="xname" class="in" value="" type="text">
<br>
<label class="la" for="xemail">Email</label>
<input name="xemail" class="in" value="" type="text">
<br>
<label class="la" for="xpass">password</label>
<input name="xpass" class="in" value="" type="text">
<br>
<label class="la" for="xpasscon">confirm</label>
<input name="xpasscon" class="in" value="" type="text">
<br>
<div class="checkbox">
<input type="checkbox" name="term" />
<label class="lb" for="term">I have read and agree to the Terms of Use and the Privacy Policy</label>
<br />
</div>
<input type="submit" value="Sign Up" />
</form>
</div>
</center>
Quick fix: wrapp checkbox with it's label into div with class "width".
Then in CSS add ".width" with styles: width:100%; clear:both.
.width{
width:100%;
clear:both;
}
Demo
I did a minor change in your code and it looks good to me. I am not sure if this is what you were looking for.
Please check the fiddle here.
These were the changes I made.
HTML:
<div class="lb"> <!-- added class "lb" to <div> and removed it from <label> -->
<input type="checkbox" name="term" />
<label for="term">I have read and agree to the Terms of Use and the Privacy Policy</label>
</div>
CSS:
.lb {
float:left; /* Floats the element to left */
}
I hope this works for you. :)
P.S. I have removed all the <br> tags inside the <form>
I have 2 divs that I want to position close together, however they keep moving eachother. They are both under the main div.
HTML:
<div id="header">
<div id="title">Social</div>
</div>
<div id="main">
<div id='notif'><strong>Incorrect details.</strong>
</div>
<div id="signin">
<form name="signinform" action="authenticate.php" method="post" onsubmit="return validate(this)" id="signinform">
<p>
<input placeholder="Username / Email" class="input" type="text" name="user" id="user" maxlength="50">
</p>
<p>
<input placeholder="Password" class="input" type="password" name="password" id="password" maxlength="50">
</p>
<p>
<input type="checkbox" name="remember" id="remember" value="checked">
<label for="remember">Remember me</label>
</p>
<p>
<input class="button" type="submit" value="Sign in">
</p>
</form>
</div>
</div>
The CSS is as follows:
Main body which both divs comes under:
#main {
padding-top: 50px;
}
Form div:
#signin {
padding-top: 5px;
padding-bottom: 5px;
width: 400px;
margin: auto;
margin-top: 150px;
}
Error div:
#notif {
padding-top: 5px;
padding-bottom: 5px;
width: 400px;
height: 20px;
margin: auto;
margin-top: 140px;
}
I know that perhaps it has something to do with the position attribute..
Here is an image of what it looks like now, as you can see, I want both of the center objects to be close together without pushing each other away from the vertical center.
remove the margin-top from the #signin div - as this is what is putting pixels between the #notif div and the #signin div.
#main {
padding-top: 50px;
}
#signin {
padding-top: 5px;
padding-bottom: 5px;
width: 400px;
margin: auto;
}
#notif {
padding-top: 5px;
padding-bottom: 5px;
width: 400px;
height: 20px;
margin: auto;
margin-top: 140px;
}
<div id="header">
<div id="title">Social</div>
</div>
<div id="main">
<div id='notif'><strong>Incorrect details.</strong>
</div>
<div id="signin">
<form name="signinform" action="authenticate.php" method="post" onsubmit="return validate(this)" id="signinform">
<p>
<input placeholder="Username / Email" class="input" type="text" name="user" id="user" maxlength="50">
</p>
<p>
<input placeholder="Password" class="input" type="password" name="password" id="password" maxlength="50">
</p>
<p>
<input type="checkbox" name="remember" id="remember" value="checked">
<label for="remember">Remember me</label>
</p>
<p>
<input class="button" type="submit" value="Sign in">
</p>
</form>
</div>
</div>
Debugging
In this sort of situation, your page inspector is going to be your best friend.
In chrome, for example, when the page inspector is open, hovering an element will show you the margins of the element, as well as any padding being given to it.