The 'required' text is showing up to the left of the input box. Similar problem in Opera except is displays on the next line (creates a line break). Looks as expected in FF3.1 and chrome. Any suggestions? Eventually I would like to use the display:none attribute on the 'required' span and show this span as necessary with javascript.
<html>
<head>
<title></title>
<style type="text/css">
<!--
input.missing { background-color: #FFFF77; }
div.row {
clear: both;
padding-top: 5px;
}
div.row span.label {
float: left;
width: 100px;
text-align: right;
}
div.row span.formw {
// float: right;
width: 235px;
text-align: left;
padding-right: 0px;
padding-left: 45px;
}
div.spacer {
clear: both;
}
.container{
width: 425px;
background-color: #ccc;
border: 1px dotted #333;
padding: 5px 5px 5px 5px;
margin: 0px auto;
}
.error{
color: #ff0000;
}
.required{
color: #ff0000;
float: right;
// display:none;
// display:inline;
}
-->
</style>
</head>
<body>
<div id="contact_form">
<form action="/jr/index.php" method="POST" id="contact">
<div id="top_message" style="width: 360px; margin: 10px auto;">
Enter Your Information Below</div>
<div class="container">
<div class="row">
<span class="label">Name:</span>
<span class="formw"><input size="30" maxlength="30" name="name" id="name" value=""></span>
</div>
<div class="row">
<span class="label">Email:</span>
<span class="formw"><input size="30" maxlength="30" name="email" id="email" value=""></span>
<span id="email_error" class="required">(required)</span>
</div>
<div class="row">
<span class="label">Shoe size:</span><span
class="formw"><input type="text" size="25" /></span>
</div>
<div class="row">
<span class="formw">
<input type="image" value="submit" name="submit" class="button" src="submit.png" alt="Submit" /></span>
</div>
<div class="spacer">
</div>
</div>
<div id="message_ajax" style="width: 360px; margin: 10px auto;"></div>
</form>
</div>
</body>
</html>
IE really makes me hate web dev sometimes.
You probably should start by adding the proper DocType tag at the top of your file.
EDIT:
After looking at your code, it appears you are not using your floats properly. First off - // does NOT comment out lines in a CSS file. You need to wrap it in /* and */ to comment it out. So your SPAN.formw style is floating to the right, which is before your SPAN.required, which also floats right. Since you're using SPAN tags, you really don't need to float anything here. If you remove all of those it should just fall into place for you.
Which doctype are you using ? A strict one may prevent that kind of problem... Also, I usually start my CSS design with a reset file to get rid of all those kind of annoyances : http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/
Using double slash "//" is not valid CSS commenting. So this float right rule:
div.row span.formw { // float: right;
Is being applied.
Use:
/* comment */
When commenting CSS.
Put a float:left on the formW class
Float all the boxes in the row to the left, instead of mixing floating and inline elements:
div.row span.label {
float: left;
width: 100px;
text-align: right;
}
div.row span.formw {
float: left;
width: 235px;
padding-left: 45px;
}
.required{
float: left;
color: #ff0000;
// display:none;
}
jriggs, since IE8 is still not completely stable, for some projects you can have IE8 revert to IE7 rendering rules. One of the benefits is that this doesn't give the user the compatibility view button on the right of the location bar.
For more info and specifics see
http://blogs.msdn.com/ie/archive/2008/06/10/introducing-ie-emulateie7.aspx
Related
I've got a static site, which is all of a sudden displaying irregular headings. This is a single page with lots of JavaScript including tabular selections at the top of the page. The site worked just fine six months ago. Now I'm seeing unexplained mis-alignment of input elements on a half of the 12 different navigation tabs:
Decorative Ends
Round to Tapered
Bracing
Round to Square
Round to Flat
Airframe Cluster
The headings contained within a form:
<form id="dte_form">
<div class="containerLeft">...</div>
<div class="containerLeft">...</div>
<div class="containerLeft">
<label title="Data can.. [hover info]">Tube O.D. (mm): </label>
<input type="text" id="dteCutTubeOD" value="31.75" size="8">
<br>
<label>Amplitude (mm):</label>
<input type="text" id="dteAmplitude" value="25.4" size="8">
<br>
<label># of Cycles:</label>
<input type="text" id="dteNumOfCycles" value="3" size="8">
<br>
</div>
<div style="clear: both"></div>
<div class="containerLeft">
<input type="button"...>
<input type="button"...>
<input type="button"...>
<input type="button"...>
</div>
</form>
The CSS is nothing fancy:
.containerLeft {
float: left;
margin: 4px 20px;
}
.containerLeft label {
float: left;
height: 21px;
margin: 8px 5px 0 5px;
}
.containerLeft input[type=text] {
float: right;
height: 15px;
margin: 4px 5px;
padding-left: 5px;
}
The heading should look like this:
Basically, in a div, I would float the label left, float the input element right, add a <br> and repeat. I can't figure out why occasionally the elements don't line up correctly. I'm sure I'm missing something silly, but I just can't see it. Any ideas what is causing the occasional misalignment?
Click here for website. Note. I'm seeing the same results in both Chrome and Firefox.
This is what happens when you use floats. They overlap following blocks and shrink line boxes.
If you want to prevent an block element from being adjacent to a float, just use clear.
.float {
float: left;
width: 50px;
height: 3em;
border: 1px solid;
background: yellow;
}
.normal, .clear {
height: 2em;
border: 1px solid;
background: pink;
}
.clear {
clear: left;
}
<div class="float">Float</div>
<div class="normal">Normal</div>
<div class="normal">Normal</div>
<br /><br />
<div class="float">Float</div>
<div class="normal">Normal</div>
<div class="clear">Clear</div>
So apparently the issue is related to element height. Note that the label and input elements have different heights. This was done for appearance. In some combinations and element lengths the float thing gets futzed up.
The corrective action was to modify the CSS style sheet in one place:
.containerLeft label {
clear: both; /* new addition to this element */
float: left;
height: 21px;
margin: 8px 5px 0 5px;
}
An alternative would be to use <div style="clear: both"></div> in lieu of the <br> elements (or use the handy CSS library classes offered up by Oriol)
I have been looking everywhere for help on this issue with Css layout width I have been running into.
Whenever I float a div to the right its width won't automatically adjust to the total width of its children. I have observed this effect on all common browsers (Firefox, Chrome and IE11/Edge). What happens is that the last child will just be displayed bellow all the others which is what I do not want.
Here is the css and html I have been using.
https://jsfiddle.net/xqpf9s95/2/
*
<div id="header-container">
<div id="header-top-container">
<div id="header-logo">
<a href="/GlobalImagens/pages/imagens.xhtml?categoria=ultima-hora">
<img src="../resources/images/logo_globalimagens.jpg" alt="Global Imagens"></a>
</div>
<div class="header-top-right-corner">
<form id="language" name="language" method="post" action="/GlobalImagens/pages/imagens.xhtml" enctype="application/x-www-form-urlencoded">
<input name="language" value="language" type="hidden">
<div id="newsletter" class="newsletter">
Subscrever Newsletter
</div>
<div style="float: right; padding-left: 6%;">
<script type="text/javascript" src="/GlobalImagens/javax.faces.resource/jsf.js.xhtml?ln=javax.faces&stage=Development"></script>
<a href="#" style="text-decoration:none; " onclick="mojarra.jsfcljs(document.getElementById('language'),{'language:j_idt31':'language:j_idt31','localeCode':'en'},'');return false">
<img src="../resources/images/flag_uk.jpg" border="0"></a>
</div>
<div style="float: right;">
<a href="#" style="text-decoration:none;" onclick="mojarra.jsfcljs(document.getElementById('language'),{'language:j_idt35':'language:j_idt35','localeCode':'pt'},'');return false">
<img src="../resources/images/flag_pt.jpg" border="0"></a>
</div>
<input name="javax.faces.ViewState" id="j_id1:javax.faces.ViewState:0" value="215900126811062761:3093351618596041247" autocomplete="off" type="hidden">
</form>
</div>
<div id="admin-container">
<div>
<span class="admin-menu1" style="padding-left: 1.5%;">Iniciar Sessão
</span>
<span class="dotted-separator"></span>
<span style="padding-left: 1.5%;">Registo
</span>
<span class="admin-menu3"><a href="/GlobalImagens/pages/entrar.xhtml">
<img src="../resources/images/bt_minhaconta.jpg" title="A Minha conta" alt="A Minha conta"></a>
</span>
<span class="dotted-separator"></span>
<span class="admin-menu4"><a href="/GlobalImagens/pages/entrar.xhtml">
<img src="../resources/images/bt_carrinho.jpg" title="Meu carrinho" alt="Meu carrinho"></a>
</span>
</div>
<div>
<div align="right">
<span style="color: #83266f; padding-right: 5px;">Não pode adquirir imagens</span>(detalhes)
</div>
</div>
</div>
</div>
/*tables header*/
.admin-menu1 {
padding-right: 1.5%;
}
.dotted-separator {
border: none;
border-left: 1px dotted #83256f;
color: #fff;
/* background-color:#dadada;
height:17px;
width:0%;
margin: 0%; */
}
.admin-menu2 {
padding-left: 10px;
background: url(../images/background_dot.jpg) no-repeat right;
}
.admin-menu-logged-in-3 {
padding-left: 1.5%;
}
.admin-menu3 {
/* width: 75px; */
}
.admin-menu4 {
/* width: 28px; */
}
/*******************************HEADER*******************************/
#header-container {
/* height: 180px; */
/* float: left; */
}
#header-top-container {
/* width: 983px; */
/* height: 100px; */
/* float: left; */
}
#header-logo {
padding-top: 1%;
float: left;
}
#header-logo img {
border: none;
border-style: none;
}
.newsletter {
float: left;
padding-top: 1%;
}
.header-top-right-corner {
float: right;
padding-top: 1%;
width: 11%;
}
#admin-container {
padding-top: 1%;
font-size: 10px;
clear: right;
float: right;
box-sizing: border-box;
}
#admin-container a {
text-decoration: none;
color: #493641;
}
#admin-container a:hover {
text-decoration: underline;
}
*
And my issue is with the div "#admin-container".
How do I fix this so as to make that div auto adjust to the correct width and display without breaking its children elements?
Cheers and thank you.
EDIT: I have editted the code as asked by #Dzijeus. As I have commented, the images don't matter for the issue. My issue is with why the width won't auto adjust on the '#admin-container' to fit all its children.
Thanks for updating the code, it was better, but still far from a minimum verifiable example. A minimum example is when you strip as much as you can from the code while still reproducing the problem.
In your case, if you had done the exercise, you would probably have come to something like this:
<div id="admin-container">
<span class="admin-menu1">Iniciar Sessão</span>
<span>Registo</span>
<span>A Minha conta</span>
<span>Meu carrinho</span>
</div>
.admin-menu1 {
padding-right: 1.5%;
}
#admin-container {
clear: right;
float: right;
}
And you would immediately have seen the interest of doing this, AND solved the problem. Because from here, it is easy to notice that the problem is coming from using a relative padding. Switch to for example padding-right: 2px, and the display is now as you expected it.
As a general rule, padding and margin does not apply to inline elements such as span. To apply padding or margin you should use display: block or display: inline-block
I'm curious why I get different results on Chrome and Firefox with this simple code:
Breaks on Chrome
Works on both Firefox, IE and Chrome
The only difference is in HTML layout:
<div class="container">
<div class="form-wrapper">
<input class="email" type="text">
<button class="send pull-right">Send</button>
</div>
</div>
versus this:
<div class="container">
<div class="form-wrapper">
<input class="email" type="text"><button class="send pull-right">Send</button>
</div>
</div>
Any recommended fix without ugly hacks and HTML changes?
<input> isn't block elements by default. You must use float:left for them:
.form-wrapper {overflow:hidden;}
input.email, button.send{float:left}
Method 1:
/* CSS used here will be applied after bootstrap.css */
.form-wrapper {
background-color: #000;
padding: 10px;
font-size: 0; /*set font-size to zero*/
}
input.email {
background-color: #fff;
border: none;
height: 50px;
width: 70%;
padding-left: 15px;
padding-right: 15px;
font-size: 16px; /*reset font-size*/
}
button.send {
background-color: grey;
border: none;
height: 50px;
width: 30%;
font-size: 16px; /*reset font-size*/
}
working demo
Method 2:
Use float for inputs and clear the float using overflow:hidden to parent div.
demo
I'm trying to make a very simple form (picture above) with three columns but without using tables. Unfortunately for me, it's not as simple in code for me as it was in Photoshop. I've been fighting with the HTML/CSS below for an hour and this is the best I could get. Is there any chance somebody could please help me with my code?
<style type="text/css">* {
}
.containerANE {
overflow: hidden;
background: #C6DEFF;
width: 992px;
}
.rightANE {
float: right;
width: 30px;
outline: 1px solid #8191a6;
}
.leftANE {
float: left;
width: 152px;
outline: 1px solid #8191a6;
}
.middleANE {
width:717px;
outline: 1px solid #8191a6;
}</style>
<h1>E-mail US</h1>
<form action="confirmed.php" method="get">
<div class=containerANE>
<div class=rightANE>
<img width="25" src="Help-icon.png">
</div>
<div class=leftANE>
Name
</div>
<div class=middleANE>
<input type="text">
</div>
<div class=rightANE>
<img width="25" src="Help-icon.png">
</div>
<div class=leftANE>
Description
</div>
<div class=middleANE>
<textarea rows="4" cols="50">
</textarea>
</div>
<div class=rightANE>
<img width="25" src="Help-icon.png">
</div>
<div class=leftANE>
E-mail<br><br>Phone
</div>
<div class=middleANE>
<input type="text">
<br> OR <BR>
<input type="text">
</div>
<input type="submit" value="SUBMIT">
Your using floats. so you need a clearfix.
Try adding group to the div's your floating:
.group:after {
content: "";
display: table;
clear: both;
}
your example fixed with .group :
http://jsfiddle.net/agconti/YvQEs/
Adding a clearfix is the best practice way to do it. You can add this class to any element that you're floating to solve similar issues in the future. Additionally the link above will tell you all you need to know about how to use it.
Also, you need to wrap your class names with quotes like class="right" instead of class=right for the classes to apply.
clear add clear right on class .rightANE
.rightANE {
float: right;
width: 30px;
outline: 1px solid #8191a6;
clear: right;
}
Im trying to get away from using the html TABLE tag, but cant figure out how to build, what I want it to look like. I have made a screenshot of me using the table tag,
How would I do this with divs or/and spans etc, and still retain the vertical alignment of the labels (firstname, lastname in this example)?
(font size and color etc is of course irrelevant here)
alt text http://img522.imageshack.us/img522/7857/forme.jpg
thankful for any input,
modano
It's good that you don't want to use the table tag for layout. The thing to keep in mind when switching is to try to make the HTML as semantical as possible. What this means might vary, since there are no real strict rules, but it could look something along these lines:
<form [..]>
<ul>
<li class="hasError">
<em class="feedback">error message here</em>
<div class="attribute">
<label for="firstName">First name:</label>
<em>(required)</em>
</div>
<div class="input">
<input type="text" name="firstName" id="firstName" />
<em class="description">optional description here</em>
</div>
<span class="clearBoth" />
</li>
<li>
<em class="feedback" />
<div class="attribute">
<label for="firstName">Last name:</label>
<em>(required)</em>
</div>
<div class="input">
<input type="text" name="lastName" id="firstName" />
<em class="description">optional description here</em>
</div>
<span class="clearBoth" />
</li>
</ul>
</form>
This achieves the following:
By placing the error feedback message above the divs, you can make an arbitrarily long error message without losing alignment
Each input element (and label) is kept in a single list item, thus grouping them logically. It also reads something like the following in a screen reader: "Form. List of two items. Label [...]". This gives the user a hint of that the form contains two inputs.
By adding the hasError class to a list item, you can easily target the descendant elements with CSS for error specific styling.
A sample CSS file could look something like (note that this is untested):
form li {
width: 300px;
}
form li.hasErrors {
width: 298px;
border: 1px red;
background-color: #C55;
}
form .attribute {
float: left;
clear: left;
width: 60px;
}
form .input {
float: right;
clear: none;
width: 240px;
}
form .feedback {
display: block;
padding-left: 50px;
color: red;
}
form .description {
display: block;
clear: both;
color: #888;
}
.clearBoth { display: block; clear: both; }
A very very good tutorial on creating accessible HTML/CSS forms can be found on A list Apart: Prettier Accessible Forms
Generally a fantastic site for information on how to create good, clean and accessible websites.
Simply give your labels a specific width; this will ensure your fields line up. You can also float your labels and inputs to easily break them into rows. Here's a minimal example:
<style type="text/css">
form { overflow: auto; position: relative; }
input { float: left; }
label { clear: left; float: left; width: 10em; }
</style>
<form>
<label>Field 1</label><input/>
<label>Field 2</label><input/>
<label>Field 3</label><input/>
</form>
I am no CSS expert, but this should get you started. Of course the styles should be in an external style sheet.
<html>
<head>
<style>
html {
font-size: 76%;
}
body {
font-size: 1.0em;
font-family: verdana;
}
div.input {
border: 1px solid white;
clear: left;
width: 25em;
height: 5em;
padding: 2px;
margin-bottom: 1.0em;
}
div.error {
border: 1px solid red;
}
div.label {
float: left;
width: 7em;
}
div.field {
float: left;
}
div.errormessage {
color: red;
}
div.description {
color: #bbb;
}
input.text {
width: 13em;
}
</style>
</head>
<body>
<form>
<div class="input error">
<div class="label">
<div> </div>
<label>First name:<br>(required)</label>
</div>
<div class="field">
<div class="errormessage">error message here</div>
<input type="text" name="FirstName" class="text">
<div class="description">optional description here</div>
</div>
</div>
<div class="input">
<div class="label">
<div> </div>
<label>Last name:<br>(required)</label>
</div>
<div class="field">
<div class="errormessage"> </div>
<input type="text" name="LastName" class="text">
<div class="description">optional description here</div>
</div>
</div>
</form>
</body>
</html>