I have table inside div , thing is if I change window size, table is coming out of div. please help me. Thanks in advance. Below is my code
<div style="height:auto">
<table width="100%" style="width: 100%;">
<thead>
<tr >
<th width="16.5%">sunday</th>
<th width="16.5%">monday</th>
<th width="16.5%">tuesday</th>
<th width="16.5%">wed</th>
<th width="16.5%">thu</th>
<th width="16.5%">fri</th>
</tr>
</thead>
<tbody>
<tr >
<td>111</td>
<td ><input value="" type="" name="" /></td>
<td ><input value="" type="" name="" /></td>
<td ><input value="" type="" name="" /></td>
<td ><input value="" type="" name="" /></td>
<td ><input value="" type="" name="" /></td>
</tr>
</tbody>
</table>
</div>
Add following css in you code
div{
width: 500px; /* you can apply any width to this div */
}
table{
table-layout:fixed;
border-spacing: 0;
border-collapse: separate;
}
table td{
padding: 5px;
}
input{
width: 100%;
box-sizing: border-box;
}
Check this Demo
Add this in CSS:
td input {
width: 90%;
margin: 0 auto;
}
You have to specify the text field size as a percentage
remove table header fixed width.
CSS
input{width:100%;}
HTML
<div style="background-color:#ccc;padding:5px">
<table >
<thead>
<tr >
<th >sunday</th>
<th >monday</th>
<th >tuesday</th>
<th >wed</th>
<th >thu</th>
<th>fri</th>
</tr>
</thead>
<tbody>
<tr>
<td>111</td>
<td ><input value="" type="text" name="" /></td>
<td ><input value="" type="text" name="" /></td>
<td ><input value="" type="text" name="" /></td>
<td ><input value="" type="text" name="" /></td>
<td ><input value="" type="text" name="" /></td>
</tr>
</tbody>
</table>
</div>
Working fiddle http://jsfiddle.net/G5y3T/1/
You should set your div style to display:inline-block;
Here you can see a demo
You should also use an extern css file rather then inline style. Much efficienter when you change something.
If you want the div to contain the table,you can use overflow: auto. This makes the div scrollable.
But if you don't want it to be scrollable, use display: table instead.
Related
Why rule in CSS does not work?
index.html - Two radio buttons. Can't correct HTML code, only CSS!
<table class="simplecheckout-methods-table">
<tbody>
<tr>
<td class="code">
<input type="radio" value="pickup.pickup"id="pickup.pickup" checked="checked">
</td>
<td class="title" valign="middle">
<label for="pickup.pickup">pickup</label>
</td>
</tr>
<tr>
<td class="code">
<input type="radio" value="flat1.flat1" id="flat1.flat1">
</td>
<td class="title" valign="middle">
<label for="flat1.flat1">flat1</label>
</td>
</tr>
</tbody>
</table>
style.css - How can I find this label. If label and input in one tr the code work fine. But as I write before I can't correct index.html
.simplecheckout-methods-table input:checked + label {
background: #B099C0;
}
Thank you for taking the time to read/answer this.
First thing: my career page has a pre-made contact form that i turned into a job application. I have two layout questions:
1.) How do i get the 'checkbox' buttons to line up a little closer to each other. I tried td colspan="2" which is the case later in the form for 2 buttons (submit/reset 1 which i removed), but to no avail, "No" appears well to the right of "Yes." I'd like to have it relatively closer to "Yes."
2.) When you pull the drop down for "Experience" down, it forces the image below the form. Once you select your option, the image goes back to its place. Do i absolutely have to absolute position the graphic? Or can i add an overflow maybe to the dropdown? I can't figure it out.
FancyForm is the form i'm using.
Here is the HTML:
<form id="contact-form" name="contact-form" method="post" action="submit.php">
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td width="15%"><label for="name">Name</label></td>
<td width="70%"><input type="text" class="validate[required,custom[onlyLetter]]" name="name" id="name" value="<?=$_SESSION['post']['name']?>" /></td>
<td width="15%" id="errOffset"> </td>
</tr>
<tr>
<td width="15%"><label for="address">Address</label></td>
<td width="70%"><input type="text" class="validate[required,custom[a-zA-Z\d\s\-\,\#\.\+]+]" name="address" id="address" value="<?=$_SESSION['post']['address']?>" /></td>
<td width="15%" id="errOffset"> </td>
</tr>
<tr>
<td width="15%"><label for="telephone">Telephone</label></td>
<td width="70%"><input type="text" class="validate[required,custom[onlyNumber]]" name="telephone" id="telephone" value="<?=$_SESSION['post']['telephone']?>" /></td>
<td width="15%" id="errOffset"> </td>
</tr>
<tr>
<td width="15%"><label for="email">Email</label></td>
<td width="70%"><input type="text" class="validate[required,custom[email]]" name="email" id="email" value="<?=$_SESSION['post']['email']?>" /></td>
<td width="15%" id="errOffset"> </td>
</tr>
<tr>
<td width="15%"><label for="citizenship">US Citizen</label></td>
<td width="35%"><input type="checkbox" name="citizen" value="yes">Yes</td>
<td width="35%"><input type="checkbox" name="citizen" value="no">No</td>
<td width="15%" id="errOffset"> </td>
</tr>
<tr>
<td width="15%"><label for="age">At Least 18</label></td>
<td width="35%"><input type="checkbox" name="age" value="yes">Yes</td>
<td width="35%"><input type="checkbox" name="age" value="no">No</td>
<td width="15%" id="errOffset"> </td>
</tr>
<tr>
<td width="15%"><label for="previousexp">Have you worked<br> with us before?</label></td>
<td width="35%"><input type="checkbox" name="previousexp" value="yes">Yes
<td width="35%"><input type="checkbox" name="previousexp" value="no">No</td>
<td width="15%" id="errOffset"> </td>
</tr>
<tr>
<td width="15%"><label for="subject">Experience</label></td>
<td width="70%"><select name="subject" id="subject">
<option value="" selected="selected"> - Choose -</option>
<option value="0-5">0-5 Years</option>
<option value="6-10">6-10 Years</option>
<option value="11-15">11-15 Years</option>
<option value="16-20">16-20 Years</option>
</select></td>
<td width="15%" id="errOffset"> </td>
</tr>
<tr>
<td><label for="captcha"><?=$_SESSION['n1']?> + <?=$_SESSION['n2']?> =</label></td>
<td><input type="text" class="validate[required,custom[onlyNumber]]" name="captcha" id="captcha" /></td>
<td valign="top"> </td>
</tr>
<tr>
<td valign="top"> </td>
<td colspan="2"><input type="submit" name="button" id="button" value="Submit" />
<?=$str?> <img id="loading" src="img/ajax-load.gif" width="16" height="16" alt="loading" /></td>
</tr>
</table>
</form>
CSS:
#form-container{
padding:0px;
}
td{
white-space:nowrap;
}
h1{
color:#777777;
font-size:22px;
font-weight:normal;
text-transform:uppercase;
margin-bottom:5px;
}
h2{
font-weight:normal;
font-size:10px;
text-transform:uppercase;
color:#aaaaaa;
margin-bottom:15px;
border-bottom:1px solid #484848;
margin-bottom:15px;
}
label{
text-transform:uppercase;
font-size:10px;
font-family:Tahoma,Arial,Sans-serif;
}
textarea{
color:#404040;
font-family:Arial,Helvetica,sans-serif;
font-size:12px;
}
td > button{
text-indent:8px;
}
Don't specify static percentile widths on the check boxes in question.
Use the:
margin-left:15px;
/* & */
margin-right:15px;
CSS properties on the checkboxes... To do this I would recommend giving the checkboxes a class of:
class="chk-close"
...or something meaningful... then use the class declaration, declared with a '.' (period / full stop) adding the new CSS declaration into your external CSS file.
aka:
.chk-close
{
margin: 0px -15px 0px -15px;
/* Will do all top, right, bottom, left... margin amounts */
}
Please comment on this if you would like any further support!
Suppose I have a table like so:
<table>
<tr>
<th>Type</th>
<th colspan="3">Type Info</th>
</tr>
<tr class="typeA">
<td><input name="type[0]" /></td>
<td class="group1"><input name="A[0]" disabled /></td>
<td class="group2"><input name="B[0]" disabled /></td>
<td class="group2"><input name="C[0]" disabled /></td>
</tr>
<tr class="typeB">
<td><input name="type[1]" /></td>
<td class="group1"><input name="A[1]" /></td>
<td class="group2"><input name="B[1]" disabled /></td>
<td class="group2"><input name="C[1]" disabled /></td>
</tr>
<tr class="typeC">
<td><input name="type[2]" /></td>
<td class="group1"><input name="A[2]" disabled /></td>
<td class="group2"><input name="B[2]" /></td>
<td class="group2"><input name="C[2]" /></td>
</tr>
</table>
There are certain data combinations that are not valid, so we disable the inputs. In this case, I believe the data makes semantic sense as a table - I am not just using a table for layout purposes.
What I would like to do is hide the disabled cells, and have the cells with the non-disabled elements fill the space formerly taken by the now hidden cells.
I can accomplish the hiding with the following css:
.typeA .group1, .typeA .group2 {
display:none;
}
.typeB .group2 {
display:none;
}
.typeC .group1 {
display:none;
}
However, this gives me:
|_____Type____|____________,__Type Info__,__________|
|_____________|
|_____________|____________|
|_____________|____________|_____________|
What I want is:
|_____Type____|____________,__Type Info__,__________|
|_____________|
|_____________|____________,_____________,__________|
|_____________|____________,_____________|__________|
(| represent cell boundaries, , represents where a single cell crosses the layout cell boundaries.
What css can I use to get the desired td to expand to fill the horizontal space vacated by the hidden td elements?
There does not appear to be a way to do this using solely CSS. It seems that to accomplish what I want, the html structure has to be modified in one way or another.
I found two options:
Do a row by row modification of the table structure, removing hidden td elements and adding appropriate colspan attributes to the visible td elements
Place all of the "group1" and "group2" inputs in the same cell, with additional div structures that can be styled as table cells.
For the second option, e.g.
<table>
<tr>
<th>Type</th>
<th>Type Info</th>
</tr>
<tr class="typeA">
<td><input name="type[0]" /></td>
<td>
<div class="group1">
<input name="A[0]" />
</div>
<div class="group2">
<div>
<input name="B[0]" />
</div>
<div>
<input name="C[0]" class="staticSize" />
</div>
</div>
</td>
</tr>
<tr class="typeB">
<td><input name="type[1]" /></td>
<td>
<div class="group1">
<input name="A[1]" />
</div>
<div class="group2">
<div>
<input name="B[1]" />
</div>
<div>
<input name="C[1]" class="staticSize" />
</div>
</div>
</td>
</tr>
<tr class="typeC">
<td><input name="type[2]" /></td>
<td>
<div class="group1">
<input name="A[2]" />
</div>
<div class="group2">
<div>
<input name="B[2]" />
</div>
<div>
<input name="C[2]" class="staticSize" />
</div>
</div>
</td>
</tr>
</table>
For the second option css, something like the following:
table {
width:100%;
}
.typeA .group1, .typeA .group2 {
display:none;
}
.typeB .group2 {
display:none;
}
.typeC .group1 {
display:none;
}
.typeC div.group2 {
display:table;
border-collapse:collapse;
}
.typeC div.group2>div {
width:100%;
display:table-cell;
}
input:not(.staticSize) {
width:100%;
box-sizing: border-box;
-webkit-box-sizing:border-box;
-moz-box-sizing: border-box;
}
Try
visibility: hidden;
That should keep it in the layout.
I have two div inside a third, I want the borders to line up but whilst they are next to eachother one is inexplicably slightly lower than the other ...
<div class="application">
<div class="contactMeForm">
Contact Us
Please provide as much information as possible about your query</br>
If you are requesting a quote this will help us to better estimate the costs involved.
<form name="contactform" method="post" action="send_form_email.php">
<table width="450px">
<tr>
<td valign="top"><label for="first_name">First Name *</label></td>
<td valign="top"><input type="text" name="first_name" maxlength="50" size="30"></td>
</tr>
<tr>
<td valign="top""><label for="last_name">Last Name *</label></td>
<td valign="top"><input type="text" name="last_name" maxlength="50" size="30"></td>
</tr>
<tr>
<td valign="top"><label for="email">Email Address *</label></td>
<td valign="top"><input type="text" name="email" maxlength="80" size="30"></td>
</tr>
<tr>
<td valign="top"><label for="telephone">Telephone Number</label></td>
<td valign="top"><input type="text" name="telephone" maxlength="30" size="30"></td>
</tr>
<tr>
<td valign="top"></td>
<td valign="top"><input type="radio" name="enquiry" value="Website Solution Quote">Website Solution Quote</td>
</tr>
<tr>
<td valign="top"><label for="comments">Enquiry Nature *</label></td>
<td valign="top"><input type="radio" name="enquiry" value="Mobile Solution Quote">Mobile Solution Quote</td>
</tr>
<tr>
<td valign="top"></td>
<td valign="top"><input type="radio" name="enquiry" value="Other">Other</td>
</tr>
<tr>
<td valign="top"> <label for="comments">Comments *</label></td>
<td valign="top"><textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea></td>
</tr>
<tr>
<td colspan="2" style="text-align:center"><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
</div>
<div class="contactMeHelp">
Extra details on how to fill in the form
</div>
</div>
And this is the CSS for the three divs
.application {
width: 97%;
margin: 20px 2% 0px 2%;
text-align: center;
display: block;
border: 2px #000000 solid;
}
.contactMeForm {
display: inline-block;
border: 5px #9E9FA1 solid;
border-right: 0px;
width: 49%;
color: #48494B;
text-align: left;
}
.contactMeHelp {
display: inline-block;
border: 5px #9E9FA1 solid;
border-left: 0px;
width: 49%;
color: #48494B;
text-align: right;
}
This is how it currently looks
http://masterzangetsu.eu/ContactMe/
Any help would be great
add
vertical-align: top;
To your two divs
Just add a "float: right;" to the .contactMeHelp element. That should do the trick.
Two problems:
1.) You do not have your float parameters set for each of your containing divs. Setting them to left and right depending on where they should be will fix it.
2.) Doing the above will still leave some weird block alignment in the .application div. This is because its height of the right-most div is not stretched to its parent div, you can do this by setting the height:100%.
Here is a fiddle showing you the results: http://jsfiddle.net/5T3NC/
My requirement is I want to align my radio button to left in table cell, but it is not happening with the below code:
My code
<div data-role="collapsible" data-theme="b" data-content-theme="b">
<h3>Action</h3>
<table class="tabledata" width="100%">
<tr>
<td class="td1">
<p>
<input id="Radio1" type="radio" value="Approve" /></p>
</td>
<td class="td2">Approve</td>
</tr>
<tr>
<td>
<input id="Radio2" type="radio" /></td>
<td class="td2">Reject</td>
</tr>
<tr>
<td>
<input id="Radio3" type="radio" />
</td>
<td class="td2">Send Back to Requestor</td>
</tr>
<tr>
<td>Amount Approved for Domestic sector : </td>
<td>
<input id="Text1" type="text" /></td>
</tr>
<tr>
<td>Remarks : </td>
<td>
<input id="Text2" type="text" /></td>
</tr>
<tr>
<td class="tabledata">
<input id="Button1" type="button" value="Submit" />
</td>
</tr>
</table>
</div>
My CSS classes:
.td1 {
vertical-align:middle;
text-align:right;
}
.td2 {
text-align: left;
}
Actually I want to keep my radio button and its corresponding text in a table row by combining 2 columns and centre aligned and also submit button shoud be centre aligned in a table row since I am using jquery mobile datarole I guess it is not happening.Please help me to get the look.
After adding the script in head also I am getting below output:
Remove ui-radio class from each radio button.
$('[type=radio]').each(function () {
$(this).closest('div').removeClass('ui-radio');
});
and add class td1 to each radio button.
<tr>
<td class="td1">
<input id="Radio1" type="radio" value="Approve" />
</td>
<td class="td2">Approve</td>
</tr>
<tr>
<td class="td1">
<input id="Radio2" type="radio" />
</td>
<td class="td2">Reject</td>
</tr>
<tr>
<td class="td1">
<input id="Radio3" type="radio" />
</td>
<td class="td2">Send Back to Requestor</td>
</tr>
Demo
Alternative method: No jQuery code is required nor custom CSS styles. Read more about it here.
Why don't you use styled radio buttons, as in the below demo.
Alternative
new CSS:
tr td:nth-child(1) {
vertical-align:middle;
text-align:right;
}
http://jsfiddle.net/yHbdn/1/