HTML table alignment not working - css

I am trying to create a table with one column and 3 rows. I want to take the heading of the table ie. Role in the center and along with that the line below Role, I want to make it small lengthwise. My row values are not aligned properly well. PLease find my attached screenshot
My code
<div style="text-align: center" class="form-group" ng-if="isNew">
<table class="table table-inverse">
<thead>
<tr class="bg-primary">
<th width="14%">
<span>Role</span>
</th>
</tr>
</thead>
</table>
<table class="table table-inverse">
<tr>
<td style="border: none">
<input type="checkbox" name = "role" value = "Super" />Super</td>
</tr>
<tr>
<td style="border: none">
<input type="checkbox" name = "role" value = "Power" />Power</td>
</tr>
<tr>
<td style="border: none">
<input type="checkbox" name = "role" value = "Regular" />Regular</td>
</tr>
</table>
</div>

I applied some CSS and wrapped your checkbox elements in a DIV. Please see the snippet.
th {
width: 100vw;
}
th > span {
width: 14%;
display: inline-block;
border-bottom: 1px #ccc solid;
}
td {
width: 100vw;
text-align: center;
}
.checkbox {
width: 80px;
margin: auto;
text-align: left;
}
.checkbox input {
margin-right: 7px;
}
<div class="form-group" ng-if="isNew">
<table class="table table-inverse">
<thead>
<tr class="bg-primary">
<th>
<span>Role</span>
</th>
</tr>
</thead>
</table>
<table class="table table-inverse">
<tr>
<td>
<div class="checkbox">
<input type="checkbox" name = "role" value = "Super" />Super
</div>
</td>
</tr>
<tr>
<td>
<div class="checkbox">
<input type="checkbox" name = "role" value = "Power" />Power
</div>
</td>
</tr>
<tr>
<td>
<div class="checkbox">
<input type="checkbox" name = "role" value = "Regular" />Regular
</div>
</td>
</tr>
</table>
</div>

Related

Non-Standard Free Width Height HTML Table

I'm trying to get an HTML markup that represents the following table layout:
I tried this but it's not working:
<table border="1">
<tr>
<td style="height: 800px">
1
</td>
<td style="width: 300px; height: 400px">
2
</td>
</tr>
<tr>
<td style="height: 200px">
<p>3</p>
</td>
<td style="height: 600px">
4
</td>
</tr>
</table>
This looks pretty close to the image you provided. It's a little tricky because it actually requires 3 rows, but once you get your head wrapped around rowspan, then it makes sense.
<table border="1">
<tr style="height: 200px;">
<td style="width: 400px;" rowspan="2">
1
</td>
<td style="width: 200px;">
2
</td>
</tr>
<tr style="height: 200px;">
<td rowspan="2">
4
</td>
</tr>
<tr style="height: 50px;">
<td>
<p>3</p>
</td>
</tr>
</table>
You just need to add another row and add rowspans:
<table border="1">
<tr>
<td style="width: 300px; height: 400px" rowspan="2">
1
</td>
<td style="width: 300px; height: 200px">
2
</td>
</tr>
<tr>
<td style="height: 200px" rowspan="2">
4
</td>
</tr>
<tr>
<td style="height: 100px">
3
</td>
</tr>
</table>
See jsfiddle: http://jsfiddle.net/mt009cha/
EDIT
Do you have to use tables? This seems more like a layout and divs might be more appropriate.
Html:
<div class="container">
<div class="left">
<div style="height: 498px">1</div>
<div style="height: 98px">3</div>
</div>
<div class="right">
<div style="height: 298px">2</div>
<div style="height: 298px">4</div>
</div>
</div>
CSS:
div {
border: 1px solid black;
}
.container {
width: 600px;
height: 600px;
}
.left {
width: 398px;
height: 100%;
float: left;
}
.right {
width: 198px;
height: 100%;
float: right;
}
See jsfiddle: http://jsfiddle.net/zynt5j7e/
FIDDL
If you must use tables:
<table class="tbl">
<tr>
<td>
<table>
<tr>
<td style="height: 800px">
<p>top left</p>
</td>
</tr>
<tr>
<td style="height: 200px">
<p>bottom left</p>
</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td style="height: 400px">
<p>top left</p>
</td>
</tr>
<tr>
<td style="height: 600px">
<p>bottom left</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
Some CSS:
.tbl, .tbl table { border-collapse: collapse; width:100%; }
.tbl td, .tbl table td{ border:1px solid black; padding:0; margin: 0; }

Conditionally change color of angularjs element?

Im still pretty new to AngularJS. Im trying to change the color of the table element so that its yellow if the user voted on this choice.
<div ng-show="poll.userVoted">
<table class="result-table">
<tr ng-repeat="choice in poll.choices">
<td>{{choice.text}}</td>
<td>
<table ng-if="choice.text == poll.userChoice.text" style="background-color: yellow; width: {{choice.votes.length/poll.totalVotes*100}}%; text-align: right">
<tr>
<td>{{choice.votes.length}}</td>
</tr>
</table>
<table ng-if="choice.text != poll.userChoice.text" style="background-color: lightblue; width: {{choice.votes.length/poll.totalVotes*100}}%; text-align: right">
<tr>
<td>{{choice.votes.length}}</td>
</tr>
</table>
</td>
</tr>
</table>
This is done by using ng-class.
Use ng-class on your td like this:
<td ng-class="{yellowstyle: choice.text==poll.userChoice.text}">...</td>
that will put the css class yellowstyle on the item when your condition is true.
And in your example:
<table class="result-table">
<tr ng-repeat="choice in poll.choices">
<td>{{choice.text}}</td>
<td>
<table style="width: {{choice.votes.length/poll.totalVotes*100}}%; text-align: right">
<tr>
<td ng-class="{yellowstyle: choice.text==poll.userChoice.text, lightbluestyle: choice.text!=poll.userChoice.text}">{{choice.votes.length}}</td>
</tr>
</table>
</td>
</tr>
</table>
with a style.css file that has:
.yellowstyle {background-color: yellow;}
.lightbluestyle {background-color: lightblue;}

Table alignment according to div size

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.

HTML + CSS, i cant seem to get two horizontally alligned divs to line up

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/

Displaying Description in Knockout on clicking Title

I have a asp.net mvc2 page where I display data with titles and descriptions using knockout. I want to hide descriptions and show description based on clicked title. any help would be appreciated. Also I would like to apply h1 tag to title.
<div id="dataDiv">
<table style="text-align: left" border="0">
<tbody>
<!-- ko foreach: list -->
<tr>
<td colspan="2" data-bind="text: title">
</td>
</tr>
<tr>
<td colspan="2" data-bind="text: description">
</td>
</tr>
<tr>
<td colspan="2">
<hr style="border-top: 1px dotted #f00; color: #fff; background-color: #fff; height: 1px;
width: 100%;" />
</td>
</tr>
<!-- /ko -->
</tbody>
</table>
Is this is what You are looking for?
Working demo http://jsfiddle.net/Rgxy9/
HTML:
<table style="text-align: left" border="0">
<tbody data-bind="foreach: list">
<tr>
<td colspan="2" data-bind="click: $root.select">
<h1 data-bind="text: title" />
</td>
</tr>
<tr data-bind="visible: $root.selected() == $data">
<td colspan="2" data-bind="text: description">
</td>
</tr>
<tr>
<td colspan="2">
<hr style="border-top: 1px dotted #f00; color: #fff; background-color: #fff; height: 1px;
width: 100%;" />
</td>
</tr>
</tbody>
</table>
<script type="text/javascript">
var item = function(title, desc) {
this.title = ko.observable(title);
this.description = ko.observable(desc);
};
var vm = function() {
var self = this;
this.list = ko.observableArray([new item('some', 'desc'),
new item('som2', 'desc2')]);
this.selected = ko.observable();
this.select = function(item) {
self.selected(item);
};
};
ko.applyBindings(new vm());
</script>

Resources