CSS Float fails for HTML5 Input Elements - css

I'm running into an issue when using HTML5 form input types (number, date, email, etc) with the CSS float property. I'm trying to float these to the right, but they are not honoring that setting.
Here's a snippit where I put the CSS inline during testing:
<div class="center" style="width: 100%">
...
<div style="width: 90%" class="textfont">
...
<table style="width:100%;">
<thead>
<tr class="tableHeading">
<td style="width: 50%; text-align: center;">
Unit Types
</td>
<td style="text-align: center;">
Number of Units
</td>
</tr>
</thead>
<tbody>
<tr>
<td style="border-right: 1px;">
Single-Family Detached
</td>
<td>
<input type="number" name="txtDetached" style="width:25%; float:right" />
</td>
</tr>
<tr>
<td style="height: 32px">
Townhouse, Row, or Cluster
</td>
<td style="height: 32px">
<input type="number" name="txtCuster" style="width:25%; float:right" />
</td>
</tr>
<tr>
<td>
Garden
</td>
<td>
<input type="number" name="txtGarden" style="width:25%; float:right" />
</td>
</tr>
<tr>
<td style="height: 43px">
Mid-rise (3-5)
</td>
<td style="height: 43px">
<input type="number" name="txtMidrise" style="width:25%; float:right" />
</td>
</tr>
<tr>
<td>
High-rise (6+)
</td>
<td>
<input type="number" name="txtHighRide" style="width:25%; float: right" />
</td>
</tr>
<tr>
<td>
Other
</td>
<td>
<input type="text" name="txtOther" style="width: 80%; float: right;" />
</td>
</tr>
</tbody>
</table>
...
</div>
...
</div>
Yes, I know tables are frowned upon...
Here's the overall CSS:
.Header
{
font-size: 30px;
font-family: Cambria;
color: White;
background: #254117;
text-align: center;
font-weight: bold;
width: 90%;
}
.subHeading
{
font-family: Arial;
font-size: 11px;
text-align: left;
}
.container
{
display: table;
width: 90%;
border-collapse: collapse;
}
.heading
{
font-weight: bold;
display: table-row;
background-color: #C91622;
text-align: center;
line-height: 25px;
font-size: 14px;
font-family: georgia;
color: #fff;
}
.table-row
{
display: table-row;
text-align: center;
}
.col
{
display: table-cell;
border: 1px solid #CCC;
}
.tableHeading
{
font-family: Arial;
background: #99C68E;
font-size: 18px;
text-align: left;
}
.textfont
{
font-size: 15px;
font-family: Arial;
text-align: left;
}
input[type=text]
{
width: 100%;
height: 22px;
}
textarea
{
width: 98%;
}
table
{
border-collapse: collapse;
border: 1px solid black;
border-spacing: 10px;
}
tr
{
border-collapse: collapse;
border: 1px solid black;
}
td, th
{
padding: 5px;
}
.center
{
margin-left: auto;
margin-right: auto;
}
Here's what this displays:
As you can see the input element with type="text" works without an issue, however when type="number" it remains at the default, left justified.
This behavior exists in IE 10, FireFox, and Chrome.
I discovered the workaround is to wrap the HTML5 input types in a div and then set the CSS to float the div right, and then this works without issue. I had issues finding information for this on the net, but is this a known issue? Is the workaround actually the proper way of handling this?
EDIT: Added full CSS (minus stuff I moved inline for testing). Added entire table and the div's they are wrapped in. If I copy all of this to jsFiddle it works properly, so I'm obviously doing something wrong here...

OK, the problem related to floating elements inside <td>, use text-align can fix it.
<td style="text-align:right;">
...
</td>
More can be read here DIV in <td> float right

Related

How do I make table row have the same height and not depend on the size of the images?

As you can see in the code snippet, the height of the table rows is slightly different depending on the height of the images.
I have the image tag set to height: auto; and if I change this to say 300px, the images they all get the same size, but it's not what I want because I still want to keep the aspect ratio.
table {
display: table;
table-layout: fixed;
width: 100%;
margin-bottom: 4rem;
border: 1px solid #c4c4c4;
border-collapse: collapse;
font-size: 1rem;
}
thead {
background: #fbfbfb;
border: 1px solid #c4c4c4;
}
th,
td {
height: 5rem;
padding: 1rem;
}
th {
text-align: start;
background: #fbfbfb;
}
td {
background: #fff;
}
tr {
border: 1px solid #c4c4c4;
}
.read-more {
color: #fff;
background: #005c68;
border-radius: 5px;
cursor: pointer;
font-size: 1rem;
font-weight: 500;
padding: 1rem;
}
.price {
font-weight: 700;
}
img {
width: 100%;
max-width: 7em;
height: auto;
}
#media screen and (max-width: 1225px) and (min-width: 1045px) {
.priority-5 {
display: none;
}
}
#media screen and (max-width: 1045px) and (min-width: 835px) {
.priority-5 {
display: none;
}
.priority-4 {
display: none;
}
}
#media screen and (max-width: 835px) and (min-width: 300px) {
.priority-5 {
display: none;
}
.priority-4 {
display: none;
}
.priority-3 {
display: none;
}
}
#media screen and (max-width: 300px) {
.priority-5 {
display: none;
}
.priority-4 {
display: none;
}
.priority-3 {
display: none;
}
.priority-2 {
display: none;
}
}
<table>
<thead>
<tr>
<th className="priority-1">Operatör</th>
<th className="priority-2">Surfmängd</th>
<th className="priority-3">Bindningstid</th>
<th className="priority-4">Samtal</th>
<th className="priority-5">Sms</th>
<th className="priority-6">Pris</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td className="priority-1">
<img src=https://www.telia.se/.resources/discover/resources/imgs/logo236x200.png alt=logo />
</td>
<td className="priority-2">124 GB</td>
<td className="priority-3">24 mån</td>
<td className="priority-4">
Fria
</td>
<td className="priority-5">
Fria
</td>
<td className="priority-6 price">99 kr</td>
<td>
<button className="read-more" type="button">
Läs mer
</button>
</td>
</tr>
<tr>
<td className="priority-1">
<img src=https://1.bp.blogspot.com/-f39w3NL2fYM/UJrk7keg5ZI/AAAAAAAAPTM/dGo3uETNoD4/s1600/Comviq+logo+2012.png alt=logo />
</td>
<td className="priority-2">124 GB</td>
<td className="priority-3">24 mån</td>
<td className="priority-4">
Fria
</td>
<td className="priority-5">
Fria
</td>
<td className="priority-6 price">99 kr</td>
<td>
<button className="read-more" type="button">
Läs mer
</button>
</td>
</tr>
<tr>
<td className="priority-1">
<img src=https://www.telia.se/.resources/discover/resources/imgs/logo236x200.png alt=logo />
</td>
<td className="priority-2">124 GB</td>
<td className="priority-3">24 mån</td>
<td className="priority-4">
Fria
</td>
<td className="priority-5">
Fria
</td>
<td className="priority-6 price">99 kr</td>
<td>
<button className="read-more" type="button">
Läs mer
</button>
</td>
</tr>
<tr>
<td className="priority-1">
<img src=https://1.bp.blogspot.com/-f39w3NL2fYM/UJrk7keg5ZI/AAAAAAAAPTM/dGo3uETNoD4/s1600/Comviq+logo+2012.png alt=logo />
</td>
<td className="priority-2">124 GB</td>
<td className="priority-3">24 mån</td>
<td className="priority-4">
Fria
</td>
<td className="priority-5">
Fria
</td>
<td className="priority-6 price">99 kr</td>
<td>
<button className="read-more" type="button">
Läs mer
</button>
</td>
</tr>
</tbody>
</table>
Let me suggest a few options:
You could specify the aspect ratio manually, if you know what you need, using css aspect-ratio property. Then specify whatever height you need so that it fits in the table row.
You could mention the height and width, and let the image content be adjusted accordingly, using the object-fit. This could somewhat obscure the contents, so you should take it with a pinch of salt.
You could mention the max-height property for the image, along with a width=auto, so that it scales down to the required size.
There are many ways to do this, you can specify the height of the parent element.
.container {
border: 1px solid red; /* Just to visualize the parent element*/
height: 150px; /* The container height it's lower than the child */
margin: 5rem 0; /* Just some space between the containers */
}
<!-- With overflow-y visible (by default) -->
<div class="container"> <!-- style="overflow-y:visible" -->
<img src="http://via.placeholder.com/200x200"/>
</div>
<!-- With overflow-y hidden -->
<div class="container" style="overflow-y:hidden">
<img src="http://via.placeholder.com/200x200"/>
</div>
Once it's "overflowed" you ajust the image as you want.

Attach the css arrow to the top of a css border

This would be really easy using negative margins, but I can't use them inside a <table>. Been at this for hours last night and this morning. Already googled different types of navs and there's nothing like this.
How do I make the CSS arrow stick to the top and bottom of the vertical line? https://codepen.io/TylerL-uxai/pen/ZqYNjw
td {
padding-top: 10px;
padding-bottom: 10px;
}
.active {
font-weight: bold;
}
table {
border-collapse: collapse;
}
.right{
text-align: right;
border-right: 1px solid black;
}
.v {
text-align: right;
}
i {
border: solid black;
border-width: 0 3px 3px 0;
display: inline-block;
padding: 3px;
}
.down {
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
}
.up {
transform: rotate(-135deg);
-webkit-transform: rotate(-135deg);
}
.dot {
height: 10px;
width: 10px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
}
<div class="menu">
<table>
<tr>
<td class="v">
<i class="arrow up"></i>
</td>
<td>
Abstract
</td>
</tr>
<tr>
<td class="right">
Why
</td>
</tr>
<tr>
<td class="right">
<div class="active">Home</div>
</td>
<td><span class="dot"></span> <small> You are here.</small></td>
</tr>
<tr>
<td class="right">
Examples
</td>
</tr>
<tr>
<td class="right">
Process
</td>
</tr>
<tr>
<td class="right">
Tools
</td>
</tr>
<tr>
<td class="v"><i class="down"></i></td>
<td style="padding-left: 10px;">
Concrete
</td>
</tr>
</table>
</div>
Position relative and then use top & right negatives
.v {
position: relative;
right:-6px;
top: -15px;
text-align: right;
}

Why isn't my 'Text' in my css isn't inline with my input i cant figure this out

I am using this codes below to Add data into my web :
//Codes//
.AddData input {
font-size: 15px;
padding: 2.5px;
margin-bottom: 15px;
}
.AddData [type='text'] {
font-weight: bold;
font-size: 18px:
margin-bottom: 6px;
}
.AddData button {
transform: translate(120%,-50%);
outline: 1px solid black;
width: 80px;
height: 40px;
font-size: 16px;
background: #ff267e;
display: block;
cursor: pointer;
color: #fff;
border: none;
}
.AddData tr {
margin-bottom: auto;
}
Below is my html codes i used for my website.
//Html//
<link rel="stylesheet" type="text/css" href="web.css">
<body>
<div class ="AddData">
<form action="add.php" method="POST" name="form1">
<table width="25%" border="0">
<tr>
<td>User ID: </td>
<td><input type="text" name="User_id" required autocomplete="off"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="Password" required autocomplete="off"></td>
</tr>
<tr>
<td>Confirm Password:</td>
<td><input type="password" name="CPass" required autocomplete="off" ></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="Add"></td>
</tr>
</table>
This is what it shows on my website i just need the 'User_id' to be inline as the input box.
https://i.stack.imgur.com/yBPEW.png
You have to use padding instead of margin to add space inside a td. I left some commented code for you to check what styles I removed from your code.
There will be some issues you'll have to fix like the difference in font size.
.AddData input {
font-size: 15px;
padding: 2.5px;
/* margin-bottom: 15px; */
}
.AddData [type='text'] {
font-weight: bold;
font-size: 18px; /*; was missing*/
/* margin-bottom: 6px; */
}
.AddData button {
transform: translate(120%,-50%);
outline: 1px solid black;
width: 80px;
height: 40px;
font-size: 16px;
background: #ff267e;
display: block;
cursor: pointer;
color: #fff;
border: none;
}
/* .AddData tr {
margin-bottom: 15px;
} */
.AddData td {
padding-bottom: 15px;
}
<body>
<div class ="AddData">
<form action="add.php" method="POST" name="form1">
<table width="25%" border="0">
<tr>
<td>User ID: </td>
<td><input type="text" name="User_id" required autocomplete="off"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="Password" required autocomplete="off"></td>
</tr>
<tr>
<td>Confirm Password:</td>
<td><input type="password" name="CPass" required autocomplete="off" ></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="Add"></td>
</tr>
</table>
</form>
</div>
</body>

Is there any theme or style for Bootstrap Table?

I am using Bootstrap now for creating the front-end of the website that I am working on, and Bootstrap is very nice and powerful. However, the default style and theme for the HTML table is not good that much. So is there any style or theme for it?
I was searching about it and found Bootswatch website. They have very nice free themes for the Bootstrap, However, those themes don't change the style of the table.
Twitter bootstrap table can be styled and well designed. However to make your table look beautiful and style , you need create your own css
You can follow this example
On your HTML
<table class="responsive-table responsive-table-input-matrix">
<tr>
<th>Role</th>
<th>Add to Page</th>
<th>Configure</th>
<th>View</th>
<th>Change Permissions</th>
</tr>
<tr>
<td data-th="Role">Guest</td>
<td data-th="Add to Page"><input type="checkbox" /></td>
<td data-th="Configure"><input type="checkbox" /></td>
<td data-th="View"><input type="checkbox" /></td>
<td data-th="Change Permissions"><input type="checkbox" /></td>
</tr>
<tr>
<td data-th="Role">Noob</td>
<td data-th="Add to Page"><input type="checkbox" /></td>
<td data-th="Configure"><input type="checkbox" /></td>
<td data-th="View"><input type="checkbox" /></td>
<td data-th="Change Permissions"><input type="checkbox" /></td>
</tr>
<tr>
<td data-th="Role">Moderator</td>
<td data-th="Add to Page"><input type="checkbox" /></td>
<td data-th="Configure"><input type="checkbox" /></td>
<td data-th="View"><input type="checkbox" /></td>
<td data-th="Change Permissions"><input type="checkbox" /></td>
</tr>
<tr>
<td data-th="Role">Administrator</td>
<td data-th="Add to Page"><input type="checkbox" /></td>
<td data-th="Configure"><input type="checkbox" /></td>
<td data-th="View"><input type="checkbox" /></td>
<td data-th="Change Permissions"><input type="checkbox" /></td>
</tr>
<tr>
<td data-th="Role">Owner</td>
<td data-th="Add to Page"><input type="checkbox" /></td>
<td data-th="Configure"><input type="checkbox" /></td>
<td data-th="View"><input type="checkbox" /></td>
<td data-th="Change Permissions"><input type="checkbox" /></td>
</tr>
</table>
Create own CSS
#import "compass/css3";
// More practical CSS...
// using mobile first method (IE8,7 requires respond.js polyfill https://github.com/scottjehl/Respond)
$breakpoint-alpha: 480px; // adjust to your needs
.responsive-table-input-matrix {
margin: 1em 0;
// min-width: 300px; // adjust to your needs
width: 100%;
#media (min-width: $breakpoint-alpha) {
.responsive-table-input-matrix {
width: auto;
}
}
tr {
border-top: 1px solid #ddd;
border-bottom: 1px solid #ddd;
td {
text-align: left;
#media (min-width: $breakpoint-alpha) {
text-align: center;
}
}
& td:first-of-type {
text-align: left;
}
}
th {
display: none; // for accessibility, use a visually hidden method here instead! Thanks, reddit!
}
td {
display: block;
&:first-child {
padding-top: .5em;
}
&:last-child {
padding-bottom: .5em;
}
&:before {
content: attr(data-th)": "; // who knew you could do this? The internet, that's who.
font-weight: bold;
// optional stuff to make it look nicer
width: 9em; // magic number :( adjust according to your own content
display: inline-block;
// end options
#media (min-width: $breakpoint-alpha) {
display: none;
}
}
}
& th:first-of-type {
text-align: left;
}
th, td {
text-align: center;
#media (min-width: $breakpoint-alpha) {
display: table-cell;
padding: .25em .5em;
&:first-child {
padding-left: 0;
}
&:last-child {
padding-right: 0;
}
}
}
}
// presentational styling
#import 'http://fonts.googleapis.com/css?family=Montserrat:300,400,700';
body {
padding: 0 2em;
font-family: Montserrat, sans-serif;
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
color: #444;
background: #eee;
}
h1 {
font-weight: normal;
letter-spacing: -1px;
color: #34495E;
}
.responsive-table {
background: #34495E;
color: #fff;
border-radius: .4em;
overflow: hidden;
tr {
border-color: lighten(#34495E, 10%);
}
th, td {
margin: .5em 1em;
#media (min-width: $breakpoint-alpha) {
padding: 1em !important;
}
}
th, td:before {
color: #dd5;
}
}
Hope you can learn something from this coding. :)
Bootstrap provides basic styling for tables with the .table class. There are other classes that can be added for additional, modest styling.
W3Schools article on Bootstrap tables

Position a div absolutely inside a tr

I have a table which is used for showing excel-like data. I need to absolutely position two icons in the top center of each row--I want to show edit/delete icons when the use hovers the mouse over any row.
When I tried adding a relative position to the TR and an absolute positioning my inner floating div, the css disregarding the relative positioning of the parent td and simply floated to the top of the screen:
http://jsfiddle.net/85aTs/2/
HTML
<table>
<tr>
<td>
fooasfdasdfasf
</td>
<td>
barasdfasfas
</td>
</tr>
<tr>
<td>
fooasfdasdfasf
</td>
<td>
barasdfasfas
</td>
<div class="absolute">
I should be in a row
</div>
</tr>
</table>
CSS:
table, td{
border: 1px solid #000;
}
tr {
position:relative;
}
.absolute {
position: absolute;
top: 0;
right: 0;
border: 1px solid #000;
background-color: yellow;
}
I am aware that this is not valid html as it is currently setup, but how can I achieve what I want without switching over to divs with table display properties?
Here's what I would do:
See working jsFiddle demo
HTML
<table>
<tr>
<td>
<div class="icons">
<img class="checkmark" />
<img class="crossmark" />
</div>
<table>
<tr>
<td>fooasfdasdfasf</td>
<td>barasdfasfas</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<div class="icons">
<img class="checkmark" />
<img class="crossmark" />
</div>
<table>
<tr>
<td>fooasfdasdfasf</td>
<td>barasdfasfas</td>
</tr>
</table>
</td>
</tr>
</table>
CSS
table, td
{
border: 1px solid #000;
}
.icons
{
height: 16px;
text-align: center;
background: #bbb;
}
.checkmark
{
display: inline;
height: 16px;
width: 16px;
border: none;
background: url('http://www.actuary.com/directory/template/default/images/icon_checkmark.gif');
}
.crossmark
{
display: inline;
height: 16px;
width: 16px;
border: none;
background: url('http://researchautism.net/img/rating_icons/crossmark_sm.png');
}
RESULTS

Resources