Here is my code:
<form name="htmlform" method="post" action="html_form_send.php">
<div id="table">
<table width="400px" style="margin-top: 50px; margin-left: 20px; color: #FFF">
</tr>
<tr>
<td valign="top">
<label for="name">Name *</label>
</td>
<td valign="top">
<input type="text" name="name" maxlength="50" size="30" style="margin-bottom: 10px">
</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" style="margin-bottom: 10px">
</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" style="margin-bottom: 10px">
</td>
</tr>
<tr>
<td valign="top">
<label for="enquiry">Enquiry *</label>
</td>
<td valign="top">
<textarea name="enquiry" maxlength="1000" cols="32" rows="6"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Submit">
</td>
</tr>
</table>
</div>
</form>
And i want to make the table and all its features smaller when viewed below 480px wide for small devices phones/etc. I don't know what to reference when using a media query:
#media only screen and (max-width: 480px) {
#table {
width: 100px;
}
This css above doesn't work, it resizes the div but the content is still original size even if i put the form in the div it still doesn't work, perhaps the div is not required anyway... any help would receive major kudos!!
Thanks!
You need to do a few things to make this work.
First, that outer div isn't required so we can get rid of it.
Second, you need to change the width of your table in the media query. I used a percentage value (for responsiveness) but you can set it to a pixel value if you desire (under 480px of course)
Third, you need to set a width in your media query for the inputs/textarea. Without this, they will take up the widths specified in the 'size' attribute and will cause the horizontal scroll bar to appear.
Here's the media query I used:
#media only screen and (max-width: 480px) {
table {
width:95%;
}
input[type=text], textarea {
width:75%;
}
}
Demo: http://jsfiddle.net/hABGX/2/
it doesn't work because your table has a style to, and that style is syaing the table has a width of 400px. Try to put this:
<table style="margin-top: 50px; margin-left: 20px; color: #FFF; width:100%">
instead of this:
<table width="400px" style="margin-top: 50px; margin-left: 20px; color: #FFF">
it wont work very well because you still have enought content to show in 100px...so i recomend you change the size to about 250px. If you really want it to have 100px i recomend you make the table in a diferent way.
Related
I know that it's been an ongoing discussion, and that float:right is supposed to be the answer to avoiding the use of tables for formatting, but I can't seem to figure out how to do the following without tables. The labels will change based on language, so fixed widths can't be used.
I can't seem to get float:right to work when the inputs are different widths. Here's the HTML I used with a table...
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head />
<body>
<style>
.left {
width:1%;
white-space:nowrap;
text-align:right;
padding-right: 5px;
}
</style>
<form>
<table
width="400">
<tr>
<td class="left">Name:</td>
<td>
<input
type="text"
style="display:table-cell; width:100%"/>
</td>
</tr>
<tr>
<td class="left">Telephone Number:</td>
<td>
<input
type="text" style="width: 30px;"
/>-<input
type="text" style="width: 30px;"
/>-<input
type="text" style="width: 40px;"/>
</td>
</tr>
<tr>
<td colspan="2">
<input
type="checkbox"
/>Okay to leave the package without a signature.
</td>
</tr>
<tr>
<td valign="top" class="left">Delivery Notes:</td>
<td>
<textarea
rows="5"
style="display:table-cell;
width:100%"
></textarea>
</td>
</tr>
</table>
</form>
</body>
</html>
Thanks.
I am currently working on a website for my business, from scratch using html5, css and javascript.
I have several table's I want to be styled individually e.g diff colours sizes etc.
I have tried to give them each their own class and I have done the table.table1 for my css - for all 3 but only one of the css is working, for all 3 tables it seems... where am I going wrong?
<form name="htmlform" method="post" target="taxshop#hotmail" action="html_form_send.php">
<table class="contact" 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">
<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>
The CSS I have for this table is as follows:
table.contact tr, td {
border: 1px solid #ffffff;
border-collapse: collapse;
color:#000000;
background-color: #ffffff;
font-size: 1em;
margin: 0;
margin-bottom: 22px;
padding: 4px;
font-style: normal;
text-align: left;
border-bottom-style: solid;
border-bottom-width: 0.25em;
border-bottom-color: #ffffff;
border-radius: 0px;
}
table.contact, td {
padding: 5px;
text-align: left;
}
table.contact label{
display:inline-block;
width:100px;
margin-right:10px;
text-align:right;
}
You had a mistake in a first row,
https://jsfiddle.net/yvvcspha/1/
table.contact tr, td {
}
This selector means that youre applying style to ;tr inside table.concat, and to all other td on the page, since comma separates selectors.
If you want to apply style only to td inside table.concat, you should use. table.contact td.
table.contact tr, table.contact td {
}
This will be the right way to do it.
Also, consider learinig more about CSS and HTML5 basics since it seems like you're lacking some basic knowlege about their synthax and way it works.
This series of articles (the beginer part) might end up being extrimely helpfull to you.
I want to put inputs in one row.
<table border='1' cellpadding="25" style='border-collapse: collapse;border-color: silver;'>
<tr style='font-weight: bold;'>
<td width='350' align='center'>
<h2>Register:</h2><br>
Login: <input type="text" name="login" maxlength="20" size="25" /><br>
Password: <input type="password" name="password" size="25" maxlength="32" /><br>
Repeat password: <input type="password" name="password2" size="25" maxlength="32" /><br><br>
</td></tr></table>
I think you are trying to get all this aligned in the center.For that we have to use the the "tr" tag defines a row in an HTML table and "th" tag which defines a header cell in an HTML table.Try the following code :
<html>
<body>
<h2 align="center">Register</h2>
<table align="center">
<tr>
<td>Login</td>
<td><input type="text" name="login" align="middle"/></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="pass" align="middle"/></td>
</tr>
<tr>
<td>Repeat Password</td>
<td><input type="password" name="rpass" align="middle"/></td>
</tr>
</table>
Also we use the align property for table and the new rows we create to get what you desire.
I think you have 3 options:
using CSS & position:relative and play with left' of eachinputs`, that's not valid at all.
Add some more HTML, I mean put each inputs on separate td. this is the best choice I think, and even better that you put the label / text' of each input on another td as well.
Using div (for example) instead of td for having more control and using CSS as well.
I strongly recommend you that using option #2, hope this help.
Do it like that:
<table border='1' cellpadding="25" style='border-collapse: collapse;border-color: silver;'>
<tr style='font-weight: bold;'>
<td style="width: 300px; text-align: right;">
Login:
</td>
<td style="width: 300px; text-align: left;">
<input type="text" name="login" maxlength="20" size="25" />
</td>
</tr>
<tr style='font-weight: bold;'>
<td style="width: 300px; text-align: right;">
Password:
</td>
<td style="width: 300px; text-align: left;">
<input type="password" name="password" size="25" maxlength="32" />
</td>
</tr>
</table>
I am using Bootstrap 2.3 and I have like 7 text input fields inside a table that uses bootstrap table style. I would like to resize (or shrink the width of) these text inputs instead of taking the whole width of the table cell but I could not do that
I tried to use the class of span1 but it did not shrink them well. So is there any way of minimizing the size or width of all text input fields within the table cell?
Here's my code:
<table class="table table-bordered">
<thead>
<tr>
<th>Exercise</th>
<th>Exercise Code</th>
<th>Initiated by</th>
<th>Initiated on</th>
<th>Done by</th>
<th>Q1</th>
<th>Q2</th>
<th>Q3</th>
<th>Q4</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="text" class="input-mini span1" />
</td>
<td>
<input type="text" class="input-mini span1" />
</td>
<td>
<input type="text" class="input-mini span1" />
</td>
<td>
<input type="text" class="input-mini span1" />
</td>
<td>
<input type="text" class="input-mini span1" />
</td>
<td>
<input type="text" class="input-mini span1" />
</td>
<td>
<input type="text" class="input-mini span1" />
</td>
<td>
<input type="text" class="input-mini span1" />
</td>
<td>
<input type="text" class="input-mini span1" />
</td>
<td>
For Action
</td>
</tr>
</tbody>
</table>
Since you have access to JQuery, try doing this in your <header> area of html, but be sure it is after all Javascript includes.
<script type="text/javascript">
$(".span1").css("width", "10px");
</script>
If the above works, I think you need to update your original post to show all your js/css includes. This seems like you just have something in the wrong order.
--Original Answer Below--
Could you not simply add a CSS entry in your header like:
.table > input[type="text"] {
width: 10px;
}
The only negative is that this will change all table type=text elements that use the .table class.
So instead, have the table itself have the span1 tag and change the above code to reflect it?
.span1 > input[type="text"] {
width: 10px;
}
*Note: Make sure this is AFTER you reference the bootstrap css.
I'd like my two inputboxes to take up the whole width of my table cell, with no/minimal space between the two inputboxes.
Fiddle: http://jsfiddle.net/Gd47b/2/
#one {
width:20%;
float: left;
}
#two {
width:80%;
display: block;
overflow: hidden;
}
What you're is missing is that the border with 1px will take up some space so you either have to remove the border from the table or adjust the width of the text fields to accommodate.
One option is to just split the cell the inputs are in into two cells like:
<table border="1" bordercolor="e2e2e2" width="400">
<tr>
<td><label>1</label> </td>
<td colspan="2"><input type="text" id="Name" value="Name" /> </td>
</tr>
<tr>
<td>2</td>
<td style="width:20%"><input type="text" id="one" value="one" style="width: 100%" /> </td>
<td style="width:80%"><input type="text" id="two" value="two" style="width: 100%" /></td>
</tr>
</table>
jsFiddle example