This is the content of <body> tag.
<div id="border">
<p><h1 style="text-align: center;">Welcome to ABC Airline!</h1></p>
<table caption="Choose your seat preference"
style="margin-bottom: 1.5em; margin-left: auto; margin-right: auto;">
<tr>
<td><p id="dd">Window Side<input type="radio" name="side"/></p></td>
<td><p id="dd">Front of plane<input type="radio" name="frontorback"/></p></td>
</tr>
<tr>
<td><p id="dd">Aisle Side<input type="radio" name="side"/></p></td>
<td><p id="dd">Middle of plane<input type="radio" name="frontorback"/></p></td>
</tr>
<tr>
<td><p id="dd">Center Seat<input type="radio" name="side"/></p></td>
<td><p id="dd">Back of plane<input type="radio" name="frontorback"/></p></td>
</tr>
</table>
<p><input type="submit" value="next" style="float: right;"></p>
</div>
styles are defined like this:
#border{
border: 2px solid black;
border-radius: 25px;
width: 50%;
margin: auto;
background-color: #ffc;
}
#dd{
margin: 0.2em 0.2em 0.2em 0.2em;
}
And, this is the result run with Chrome in macOS.
The button is on the right side as I intended but it's out of the div block.. When style="float: right;" is not defined, it is not aligned to right but in the border.
I'd like to keep this inside the border. What should I do?
Giving overflow: hidden fixes this. It is because of clearfix. This is the fix you are looking for:
#border {
overflow: hidden;
padding-bottom: 10px;
}
I have given an extra bottom padding to facilitate the whole button, instead of cutting it. You may even give a margin-right to the button to make it out of the border cut.
Snippet
#border {
border: 2px solid black;
border-radius: 25px;
width: 50%;
margin: auto;
background-color: #ffc;
overflow: hidden;
padding-bottom: 10px;
}
#dd {
margin: 0.2em 0.2em 0.2em 0.2em;
}
<div id="border">
<p>
<h1 style="text-align: center;">Welcome to ABC Airline!</h1>
</p>
<table caption="Choose your seat preference" style="margin-bottom: 1.5em; margin-left: auto; margin-right: auto;">
<tr>
<td>
<p id="dd">Window Side
<input type="radio" name="side" />
</p>
</td>
<td>
<p id="dd">Front of plane
<input type="radio" name="frontorback" />
</p>
</td>
</tr>
<tr>
<td>
<p id="dd">Aisle Side
<input type="radio" name="side" />
</p>
</td>
<td>
<p id="dd">Middle of plane
<input type="radio" name="frontorback" />
</p>
</td>
</tr>
<tr>
<td>
<p id="dd">Center Seat
<input type="radio" name="side" />
</p>
</td>
<td>
<p id="dd">Back of plane
<input type="radio" name="frontorback" />
</p>
</td>
</tr>
</table>
<p>
<input type="submit" value="next" style="float: right;">
</p>
</div>
Preview
The simple answer is 'use overflow auto to force BFC', like this:
overflow: auto;
Source: Why does overflow: hidden have the unexpected side-effect of growing in height to contain floated elements?
I am trying to float the submit button to the right in the form but I am facing problem the float is not being applied on the submit button Login. I have added some of server-side generated code.
Code
#login-form{
width: 400px;
background-color: #6B0000;
color: white;
}
#loginButton{
color: #6B0000;
border: 1px solid;
padding: 5px 30px 5px 30px;
background-color: white;
border-radius: 3px;
/*This one here does not work */
float: right;
}
<body>
<header id="header">
<h1>
Google Maps & Yahoo Mashup
</h1>
</header>
<DIV id="content">
<form id="login-form" name="login-form" method="post" onSubmit='return false'>
<input type="hidden" name="login-form" value="login-form" />
<table>
<tbody>
<tr>
<td><label>Email</label></td>
<td><input id="login-form:email" type="text" name="login-form:email" /></td>
</tr>
<tr>
<td><label>Password</label></td>
<td><input id="login-form:pwd" type="text" name="login-form:pwd" /></td>
</tr>
<tr>
<td><input type="submit" value="Login" id="loginButton" /></td>
</tr>
</tbody>
</table>
<input type="hidden" name="javax.faces.ViewState" id="j_id1:javax.faces.ViewState:0" />
</form>
</DIV>
</body>
Try this one. I set a colspan of 2 to the input button and gave its parent td a width of 100%, this along with the float right should shift it to the right.
#login-form{
width: 400px;
background-color: #6B0000;
color: white;
}
#loginButton{
color: #6B0000;
border: 1px solid;
padding: 5px 30px 5px 30px;
background-color: white;
border-radius: 3px;
/*This one here does not work */
float: right;
}
/* Make the input's parent td 100%, you may want
a class here instead for browser support */
td:last-child {
width: 100%;
}
<body>
<header id="header">
<h1>
Google Maps & Yahoo Mashup
</h1>
</header>
<DIV id="content">
<form id="login-form" name="login-form" method="post" >
<input type="hidden" name="login-form" value="login-form" />
<table>
<tbody>
<tr>
<td><label>Email</label></td>
<td><input id="login-form:email" type="text" name="login-form:email" /></td>
</tr>
<tr>
<td><label>Password</label></td>
<td><input id="login-form:pwd" type="text" name="login-form:pwd" /></td>
</tr>
<tr>
<!-- setting a colspan of two -->
<td colspan="2"><input type="submit" value="Login" id="loginButton" /></td>
</tr>
</tbody>
</table>
<input type="hidden" name="javax.faces.ViewState" id="j_id1:javax.faces.ViewState:0" />
</form>
</DIV>
</body>
I have this table:
<table>
<tr>
<td>
<input type="text" class="half"/>
<input type="text" class="half" />
</td>
<td>
<input type="text"/>
</td>
<td>
<input type="text"/>
</td>
</tr>
</table>
CSS:
table {
width: 100%;
border-spacing: 0;
}
.half {
float: left;
width: 50%;
}
How can I have two input fields next to each other each filling up 50% of the table cell's (natural / normal) width?
Right now, this doesn't work. The table cells containing the input fields of class half are far too wide and I can't see why this happens.
You need two things: DEMO
avoid the white-space in between inline-block element (you may then drop the float property).
include border size into width.
First, the easiest way is to remove white-space from html code and write it so :
<input ... /><input ... />
Second, is to switch to another box-model so :
box-sizing:border-box;
Add vendor-prefix whenever needed .
How about applying .half to the <td> parent?
<td class="half">
<input type="text" />
<input type="text" />
</td>
How about :
<table border="2px">
<tr>
<td>
<input type="text" class= "half"/>
<input type="text" class= "half"/>
</td>
<td>
<input type="text"/>
</td>
<td>
<input type="text"/>
</td>
</tr>
</table>
.css
table {
width: 100%;
border-spacing: 0;
}
td{
padding-left: 5px;
}
.half {
float: left;
width: 49%;
margin: 2px;
}
A quick way to resolve this, wrap then inputs in a span tag. Set the span to inline-block 50%, and the inputs to 100%. Using a box model maintains the inputs in the td
http://jsfiddle.net/HgxFf/
<table>
<tr>
<td>
<span><input type="text" class="half"/></span>
<span><input type="text" class="half" /></span>
</td>
<td>
<input type="text"/><input type="text"/>
</td>
<td>
<span><input type="text"/></span>
</td>
</tr>
</table>
CSS
table {
width: 100%;
border-spacing: 0;
}
td{border:1px solid #000000;font-size:0px; }
span{
display:inline-block;
width:50%;
padding:0px
}
.half {
width: 100%;
}
input[type="text"]{
box-sizing:border-box;
}
}
I have problem with floating on contact page. Here is the following code.
HTML
<div class="contact">
<form class="form" method="post" action="">
<table>
<tr>
<td class="contact-firstcol">
<label for="name">Name</label>
</td>
<td class="contact-secondcol">:</td>
<td class="contact-thirdcol">
<input type="text" name="name" id="name" />
</td>
</tr>
<tr>
<td class="contact-firstcol">
<label for="email">Email</label>
</td>
<td class="contact-secondcol">:</td>
<td class="contact-thirdcol">
<input type="text" name="email" id="email" />
</td>
</tr>
<tr>
<td class="contact-firstcol">
<label for="phone">Phone</label>
</td>
<td class="contact-secondcol">:</td>
<td class="contact-thirdcol">
<input type="text" name="phone" id="phone" />
</td>
</tr>
<tr>
<td class="contact-firstcol">
<label for="topic">Topic</label>
</td>
<td class="contact-secondcol">:</td>
<td class="contact-thirdcol">
<div class="styled-select select">
<select class="dropdown">
<option value="generalQuestion">General Question</option>
</select>
</div>
</td>
</tr>
<tr>
<td class="contact-firstcol">
<label for="message">Message</label>
</td>
<td class="contact-secondcol">:</td>
<td class="contact-thirdcol">
<textarea id="message" name="message"></textarea>
</td>
</tr>
<tr>
<td class="contact-firstcol"></td>
<td class="contact-secondcol"></td>
<td class="contact-thirdcol">
<input type="reset" name="reset" value="CLEAR" />
<input type="submit" name="submit" value="SUBMIT" />
</td>
</tr>
<table>
</form>
</div>
<div class="aside">
<p>Email</p>
<p>Telephone</p>
<p>Address</p>
</div>
CSS
.contact {
float:left;
width:68%;
margin:20px 0 0 0;
padding:10px;
}
.aside {
float:left;
width:27%;
margin:20px 0 0 0;
padding:10px;
background-color:#CECECE;
}
#home-contact p {
font-family:'alegreya_sansregular';
letter-spacing:0;
}
table {
line-height:30px;
margin:20px;
display:inline-block;
}
td {
vertical-align:top;
}
.contact-firstcol {
font-family:'alegreya_sansregular';
width:100px;
font-size:17px;
color:#999;
}
.contact-secondcol {
font-family:'alegreya_sansregular';
width:20px;
text-align:center;
font-size:17px;
color:#999;
}
.contact-thirdcol {
width:300px;
color:#999;
}
.form {
margin-top:20px;
}
.form input, textarea {
padding: 5px;
margin: 2px 5px;
border: solid 1px #E5E5E5;
outline: 0;
font: normal 12px/100% Verdana, Tahoma, sans-serif;
width: 280px;
background: -webkit-gradient(linear, left top, left 25, from(#FFFFFF), color-stop(4%, #EEEEEE), to(#FFFFFF));
background: -moz-linear-gradient(top, #FFFFFF, #EEEEEE 1px, #FFFFFF 25px);
box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 8px;
-moz-box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 8px;
-webkit-box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 8px;
max-height:300px;
resize:none;
}
.form textarea {
width:280px;
max-width:280px;
height:100px;
max-height:100px;
line-height:150%;
}
input[type="submit"], input[type="reset"] {
color:#FFF;
background:rgba(100, 100, 100, 1);
border:none;
width:100px;
letter-spacing: 1px;
font-family:'alegreya_sansregular', sans-serif;
font-size:17px;
cursor:pointer;
}
input[type="submit"]:hover, input[type="reset"]:hover {
background:rgba(100, 100, 100, 0.5);
-o-transition:.5s;
transition:.5s;
-ms-transition:.5s;
-moz-transition:.5s;
-webkit-transition:.5s;
}
.styled-select select {
width:293px;
padding-top:2px;
color:#999;
margin-left:5px;
border:1px solid #CCC;
height:28px;
font-size:15px;
background: -webkit-gradient(linear, left top, left 25, from(#FFFFFF), color-stop(4%, #EEEEEE), to(#FFFFFF));
background: -moz-linear-gradient(top, #FFFFFF, #EEEEEE 1px, #FFFFFF 25px);
box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 8px;
-moz-box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 8px;
-webkit-box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 8px;
}
-webkit-appearance: none;
}
.styled-select {
width: 240px;
height: 34px;
overflow: hidden;
background: url(../images/arrowdown.png) no-repeat right #ddd;
border: 1px solid #ccc;
}
Can you help how to fix this?
I want to make .contact and .aside float left very well. But it turned out that .aside didn't float at all, and stay at .contact.
I tried to removed one by one and I spotted after I removed table tag, it's working well. But as soon as I insert table tag, it didn't work at all..
And here is JSFIDDLE for you to understand more clearly.
Thanks! Looking forward to hear from you!
IF you resize the window on your jfiddle to allow for more space on the actual display you'll see that if you make it big enough it will float left as you expect. I think the issue is the widths you have set as if there is not enough room. If there is not enough room for an element to float, it will be placed below the other element or "wrap to the next line" as it were.
edit: Props to pankaj for noticing that yout table closing tag was missing the / (</table>) for cleanliness, though it Shoudln't have affected the div floats.
There was a small typo in the code that you shared. The closing tag of table wasn't proper. Check that.
Also, since you have given width in %age along with some padding for both .aside and .contact, it is messing with the calculation.
If I remove the padding from both .aside(32% width) and .contact(68% width), the divs are coming side by side. You can create another internal div to give proper padding.
Updated your jsfiddle link - http://jsfiddle.net/28CEE/1/
Here is the modified css:
.contact {
float:left;
width:68%;
margin:20px 0 0 0;
}
.aside {
float:left;
width:32%;
margin:20px 0 0 0;
background-color:#CECECE;
}
Be sure to close your </table> in your fiddle. You shouldn't need to change the display property of a table (you have it set to inline-block). As well, you might check your padding properties so they are percentage based (so they match your width units). You could also change the asides float to right.
You can try like this: LINK
HTML:
<div class="aside">
<p>Email</p>
<p>Telephone</p>
<p>Address</p>
</div>
<div class="contact">... </div>
Suppose if you want to float "aside" to right... use float:right instead of left
add css class
.form {
width: 68%;
float: left;
}
set width for contact like (width: 88%;)
close table tag </table>, set a active after form
<div class="contact">
<form class="form" method="post" action="">
<table>
<tr>
<td class="contact-firstcol"> <label for="name">Name</label> </td>
<td class="contact-secondcol"> : </td>
<td class="contact-thirdcol"> <input type="text" name="name" id="name" /> </td>
</tr>
<tr>
<td class="contact-firstcol"> <label for="email">Email</label> </td>
<td class="contact-secondcol"> : </td>
<td class="contact-thirdcol"> <input type="text" name="email" id="email" /> </td>
</tr>
<tr>
<td class="contact-firstcol"> <label for="phone">Phone</label> </td>
<td class="contact-secondcol"> : </td>
<td class="contact-thirdcol"> <input type="text" name="phone" id="phone" /> </td>
</tr>
<tr>
<td class="contact-firstcol"> <label for="topic">Topic</label> </td>
<td class="contact-secondcol"> : </td>
<td class="contact-thirdcol">
<div class="styled-select select">
<select class="dropdown">
<option value="generalQuestion"> General Question </option>
</select>
</div>
</td>
</tr>
<tr>
<td class="contact-firstcol"> <label for="message">Message</label> </td>
<td class="contact-secondcol"> : </td>
<td class="contact-thirdcol"> <textarea id="message" name="message"></textarea> </td>
</tr>
<tr>
<td class="contact-firstcol"></td>
<td class="contact-secondcol"></td>
<td class="contact-thirdcol"> <input type="reset" name="reset" value="CLEAR" /> <input type="submit" name="submit" value="SUBMIT" /> </td>
</tr>
</table>
</form>
<div class="aside">
<p> Email </p>
<p> Telephone </p>
<p> Address </p>
</div>
</div>
I have a simple contact form within a div but I can't get it to center within the div. I have tried margins, padding, text-align:center but none of them work.
html: http://www.joekellywebdesign.com/churchsample/contact.html
<div id="contactbottomright">
<h2>Contact Form</h2>
<form action="feedback.php" method="post">
<table border="0" cellpadding="8" cellspacing="8">
<tr>
<td>
<label for="tswname">Name</label>:</td>
<td>
<input type="text" name="fullname" id="tswname" size="25" />
</td>
</tr>
<tr>
<td>
<label for="tswemail">Email address</label>:</td>
<td>
<input type="text" id="tswemail" name="email" size="25" />
</td>
</tr>
<tr>
<td colspan="2">
<label for="tswcomments">Comments</label>
<br />
<textarea rows="15" cols="35" name="comments" id="tswcomments"></textarea>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" value="Submit" />
<br />
</td>
</tr>
</table>
</form>
</div>
css: http://www.joekellywebdesign.com/churchsample/css/styles.css
/* rules for contact page */
#contactbottomleft {z-index:26; width:450px;height: 700px; background-color:#92B681; margin: 30px 0 0 0; float:left;position: relative;}
#contactbottomright { z-index:27; width:450px; height: 700px; margin: 30px 0 0 0px; background-color:#428C3E; float:right;position: relative;}
form {
display: inline-block;
text-align: center;
}
/* end rules for contact page */
You could set a width to the form and then add margin: 0 auto; to the CSS. For example:
HTML:
<div>
<form></form>
</div>
CSS:
form {
margin: 0 auto;
width: 300px;
}
NOTE: For this to work, you must remove display:inline-block from form.
JS Fiddle Example (using your HTML/CSS).
You must set a Width of Ancestor element and then add margin:0 auto to its child.
See demo