How to get the kendo NumericalTextBox to share the width of a table cell the same way the kendo DropDownList does? - css

I have a very simple form laid our in a table with one row and two cells. I have a kendo NumericalTextBox in one cell and a Text Input in the other. I have the table width set to 100% and no width on the cells.
The Problem:
The problem is that the NumericalTextBox takes up more that 50% width in it's cell, and squashes up the Text Input.
I have tested this with a kendo DropDownList and it works fine. It just takes 50%.
Why is the NumericalTextBox pushing out it's cell to more than 50% and how can I stop it doing this?
I realize I can put a style="width:50%" on the table cells, but this is an overhead on larger forms, as if you add a cell you have to go and update all your other cells width percentages etc...
Ideally I just want to be able to say the width of the table is 100% and the cells will equally share that, and each control in each cell will take up 100% of the cell width.
I put together a demo page that shows what is going on:
HTML:
<div id="testContainer">
<strong>Numerical TextBox and DropDownList</strong>
<table class="mistro-form">
<tr>
<td>
<label>Numerical TextBox:</label>
<input data-role="numerictextbox"
data-format="n0"
data-min="0"
data-decimals="0" />
</td>
<td>
<label>Drop Down List:</label>
<select name="Include Title"
data-role="dropdownlist"
data-value-primitive="true">
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</td>
</tr>
<table>
<div style="height:20px"></div>
<strong>Drop Down List and Text Input</strong>
<table class="mistro-form">
<tr>
<td>
<label>Drop Down List:</label>
<select name="Include Title"
data-role="dropdownlist"
data-value-primitive="true">
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</td>
<td>
<label>Include Title:</label>
<input type="text" class="form-control" />
</td>
</tr>
<table>
</div>
CSS:
table.mistro-form {
width:100%;
}
.mistro-form td {
padding: 5px;
vertical-align: top !important;
}
.mistro-form .k-dropdown, .mistro-form .k-combobox, .mistro-form .k-numerictextbox, .mistro-form .k-textbox, .mistro-form .k-numerictextbox {
width: 100% !important;
}
JavaScript:
$(document).ready(function() {
kendo.init($('#testContainer'));
});
Here is a fiddle of the above code: http://jsfiddle.net/codeowl/UQdGQ/6/
Thank you for your time,
Regards,
Scott

Ok I just worked this out. I just needed to set the table-layout css property to fixed;
eg;
table.mistro-form {
width:100%;
table-layout:fixed;
}
Hope this can save someone else some time ;-)

Related

Pinpoint table section within td tr table class

I am wanting to pinpoint the attribute size element which shows 3XL and make the width smaller. But I am struggling to pinpoint it in CSS!
Website screen shot
At the moment I have
table.variations td.value {
}
But this pinpoints the entire section of the column including the "clear" button. I have tried:
table.variations td.value .attribute_size {
}
But this also does not work.
Please help!
Thanks!
Beck
You have to pinpoint the select option within the td.value field. Then you can style it anyway you wish.
HTML
<table class="variations">
<tbody>
<tr>
<td class="value">
<select id="size" name="attribute_size">
<option>Choose an option</option>
<option value="2XL">2XL</option>
<option value="3XL">3XL</option>
</select>
CLEAR
</td>
</tr>
</tbody>
</table>
CSS
table.variations td.value {
font-size: 12px;
}
select#size {
color: white;
background-color: blue;
font-size: 42px;
}
JSFiddle.

Get label under a row use the full width of the table

I am using jqxValidator to validate a group of radio buttons. When the red message (which is a label) appears under the row, it inherits the width of the first column, breaking the design:
I tried many things, finally changing the display of the label fixes the table layout, but the message get splitted in 2 lines.
Is there a way to extend the width of the label to use the whole table width?
Example: https://codepen.io/lhernand/pen/OEZbXb
HTML:
<table style="border:0; border-collapse:collapse; " width="100%">
<tbody>
<tr class="rowRequired jqx-validator-error-element" id="optionsID0EYE">
<td style="border:0; width:50%; "><input id="ID0EYE" name="Patient-MainGP" value="true" type="radio"><span> Yes</span></td>
<td style="border:0; width:50%; "><input style="margin-left:20px; " id="ID0EYE" name="Patient-MainGP" value="false" type="radio"><span> No</span></td>
</tr><label class="jqx-validator-error-label" style="position: relative; left: 0px; width: 304.688px; top: 2px;">Please choose one option!</label>
</tbody>
</table>
Note: it should work in IE11
Working with this kind of fixed structure requires some mayor hacking,
since jquery validator inserts a label after a td on the table, the element behave like a td with no match on the same row.
Using the chrome dev tools option to copy the selector on the inspector, I can get the most specific selector posible for the html structure you have, so aplying a 200% size to this element, tricks the table to not missbehave
#tablePatientDetailsContainer > tbody > tr:nth-child(1) > td > table > tbody > tr > td:nth-child(2) > table > tbody > label{
width: 200% !important;
box-sizing: border-box;
}
Tested on Chrome, FF and Safari
My Working Code
https://codepen.io/Teobis/full/vrjZVR/
Hope this helps
You placed the id optionsID0EYE in the wrong place. jqxValidator will create a sibling for the element who has this id. You need to do something like so:
<tbody>
<tr class="rowRequired">
<div id="optionsID0EYE" style="display: flex; flex-wrap: wrap">
<div style="width: 50%">
<input id="ID0EYE" name="Patient-MainGP" value="true" type="radio"><span> Yes</span>
</div>
<div style="width: 50%">
<input style="margin-left:20px; " id="ID0EYE" name="Patient-MainGP" value="false" type="radio"><span> No</span>
</div>
</div>
</tr>
</tbody>
I moved the id optionsID0EYE to a new div I made.
Working example: https://codepen.io/anon/pen/YvLZeB?editors=1000

CSS element width to increase in steps

UPDATE: Please see image at the bottom of question.
So I have a set of inputs and checkboxes, and it is now required that the checkboxes and text inputs align; so I want to "step" the size of the inputs.
The checkboxes are fine and have a width of 160px, horizontally lining up as many as possible on the device screen width, but I need some way of getting the size of the text boxes to also fit the same sizing such as:
Overall container size only matters in that textbox container size is 76% of it
Textbox container: 608px
Textbox Size: 480px (160 x 3)
Checkboxes in row: 3
Textbox container: 532px
Textbox Size: 480px (160 x 3)
Checkboxes in row: 3
Textbox container: 380px
Textbox Size: 320px (160 x 2)
Checkboxes in row: 2
Textbox container: 304px
Textbox Size: 160px (160 x 1)
Checkboxes in row: 1
To be clear
If the container width is 380px then the textbox within would need to act like the inline-block checkboxes and only be 320px wide because the next step would be 320+160 = 480px which would be wider than the container.
So that the width of the textbox increases in "steps" equal to the width of the checkboxes (160px, but this would be hardcoded as it won't change once set).
Below is the code I have at the moment; and really I'm not sure where to being with this problem. Is there a certain phrase to search for, a certain wording to find out possible solutions.
Also; while the HTML is in a table format; I don't think that should be too important in this instance as it's only a single cell container for the <input> elements just like a div, etc.
.catitem {
width: 160px;
display: inline-block;
border:1px solid #090;
}
table {
width: 100%
max-width: 800px;
margin: 0 auto;
border-collapse: collapse;
}
table tr:nth-of-type(2n+1) {
background-color:#eaeaea;
}
table tbody tr td:first-of-type {
width: 24%;
min-width: 55px;
font-weight: bold;
box-sizing: border-box;
padding-left: 1rem;
}
table tr td:nth-of-type(2) input[type="text"] {
width:82%; /* THIS bit needs changing */
max-width:500px; /* */
}
<table>
<tbody>
<tr>
<td>Title:</td>
<td><input name="title" id="title" maxlength="12" placeholder="" type="text">
</td>
</tr>
<tr>
<td>First Name:</td>
<td><input name="fname" id="fname" maxlength="64" required="" type="text"></td>
</tr>
<tr>
<td>Surname:</td>
<td><input name="sname" id="sname" maxlength="64" required="" type="text"></td>
</tr>
<tr>
<td>Postcode:</td>
<td><input name="pcode" id="pcode" maxlength="10" required="" type="text"></td>
</tr>
<tr>
<td valign="top">Categories:</td>
<td>
<label class="catitem">
<input name="cats[]" value="chs" type="checkbox">
Coach
</label>
<label class="catitem">
<input name="cats[]" value="exm" type="checkbox">
Ex-members
</label>
<label class="catitem">
<input name="cats[]" value="fam" type="checkbox">
Family Membership
</label>
<label class="catitem">
<input name="cats[]" value="fos" type="checkbox">
Friends
</label>
<label class="catitem">
<input name="cats[]" value="ldy" type="checkbox">
Ladies
</label>
<label class="catitem">
<input name="cats[]" value="spr" type="checkbox">
Sponsor
</label>
</td>
</tr>
<tr>
<td> </td>
<td><input value="Add Member" type="submit"></td>
</tr>
</tbody>
</table>
Image Explanation:
So the 1 Step width will be on show when the container width is less than 2 steps (160 x 2); and the two step width will be on show when the container element is less than 3 steps wide (160 x 3), etc.
In the image above all boxes should be the width of the Postcode box, and when the container shrinks they would reduce down to the width of the title input box, but would not use any inbetween widths.
For a more dynamic result than Media Queries, you could try structuring this using CSS calc(): https://www.w3schools.com/cssref/func_calc.asp
So you'd have something like width: (100% - 160px); for each container and have a max-width for the container set either fixed (if you're ok with those) or use Bootstrap or similar to set a max-width based on columns in the page.

Align Checkboxes Horizontally (Table Layout)

I have checkboxes as shown in http://jsfiddle.net/Lijo/Fw3fz/. I need to align the checkboxes horizontally. How to align them using CSS?
Note: The following HTML code is generated from ASP.NET. I cannot change this HTML code.
<table id="Checkboxlist1">
<tr>
<td><input id="Checkboxlist1_0" type="checkbox" name="Checkboxlist1$0" value="red" /><label for="Checkboxlist1_0">Red</label></td>
</tr><tr>
<td><input id="Checkboxlist1_1" type="checkbox" name="Checkboxlist1$1" value="blue" /><label for="Checkboxlist1_1">Blue</label></td>
</tr><tr>
<td><input id="Checkboxlist1_2" type="checkbox" name="Checkboxlist1$2" value="green" /><label for="Checkboxlist1_2">Green</label></td>
</tr>
</table>
Create a CheckBoxList and set the horizontal layout property:
<asp:CheckBoxList ID="cbl" runat="server" RepeatDirection="Horizontal">
<asp:ListItem>Red</asp:ListItem>
<asp:ListItem >Blue</asp:ListItem>
<asp:ListItem>Green</asp:ListItem>
</asp:CheckBoxList>
More info:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.checkboxlist.repeatdirection.aspx
You have to change the trs display property: http://jsfiddle.net/Fw3fz/4/
​#Checkboxlist1 tr{
display:inline-block;
margin-right:20px;
}​
Or, use float: http://jsfiddle.net/Fw3fz/10/
#Checkboxlist1 tr{
float:left;
margin-right:20px;
}​
If you want some space between the checkboxes and the labels, add this snippet:
#Checkboxlist1 tr label{
margin-left:5px;
}
However, it's very uncommon to display table rows inline or to float them. If possible, change the HTML structure.
#Checkboxlist1 tr {
float: left; // or diplay: inline-block
margin-right: 15px;
}
#Checkboxlist1 td label {
margin-left: 5px;
}
DEMO
If you are using ASP.NET Framework 4, you can check following properties:
CheckBoxList.RepeatDirection Property:
Gets or sets a value that indicates whether the control displays vertically or horizontally.
CheckBoxList.RepeatLayout Property (to get rid of table layout)
Gets or sets a value that specifies whether the list will be rendered by using a table element, a ul element, an ol element, or a span element.
Either put them in different cells but in one line (tr), or lose the table and use css float.

How to overflow specific content inside an <td>?

I start with a td cell like this
<td>
<span>123</span>
<input style="display:none;">
</td>
I'm looking for a way to style this so that the orignal content is hidden, the input box is shown and overflowing instead of resizing the td, and keeping the td sized to just its original content.
State A, which I have now, looks like this
[123][45aaaaaaaaaaaaaaa6][7aaaaaa89]
I want state B to look like this
[*input text field*aaaaaaaaa6][7aaaaaa89]
<td>
<span>123</span>
<input style="display:none;">
</td>
Is the correction for your markup, but what exactly is the effect you want to achieve and what have you tried so far?
<td>
<span>123</span>
<div id="hidden">
<input type="text" />
</div>
</td>
in style define :
#hidden{
display:none;
position:absolute;
margin:.5em;
}
make script that shows the div on over (you will need to include jquery js ...)
<script type="text/javascript">
$(document).ready(function(){
$('table tr td').children().find('div').hover(function(){
$(this).show();
}
)
});
</script>
Figured it out. What I did not realize is that an element with position:absolute cannot be assumed to be defaulting to a 0,0 position, so I need to set the Left to 0 explicitly
<td>
<div style="position: relative;">
<span style="visibility:hidden;">123</span>
<input style="position: absolute; left:0; display:inline;">
</div>
</td>

Resources