How to overlap the table(td) text without using position property - javascript

Here, I'm having issues with the table in display inline-block property. In my scenario, I need to add 2 spans and text inside the td element. When I use it the text wrapped into the next line. Here I need the text overlap into the span, i.e., the spans should not be disturbing the td's text content. I don't want to use position property. Here is my simple demo.
table {
border-collapse: collapse;
width: 200px;
}
table tr td {
border: 1px solid;
}
span.leftspan {
display: inline-block;
width: 50%;
height: 20px;
background-color: skyblue;
}
span.rightspan {
display: inline-block;
width: 40%;
height: 20px;
background-color: red;
}
<table>
<tr>
<td><span class="leftspan"></span><span class="rightspan"></span>12</td>
<td><span class="leftspan"></span><span class="rightspan"></span>25</td>
</tr>
</table>
In the demo 2 numbers (12, 25) shouldn't wrap into the next line. I need to achieve this without position property.

Using display:flex on the td element and flex-grow: 1 in the element containing the number will make this element to fill the rest of the space on the parent td element. then you can make them overlap using a translateX transform. Check this answer for extra info about how flex and flex-grow.
table {
border-collapse: collapse;
width: 200px;
}
table tr td {
border: 1px solid;
display: flex;
}
span.leftspan {
display: inline-block;
width: 50%;
height: 20px;
background-color: skyblue;
}
span.rightspan {
display: inline-block;
width: 40%;
height: 20px;
background-color: red;
}
span.rest {
flex-grow: 1;
transform: translateX(-100%)
}
<table>
<tr>
<td><span class="leftspan"></span><span class="rightspan"></span><span class="rest">12</span></td>
<td><span class="leftspan"></span><span class="rightspan"></span><span class="rest">25</span></td>
</tr>
</table>

Added Div, and added style for Div
table {
border-collapse: collapse;
width: 200px;
}
table tr td {
border: 1px solid;
}
table tr td div {
display: flex;
}
span.leftspan {
display: inline-block;
width: 50%;
height: 20px;
background-color: skyblue;
}
span.rightspan {
display: inline-block;
width: 40%;
height: 20px;
background-color: red;
}
<table>
<tr>
<td>
<div>
<span class="leftspan"></span><span class="rightspan"></span>12
</div>
</td>
<td>
<div>
<span class="leftspan"></span><span class="rightspan"></span>25
</div>
</td>
</tr>
</table>

Related

focus-within css not working for html label

I'm trying to build a dropdown list with checkboxes in dropdown area.
Here is the code I'm using:
.search-box {
color: black;
width: 450px;
}
.search-box .fake-tb {
display: flex;
flex-wrap: nowrap;
background: #ffffff;
border: 1px solid #e5e5e5;
box-sizing: border-box;
border-radius: 6px;
padding: 2px 5px;
margin: auto;
height: 35px;
max-width: 700px;
}
.search-box .fake-tb * {
border: 0 !important;
height: auto !important;
}
.search-box .fake-tb input[type=search] {
border-radius: 6px;
width: 100% !important;
outline: none;
}
.search-box .fake-tb img {
vertical-align: middle;
margin: auto;
padding: 2px;
}
.search-box .dropdown {
display: none;
position: absolute;
border: 1px solid #e5e5e5;
cursor: default;
background: white;
z-index: 99999;
text-align: left;
}
.search-box:focus-within .dropdown {
display: block;
background-color: white;
color: black;
}
.search-box .dropdown>table {
padding: 3px 10px 3px 2px;
width: 100%;
}
.search-box .dropdown table tr:hover {
background-color: lightskyblue;
}
<div>line before ...</div>
<div class="search-box">
<div class="fake-tb">
<input name="ctl32$txtCusSearch" id="ctl32_txtCusSearch" auto-complete="off" type="search">
<img src="search.svg" />
</div>
<div class="dropdown">
<table id="ctl32_lstOptions">
<tbody>
<tr>
<td><input id="ctl32_lstOptions_0" name="ctl32$lstOptions$0" type="checkbox" value="Value1"><label for="ctl32_lstOptions_0">Checkbox 1</label></td>
</tr>
<tr>
<td><input id="ctl32_lstOptions_1" name="ctl32$lstOptions$1" type="checkbox" value="Value2"><label for="ctl32_lstOptions_1">Checkbox 2</label></td>
</tr>
<tr>
<td><input id="ctl32_lstOptions_2" name="ctl32$lstOptions$2" type="checkbox" value="Value3"><label for="ctl32_lstOptions_2">Checkbox 3</label></td>
</tr>
<tr>
<td><input id="ctl32_lstOptions_3" name="ctl32$lstOptions$3" type="checkbox" value="Value4"><label for="ctl32_lstOptions_3">Checkbox 4</label></td>
</tr>
<tr>
<td><input id="ctl32_lstOptions_4" name="ctl32$lstOptions$4" type="checkbox" value="Value5"><label for="ctl32_lstOptions_4">Checkbox 5</label></td>
</tr>
</tbody>
</table>
</div>
</div>
<div>line after ...</div>
There are 2 problems I'm struggling with:
Clicking on checkbox works fine, but clicking on its label closes the dropdown. How can I keep it open?
How do I make the width of dropdown equal to the textbox area, without specifying a fixed width?
I'll prefer a pure CSS solution if possible.
:focus-within activates when an element within your div is focused. However, most elements, including label, cannot be focused on. input can be, which is why your dropdown doesn't disappear on checking a checkbox.
To fix this simply add the tabindex="0" attribute to your label elements.

HTML Horizontal Scroll not showing up

I am having trouble getting the horizontal scroll bar to show up. I can still scroll horizontally with the track pad and everything is formatted correctly but the bar itself is not showing up so that you can use it to move horizontally on the table with the mouse. Any help figuring this out would be greatly appreciated, thank you!
HTML - Through React Framework
{/* Order */}
<div className ="order">
<table>
<tbody>
<tr>
<td>Id</td>
<td>Farm</td>
<td>Field</td>
<td>W/O</td>
<td>Job</td>
<td>APA</td>
<td>Acres</td>
<td>Status</td>
<td>Solution</td>
<td>Date Ordered</td>
<td>Date Sampled</td>
<td>Date Billed</td>
<td>Price</td>
<td>Years Billed</td>
<td>Split 1</td>
<td>Split 2</td>
</tr>
{orders.map((order, num) => {
let splitOne = ""
let splitTwo = ""
if(order.split_one_name.length > 1){
splitOne = `${order.split_one_name} - ${order.split_one_share}`
}
if(order.split_two_name.length > 1){
splitTwo = `${order.split_two_name} - ${order.split_two_share}`
}
return (
<tr key={order.id}>
<td>{order.id}</td>
<td>{order.farm}</td>
<td>{order.field}</td>
<td>{startInputMode(order.wo_num, num, 'wo_num')}</td>
<td>{startInputMode(order.job_num, num, 'job_num')}</td>
<td>{order.firstname + " " + order.lastname}</td>
<td>{order.acres}</td>
<td>{startInputMode(order.status, num, 'status')}</td>
<td>{order.solution}</td>
<td>{order.date_ordered.slice(0,10)}</td>
<td>{startInputMode(order.date_sampled, num, 'date_sampled')}</td>
<td>{startInputMode(order.date_billed, num, "date_billed")}</td>
<td>{order.price}</td>
<td>{order.years_billed}</td>
<td>{splitOne}</td>
<td>{splitTwo}</td>
</tr>)
})}
</tbody>
</table>
</div>
CSS
table {
font-family: arial, sans-serif;
border-collapse: collapse;
align-self: center;
justify-self: center;
width: 100%;
overflow: scroll;
white-space: nowrap;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
min-width: 100px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
.order {
display: block;
grid-area: orders;
height: 100%;
width: 100%;
align-self: center;
justify-self: center;
max-height: 520px;
overflow: scroll;
justify-content: center;
align-content: center;
}
::-webkit-scrollbar {
width: 5px;
height: 0px;
}
::-webkit-scrollbar-track {
box-shadow: inset 0 0 5px grey;
border-radius: 10px;
}
::-webkit-scrollbar-thumb {
background: grey;
border-radius: 10px;
}
In your table css, change overflow: scroll to overflow: auto.
Then remove height: 0px from ::-webkit-scrollbar.
::-webkit-scrollbar Docs

<td> has imaginary middle padding

Hello Ive ran into this problem where I cant seem to get the table data border to line up with the border of the border here is the code:
<table id="proxy-list">
<tr>
<th>Proxies</th>
</tr>
<tr>
<td>Proxy1</td>
<td>12.34.54.78.90</td>
</tr>
</table>
and heres the css:
#proxy-list {
position: absolute;
top: 15%;
left: 60%;
border: 5px solid #e83737;
border-collapse: collapse;
}
th {
width: 300px;
height: 50px;
border: 5px solid #e83737;
text-align: center;
}
th, td {
color: #4F8AFF;
}
td {
width: 20px;
height: 180px;
padding-bottom: 100px;
}
Ive been trying to fix this forever Please help!!!!!
Add colspan attribute to th tag. The colspan attribute defines the number of columns a cell should span.
<th colspan="2">Proxies</th>
#proxy-list {
position: absolute;
top: 15%;
left: 60%;
border: 5px solid #e83737;
border-collapse: collapse;
}
th {
width: 300px;
height: 50px;
border: 5px solid #e83737;
text-align: center;
}
th,
td {
color: #4f8aff;
}
td {
width: 20px;
height: 180px;
padding-bottom: 100px;
}
<table id="proxy-list">
<tr>
<th colspan="2">Proxies</th>
</tr>
<tr>
<td>Proxy1</td>
<td>12.34.54.78.90</td>
</tr>
</table>
Set colspan=2 in th header
<table id="proxy-list">
<tr>
<th **colspan=2**>Proxies</th>
</tr>
<tr>
<td>Proxy1</td>
<td>12.34.54.78.90</td>
</tr>
</table>

How can I set width to td?

How can I keep cell phone words in the same line?
.label {
width: 300px;
padding: 5px 15px;
}
.input {
border: 1px solid red;
width: 100%;
}
.input > input {
width: calc(100% - 4px);
}
<form class="frm-find-people">
<table>
<tbody>
<tr>
<td class="label">Cell Phone</td>
<td class="input"><input type="text" name="name"></td>
</tr>
</tbody>
</table>
</form>
As you see, I've set width: 300px for that column. But seems it doesn't apply. Why?
Add white-space: nowrap; to .label:
.label {
padding: 5px 15px;
white-space: nowrap;
}
.input {
border: 1px solid red;
width: 100%;
}
.input > input {
width: calc(100% - 4px);
}
<form class="frm-find-people">
<table>
<tbody>
<tr>
<td class="label">Cell Phone</td>
<td class="input"><input type="text" name="name"></td>
</tr>
</tbody>
</table>
</form>
the 300px width is not being applied because you have a width:100% on the next column, which tells it to occupy as much space as it can.
To fix that, you have to remove the width:100% on the next td. Transfer that to the text field instead. Finally, set the entire table to have width:100% so it covers the entire parent. Below is the corrected CSS.
table {
width: 100%; /* This should be 100% */
}
.label {
width: 300px;
padding: 5px 15px;
}
.input {
border: 1px solid red;
/* remove width 100% from here */
}
.input > input {
width: 100%; /* this should be 100% */
}
Use following css:
table { width:100%; } .label { width: 30%; padding: 5px 15px; } .input { border: 1px solid red; width:70%; } .input > input { width: calc(100% - 4px); }
The problem with your code, is that you should have:
table.mytable {
width: 100%;
}
Because the <td> is a child element of the <table class="mytable">. So the parent element has to have a set size to be able to modify child elements such as <td>. The added mytable class is so that it only affects that table incase you have others.
You've set .input to width: 100%, which is shrinking .label down to the smallest size possible (the length of the words inside)
You could use css calc to make .input 100vw - 300px wide
.input {
width: calc(100vw - 300px);
}
And
.input > input {
width: calc(100vw - 300px);
}
.label {
padding: 5px 15px;
border: 1px solid red;
width: 300px;
}
.input {
border: 1px solid red;
width: calc(100vw - 300px);
}
.input > input {
width: calc(100vw - 300px);
}
tr {
border: 1px solid blue;
}
<form class="frm-find-people">
<table>
<tbody>
<tr>
<td class="label">Cell Phone</td>
<td class="input"><input type="text" name="name"></td>
</tr>
</tbody>
</table>
</form>

Element containing another overflowing element in jquery

I need to see if an element in jQuery contains another overflowing element.
I need to do this without referring to/knowing the elements that could be overflowing into it - just that some other element overflows into the current cell
Snippet below (ignoring varying widths)
$.fn.exists = function () {
return this.length !== 0;
}
$( document ).ready(function() {
var $element = $('td#append');
var do_spans_exist = $('span', $element).exists();
if ( do_spans_exist == true );
//change top position
add_html = $('td#append').append('<span class="span1"></span>'); //and have some top position attribute
});
.table1 {
border:1px solid navy;
width: 70%;
text-align: center;
}
.table1 td {
width: 100px;
height: 100px;
vertical-align: top;
text-align: right;
border: 1px solid #c6c6ec;
position: relative;
left: 0;
position: relative;
}
.span1 {
display: inline-block;
width: 300px;
height: 30px;
background-color: blue;
z-index: 1;
position:absolute;
border: solid black 1px;
}
div {
position: relative;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<div>
<table class="table1">
<tr>
<td><span class="span1"></span></td>
<td id="append"></td>
<td></td>
<td></td>
</tr>
</table>
</div>
So before I append the span in jQuery, I want to get if there are any other span elements overflowing into the cell. So I can change the position to avoid overlap.
My exists() function only gets a span that is physically in the cell rather than overflowing into it.
Thanks!
try this css and don't use your .table1 you will get result
.table1 td {
width: 100px;
height: 100px;
vertical-align: top;
border: 1px solid #c6c6ec;
position: relative;
left: 0;
position: relative
}
.span1 {
display: inline-block;
width: 418px;
height: 30px;
background-color: blue;
z-index: 1;
position:absolute;
border: solid black 1px;
}
Just check if the width of element inside another, is greater than its parent...

Categories

Resources