I have a very convoluted table in which I have to add a menu that appears on hover and has its position based on each row's position.
Every row is generated at the same time in a loop (React props.map), so changing the next row z-index is possible, but I don't know if I should.
I managed to do some work, but I can't seem to make the menu appear on top of the "th" other than its parent.
I know it (probably) has to do with the Stacking Context, but I don't know how to fix this.
This fiddle represents a very resumed version of the table: https://jsfiddle.net/4n9bj16x/2/
I tried a lot of things, and some worked but then it broke something else. What I need is a way of maintaining the first column fixed and make this menu overlap all "th" siblings.
Things that worked but broke something else:
Taking the "sticky" position out of the "th", the menu will overlap perfectly, but then it break the fixed first column.
Make the menu relative positioned, then it enters the normal flow, but that makes the div grow in and out.
Remove the "th" background-color property, but then it becomes invisible and, when the table is scrolled, you can see all the other columns underneath.
Thanks in advance!
PS: The original table is coded in React and SCSS, if this is of any help.
HTML & CSS: (the fiddle is written in scss because its easier to read)
.overflowTable {
overflow-x: scroll;
margin-left: 0;
overflow-y: visible;
padding: 0;
position: relative;
height: 100vh;
}
table {
border-collapse: separate;
}
tr {
background-color: white;
}
th {
border-right: 2px solid #eee;
font-weight: 600;
color: #333;
left: 0;
position: sticky;
z-index: 2;
background-color: inherit;
}
tbody tr:hover {
background-color: #fafafa;
}
tbody th {
cursor: pointer;
}
tbody td {
cursor: grab;
}
tbody td:active {
cursor: grabbing;
}
.headerTable {
font-family: "Open-sans", sans-serif;
font-style: normal;
font-weight: 600;
font-size: 18px;
line-height: 25px;
color: #666;
border-bottom: 2px solid #eee;
padding: 10px 30px;
min-width: 150px;
}
.content {
padding: 10px 30px;
}
.content .actualMenu {
visibility: hidden;
}
.content .menuMore {
position: absolute;
width: 250px;
visibility: hidden;
right: 0;
background-color: #333;
color: white;
box-shadow: 0 4px 2px rgba(0, 0, 0, 0.1), 4px 4px 10px rgba(0, 0, 0, 0.1);
}
.content:hover .actualMenu, .content:hover .menuMore {
visibility: visible;
}
.content .title {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
.content .title .name {
flex: 1;
}
.content .title .moreOptions {
position: relative;
flex: 0;
}
<div class="overflowTable">
<table>
<thead>
<tr>
<th class="headerTable">
Name
</th>
<td class="headerTable">
Status
</td>
<td class="headerTable">
People
</td>
<td class="headerTable">
Date
</td>
</tr>
</thead>
<tbody>
<tr>
<th class="content">
<div class="title">
<div class="name">
Name
</div>
<div class="moreOptions">
<span class="actualMenu">...</span>
<div class="menuMore"> Options<br/>
Options<br/>
Options<br/>
Options<br/>
Options<br/>
</div>
</div>
</div>
</th>
<td class="content">
Status
</td>
<td class="content">
First Person
</td>
<td class="content">
Random Date
</td>
</tr><tr>
<th class="content">
<div class="title">
<div class="name">
Name
</div>
<div class="moreOptions">
<span class="actualMenu">...</span>
<div class="menuMore"> Options<br/>
Options<br/>
Options<br/>
Options<br/>
</div>
</div>
</div>
</th>
<td class="content">
Status
</td>
<td class="content">
First Person
</td>
<td class="content">
Random Date
</td>
</tr>
</tbody>
</table>
</div>
FIRST ANSWER:
You have to remove background-color: inherit; from th.
w3schools resource:
The inherit keyword specifies that a property should inherit its value from its parent element.
UPDATE:
First of all, sorry for misunderstanding,
You gave z-index: 2; to .content class. Its mean all .content elements have equal index. You can fix this and add another way. Go second row and add z-index: 3; then you will understand me. :)
here is fiddle
<th class="content" style="z-index: 3!important;">
Sorry for my bad english.
On hover change tr's and th's z-index
.overflowTable {
overflow-x: scroll;
margin-left: 0;
overflow-y: visible;
padding: 0;
position: relative;
height: 100vh;
}
table {
border-collapse: separate;
}
tr {
background-color: white;
position: relative;
z-index: 1;
}
tr:hover {
z-index: 2;
}
tr:hover th {
z-index: 3;
}
th {
border-right: 2px solid #eee;
font-weight: 600;
color: #333;
left: 0;
position: sticky;
z-index: 2;
background-color: inherit;
}
tbody tr:hover {
background-color: #fafafa;
}
tbody th {
cursor: pointer;
}
tbody td {
cursor: grab;
}
tbody td:active {
cursor: grabbing;
}
.headerTable {
font-family: "Open-sans", sans-serif;
font-style: normal;
font-weight: 600;
font-size: 18px;
line-height: 25px;
color: #666;
border-bottom: 2px solid #eee;
padding: 10px 30px;
min-width: 150px;
}
.content {
padding: 10px 30px;
}
.content .actualMenu {
visibility: hidden;
}
.content .menuMore {
position: absolute;
width: 250px;
visibility: hidden;
right: 0;
background-color: #333;
color: white;
box-shadow: 0 4px 2px rgba(0, 0, 0, 0.1), 4px 4px 10px rgba(0, 0, 0, 0.1);
}
.content:hover .actualMenu, .content:hover .menuMore {
visibility: visible;
}
.content .title {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
.content .title .name {
flex: 1;
}
.content .title .moreOptions {
position: relative;
flex: 0;
}
<div class="overflowTable">
<table>
<thead>
<tr>
<th class="headerTable">
Name
</th>
<td class="headerTable">
Status
</td>
<td class="headerTable">
People
</td>
<td class="headerTable">
Date
</td>
</tr>
</thead>
<tbody>
<tr>
<th class="content">
<div class="title">
<div class="name">
Name
</div>
<div class="moreOptions">
<span class="actualMenu">...</span>
<div class="menuMore"> Options<br/>
Options<br/>
Options<br/>
Options<br/>
Options<br/>
</div>
</div>
</div>
</th>
<td class="content">
Status
</td>
<td class="content">
First Person
</td>
<td class="content">
Random Date
</td>
</tr><tr>
<th class="content">
<div class="title">
<div class="name">
Name
</div>
<div class="moreOptions">
<span class="actualMenu">...</span>
<div class="menuMore"> Options<br/>
Options<br/>
Options<br/>
Options<br/>
</div>
</div>
</div>
</th>
<td class="content">
Status
</td>
<td class="content">
First Person
</td>
<td class="content">
Random Date
</td>
</tr>
</tbody>
</table>
</div>
Related
I have a custom table and what I would like to have is some text box appearing after you hover over its row. Some of the rows will be blurred, so I will add this in the example code as well. The issue that I'm facing is that I am clearly not good at CSS or HTML and I can't quite figure out how to adress the table row for that to work correctly and I have not found any solutions for that. I have successfully added the same tooltip to the column names, so you will se what I want to achieve in the example below:
<style>
* {
box-sizing: border-box;
}
.tooltip {
font-size: 15px;
position: relative;
display: inline-block;
}
.tooltip .tooltiptext {
visibility: hidden;
max-width: 60vw;
background-color: white;
border-style: solid;
border-color: #1a7bc9;
color: #000;
text-align: left;
border-radius: 6px;
padding: 15px 15px;
position: absolute;
z-index: 100;
bottom: 100%;
left: 50%;
margin-left: 0%;
/* I think this ↑ is supposed to help with it skewing to the right
but it does not... */
}
.tooltip:hover .tooltiptext {
visibility: visible;
}
.styled-table:hover .tooltiptext {
visibility: visible;
}
.styled-table th,
.styled-table td {
padding: 12px 15px;
}
.styled-table tbody tr:nth-of-type(even):hover,
.styled-table tr:hover {
background-color: #c7c7c7;
}
.styled-table {
border-collapse: collapse;
margin: 25px 0;
font-size: 0.9em;
font-family: sans-serif;
min-width: 400px;
max-width: 57vw;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
position: relative;
margin-left: 15vw;
cursor: pointer;
}
.styled-table tbody tr:nth-of-type(even) {
background-color: #f3f3f3;
}
.styled-table tbody tr.active-row {
font-weight: bold;
}
</style>
<div class='tooltip'><Tooltip>
<span class="tooltiptext">this is just a minimal tooltip</span>
</div>
<table>
<thead>
<tr>
<th id="C1">Column_1
</th>
<th id="C2">
<div class="tooltip">Column_2
<span class="tooltiptext">This is my favourite column, it's so epic ngl</span>
</div></th>
<th id="C3" >
<div class="tooltip">Column_3
<span class="tooltiptext">This one is also good, but I like column 2 a little more</span>
</div>
</th>
<tr class="styled-table" style="text-color: #1a7bc9
filter: blur(4px) -o-filter:blur(4px)
-ms-filter:blur(4px);
-moz-filter:blur(4px);
-webkit-filter: blur(4px);
"> <!-- For some reson blur ignores text-color -->
<span class="tooltiptext">This is not supposed to be visible</span>
<td>Wow, hidden</td>
<td>Shhhh</td>
<td>Epic</td>
</tr>
</table>
Here you can see that I have a table row of class styled-table and inside of it there is a class tooltiptext. I am trying to adress it using .styled-table:hover .tooltiptext, but nothing happens. Also, the tooltip appears to be skewed to the right and blur removes the text color, but this is not the main concern :)
This is what I'm trying to make
There are a couple reasons on why I'm having trouble making this, I can't put all of these tables in one big table since that will make the main box able to go through all the obstacles.
Here's the code for a simple level to show what I'm trying to do exactly:
Html:
<!DOCTYPE HTML>
<html lang="en-us">
<head>
<title> Level 1 </title>
<link rel="stylesheet" type="text/css" href="Mohanned_Project.css" />
<style>
body {
background: blue;
background-size: cover;
}
</style>
</head>
<body>
<table>
<tr>
<th>
<img src="Obstacle_1.png" height="285px" width="1400px">
<img src="Box.png" id="Goat" align="left">
<img src="Win.png" align="right">
</th>
</tr>
</table>
<table style="padding: 0px 1300px 1300px 0px;">
<tr>
<th>
<img src="Obstacle_1.png" height="285px" width="1400px">
</th>
</tr>
</table>
</body>
</html>
Css:
#Goat {
position: sticky;
top: 300px;
left: 10px;
right: 10px;
}
#Goat_2 {
position: sticky;
top: 10px;
left: 10px;
right: 10px;
}
.btn{
color: #fff;
border: none;
margin: 5px;
padding: 10px 8px;
font-size: 20px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 2px;
cursor: pointer;
border-radius: 10px;
transition: 0.4s;
transition-property: box-shadow;
}
.btn-primary{
font-size: 31px;
}
and heres the result: When you move the screen, the red box sticks to the borders and moves
I would really apprecciate advice on how do I set up the 2nd level since I've been trying for an hour and can't seem to figure it out
Stop using tables. Use divs. and flexbox.
.cafeteria {
display: flex;
flex-direction: column;
}
.first-row {}
.table-row {
display: flex;
}
.table {
width: 40px;
height: 200px;
border: 1px solid black;
background-color: brown;
}
.small-table {
align-self: flex-end;
width: 40px;
height: 100px;
background-color: brown;
}
.small-table.blue {
background-color: blue;
}
.small-table.green {
background-color: green;
}
<div class="cafeteria">
<div class="first-row">
<div class="small-table blue"></div>
</div>
<div class="table-row">
<div class="table"></div>
<div class="small-table"></div>
<div class="table"></div>
<div class="small-table"></div>
<div class="table"></div>
<div class="small-table"></div>
<div class="table"></div>
<div class="small-table green"></div>
<div class="table">
</div>
</div>
</div>
I'm struggling with something regarding jQuery, HTML and CSS. I am currently working on a project that is to do with a railway company. I am designing the website, I completed the Home page, but I am now on the tickets page. I am using only HTML,CSS and jQuery to build this site but I just cannot get the tickets page to work properly. I created a ticket section that has a purchase button after you selected if you are an adult, but all the purchase buttons appear if just one of the trips's, can someone please help me out, the purchase button all have the same class name but I know that using $(this).find(".className").show(); always works but it does not seem to now. I also tried $("tr").find(".className").show(); as well as $("this").closest(".classname").show();
// Trips Page Functionality
$("input").click(function() {
$("tr").first(".purchase-button").fadeIn(800);
});
//footer functionality
$("#social-media-group").mouseenter(function() {
$(this).find(".facebook-block").attr("src", "assets/icons/facebook-hover.svg");
});
$("#social-media-group").mouseleave(function() {
$(this).find(".facebook-block").attr("src", "assets/icons/facebook.svg");
});
$("#social-media-group").mouseenter(function() {
$(this).find(".instagram-block").attr("src", "assets/icons/instagram-hover.svg");
});
$("#social-media-group").mouseleave(function() {
$(this).find(".instagram-block").attr("src", "assets/icons/instagram.svg");
});
$("#social-media-group").mouseenter(function() {
$(this).find(".youtube-block").attr("src", "assets/icons/youtube-hover.svg");
});
$("#social-media-group").mouseleave(function() {
$(this).find(".youtube-block").attr("src", "assets/icons/youtube.svg");
});
});
* {
padding: 0;
margin: 0;
}
body {
overflow-x: hidden;
}
#container {
background-color: #000000;
width: 100%;
height: auto;
}
/* Nav-Bar Styling */
#overlay {
position: fixed;
background-color: rgba(203, 187, 42, 0.6);
width: 100%;
z-index: 2;
}
#header {
background-color: black;
height: 150px;
text-align: center;
}
#phone-div {
margin-top: 0px;
position: relative;
right: 350px;
bottom: 100px;
}
h6 {
font-family: 'Prata', serif;
color: white;
font-size: 12px;
}
#email-div {
margin-top: 0px;
position: relative;
left: 350px;
bottom: 150px;
}
#dropdown {
width: 700px;
height: 50px;
margin: 0 auto;
}
#dropdown:hover {
transition: 0.2s;
}
li {
text-decoration: none;
display: inline;
margin-left: 150px;
text-align: center;
position: relative;
left: -50px;
font-family: 'Prata', serif;
position: relative;
top: 14px;
color: white;
}
li:hover {
text-shadow: 2px 2px 5px black;
transition: 0.2s;
cursor: pointer;
}
a {
text-decoration: none;
}
/* End of Nav Bar Styling */
/* Container styling */
h1 {
font-family: 'MonteCarlo', 'sans-serif';
color: white;
position: relative;
top: 220px;
left: 50px;
text-align: center;
font-size: 62px;
}
h2 {
position: relative;
top: 300px;
margin-left: 120px;
margin-right: 120px;
color: white;
font-family: 'Prata', 'sans-serif';
border-radius: 10px;
text-align: center;
}
/* Tickets Section Styling */
#tickets-group {
width: 100%;
height: auto;
margin: 50px;
;
border-radius: 10px;
position: relative;
top: -2200px;
right: 50px;
}
table {
width: 70%;
position: relative;
left: 20px;
border-collapse: collapse;
position: relative;
left: 250px;
background-color: rgba(0, 0, 0, 0.5);
border: none;
}
th {
color: white;
font-family: 'Prata', 'sans-serif';
text-align: center;
border-bottom: 1px solid rgba(255, 255, 255, 0.5);
border-radius: 10px;
}
td {
color: white;
text-align: center;
border-right: 3px solid rgba(0, 0, 0, 0.5);
font-family: 'Prata', serif;
}
input:hover {
cursor: pointer;
}
.trips:hover {
cursor: pointer;
background-color: rgba(203, 187, 42, 0.6);
transition: 0.3s;
}
.purchase-button {
text-align: center;
position: relative;
left: 43%;
font-size: 24px;
border-bottom: none;
}
table:hover {
box-shadow: 3px 1px 20px black;
transition: 0.3s ease;
}
h3 {
font-family: 'Prata', serif;
font-size: 24px;
}
.purchase-button:hover {
transition: 0.3s;
cursor: pointer;
background-color: rgba(0, 0, 0, 0.5)
}
/* Footer Styling */
#footer {
width: 100%;
float: left;
background-color: #CBBB2A;
overflow: hidden;
}
#social-media-group img {
margin: 20px;
position: relative;
left: 40%;
bottom: 130px;
}
/* End of Footer Styling */
<!DOCTYPE html>
<html>
<head>
<meta name="author" content="Wiaan Duvenhage">
<meta name="lecturer" content="Armand Pretorius">
<meta name="assessment" content="Website-root">
<meta name="studentnumber" content="200307">
<meta name="subject" content="DV100">
<meta name="class" content="Class 2">
<link rel="stylesheet" href="../css/trips-page.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Julius+Sans+One&family=MonteCarlo&family=Prata&display=swap" rel="stylesheet">
<title>Velocity Railways</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="../js/data.js"></script>
<script src="../js/index.js"></script>
</head>
<body>
<div id="container">
<div id="overlay">
<div id="header">
<img src="../assets/logo.svg" alt="velocity_logo" width="200px">
<div id="phone-div">
<img src="../assets/icons/phone .svg" alt="phone_icon" width="30px">
<h6>+27 12 785 3355</h6>
</div>
<!--Phone Div-->
<div id="email-div">
<img src="../assets/icons/email.svg" alt="phone_icon" width="30px">
<h6>enquiries#velocityrailways.co.za</h6>
</div>
<!--Email Div-->
</div>
<!--Header-->
<div id="dropdown">
<ul>
<a href="pages/trips-page.html">
<li>Trips</li>
</a>
<li>Purchase Tickets</li>
<li>About</li>
</ul>
</div>
<!-- Dropdown -->
</div>
<!--Overlay-->
<div id="inner-container">
<h1>Trips Page</h1>
<div id="introduction-body">
<h2>Welcome To Trips Page Section! Feel free to book your tickets on this page and after selecting it, proceeding to the next page, which is the Purchase Tickets Page!</h2>
</div>
<img class="home-page-image" src="../img/iccup-nNV3q_nhGKQ-unsplash.jpg" width="100%" height="auto">
<div id="tickets-group">
<table>
<tr>
<th>
<h3>FROM</h3>
</th>
<th>
<h3>TO</h3>
</th>
<th>
<h3>DEPART</h3>
</th>
<th>
<h3>ARRIVE</h3>
</th>
<th>
<h3>ADULT</h3>
</th>
</tr>
<tr class="trips">
<td>Pretoria</td>
<td>Johannesburg</td>
<td>09:00</td>
<td>10:00</td>
<td><label><input type="checkbox"><span class="checkmark"></span></label></td>
</tr>
<tr>
<th class="purchase-button">Purchase</th>
</tr>
<tr class="trips">
<td>Pretoria</td>
<td>Johannesburg</td>
<td>09:00</td>
<td>10:00</td>
<td><label><input type="checkbox"><span class="checkmark"></span></label></td>
</tr>
<tr>
<th class="purchase-button">Purchase</th>
</tr>
<tr class="trips">
<td>Pretoria</td>
<td>Johannesburg</td>
<td>09:00</td>
<td>10:00</td>
<td><label><input type="checkbox"><span class="checkmark"></span></label></td>
</tr>
<tr>
<th class="purchase-button">Purchase</th>
</tr>
<tr class="trips">
<td>Pretoria</td>
<td>Johannesburg</td>
<td>09:00</td>
<td>10:00</td>
<td><label><input type="checkbox"><span class="checkmark"></span></label></td>
</tr>
<tr>
<th class="purchase-button">Purchase</th>
</tr>
</table>
</div>
</div>
<div id="footer">
<img src="../assets/logo-footer.svg" alt="velocity_logo" width="200px">
<div id="social-media-group">
<img src="../assets/icons/facebook.svg" alt="facebook-logo" width="50px">
<img src="../assets/icons/instagram.svg" alt="facebook-logo" width="50px">
<img src="../assets/icons/youtube.svg" alt="facebook-logo" width="50px">
</div>
</div>
</div>
<!-- End of Outer Container -->
</body>
</html>
Default your purchase button should be hide by CSS property like .purchase-button{display: none;}.
After that you need to check condition of checkbox is checked or Not as respectively show/hide purchase-button through jQuery functionality.
And need to add colspan="5" attribute on .purchase-button element for standard html structure.
$(document).on('change', 'input[type="checkbox"]', function () {
if($(this).is(':checked')){
$(this).parents('.trips').next().find('.purchase-button').show();
}else{
$(this).parents('.trips').next().find('.purchase-button').hide();
}
});
* {
padding: 0;
margin: 0;
}
body {
overflow-x: hidden;
}
#container {
background-color: #000000;
width: 100%;
height: auto;
}
/* Nav-Bar Styling */
#overlay {
position: relative;
background-color: rgba(203, 187, 42, 0.6);
width: 100%;
z-index: 2;
}
#header {
background-color: black;
height: 150px;
text-align: center;
}
#phone-div {
margin-top: 0px;
position: relative;
}
#email-div {
margin-top: 0px;
position: relative;
}
h6 {
font-family: 'Prata', serif;
color: white;
font-size: 12px;
}
#dropdown {
width: 100%;
max-width: 700px;
height: 50px;
margin: 0 auto;
}
#dropdown:hover {
transition: 0.2s;
}
li {
text-decoration: none;
display: inline;
margin-left: 150px;
text-align: center;
position: relative;
left: -50px;
font-family: 'Prata', serif;
position: relative;
top: 14px;
color: white;
}
li:hover {
text-shadow: 2px 2px 5px black;
transition: 0.2s;
cursor: pointer;
}
a {
text-decoration: none;
}
/* End of Nav Bar Styling */
/* Container styling */
h1 {
font-family: 'MonteCarlo', 'sans-serif';
color: white;
position: relative;
text-align: center;
font-size: 62px;
}
h2 {
font-size: 32px;
position: relative;
color: white;
font-family: 'Prata', 'sans-serif';
border-radius: 10px;
text-align: center;
}
/* Tickets Section Styling */
#tickets-group {
width: 100%;
max-width: 1320px;
height: auto;
margin: 50px auto;
border-radius: 10px;
position: relative;
}
table {
width: 100%;
position: relative;
border-collapse: collapse;
position: relative;
background-color: rgba(0, 0, 0, 0.5);
border: none;
}
th {
color: white;
font-family: 'Prata', 'sans-serif';
text-align: center;
border-bottom: 1px solid rgba(255, 255, 255, 0.5);
border-radius: 10px;
padding: 10px;
}
td {
color: white;
text-align: center;
border-right: 3px solid rgba(0, 0, 0, 0.5);
font-family: 'Prata', serif;
padding: 10px;
}
input:hover {
cursor: pointer;
}
.trips:hover {
cursor: pointer;
background-color: rgba(203, 187, 42, 0.6);
transition: 0.3s;
}
.purchase-button {
text-align: center;
position: relative;
font-size: 24px;
border-bottom: none;
display: none;
}
table:hover {
box-shadow: 3px 1px 20px black;
transition: 0.3s ease;
}
h3 {
font-family: 'Prata', serif;
font-size: 24px;
}
.purchase-button:hover {
transition: 0.3s;
cursor: pointer;
background-color: rgba(0, 0, 0, 0.5)
}
/* Footer Styling */
#footer {
width: 100%;
float: none;
background-color: #CBBB2A;
overflow: hidden;
text-align: center;
padding: 15px;
}
#social-media-group{
width: 100%;
max-width: 1320px;
margin: 0 auto;
}
#social-media-group img {
margin: 10px 10px 0 10px;
position: relative;
}
/* End of Footer Styling */
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Julius+Sans+One&family=MonteCarlo&family=Prata&display=swap" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<div id="container">
<div id="overlay">
<div id="header">
<img src="../assets/logo.svg" alt="velocity_logo" width="200px">
<div id="phone-div">
<img src="../assets/icons/phone .svg" alt="phone_icon" width="30px">
<h6>+27 12 785 3355</h6>
</div>
<!--Phone Div-->
<div id="email-div">
<img src="../assets/icons/email.svg" alt="phone_icon" width="30px">
<h6>enquiries#velocityrailways.co.za</h6>
</div>
<!--Email Div-->
</div>
<!--Header-->
<div id="dropdown">
<ul>
<li>Trips</li>
<li>Purchase Tickets</li>
<li>About</li>
</ul>
</div>
<!-- Dropdown -->
</div>
<!--Overlay-->
<div id="inner-container">
<h1>Trips Page</h1>
<div id="introduction-body">
<h2>
Welcome To Trips Page Section! Feel free to book your tickets on this page and after selecting it,
proceeding to the next page, which is the Purchase Tickets Page!
</h2>
</div>
<img class="home-page-image" src="../img/iccup-nNV3q_nhGKQ-unsplash.jpg" width="100%" height="auto">
<div id="tickets-group">
<table>
<tr>
<th><h3>FROM</h3></th>
<th><h3>TO</h3></th>
<th><h3>DEPART</h3></th>
<th><h3>ARRIVE</h3></th>
<th><h3>ADULT</h3></th>
</tr>
<tr class="trips">
<td>Pretoria</td>
<td>Johannesburg</td>
<td>09:00</td>
<td>10:00</td>
<td><label><input type="checkbox"><span class="checkmark"></span></label></td>
</tr>
<tr>
<th colspan="5" class="purchase-button">Purchase</th>
</tr>
<tr class="trips">
<td>Pretoria</td>
<td>Johannesburg</td>
<td>09:00</td>
<td>10:00</td>
<td><label><input type="checkbox"><span class="checkmark"></span></label></td>
</tr>
<tr>
<th colspan="5" class="purchase-button">Purchase</th>
</tr>
<tr class="trips">
<td>Pretoria</td>
<td>Johannesburg</td>
<td>09:00</td>
<td>10:00</td>
<td><label><input type="checkbox"><span class="checkmark"></span></label></td>
</tr>
<tr>
<th colspan="5" class="purchase-button">Purchase</th>
</tr>
<tr class="trips">
<td>Pretoria</td>
<td>Johannesburg</td>
<td>09:00</td>
<td>10:00</td>
<td><label><input type="checkbox"><span class="checkmark"></span></label></td>
</tr>
<tr>
<th colspan="5" class="purchase-button">Purchase</th>
</tr>
</table>
</div>
</div>
<div id="footer">
<img src="../assets/logo-footer.svg" alt="velocity_logo" width="200px">
<div id="social-media-group">
<img src="../assets/icons/facebook.svg" alt="facebook-logo" width="50px">
<img src="../assets/icons/instagram.svg" alt="facebook-logo" width="50px">
<img src="../assets/icons/youtube.svg" alt="facebook-logo" width="50px">
</div>
</div>
</div>
<!-- End of Outer Container -->
You could select the parent tr with .parents('.trips'), then the next tr with .next() and then the button with .find('.purchase-button'):
$('input[type="checkbox"]').on('click', function() {
$(this).parents('.trips').next().find('.purchase-button').show();
});
I have implemented a table with horizontal scrolling in angular and have requirement to fix the first two columns while scrolling vertically. I have created a stackblitz to show two tables. What I looking for is that as and when the user scrolls the second table, the first two rows that is Legal Class Name and Fund Name should be fixed.
I tried to apply the following class to the respective tds and it didnt work
.stickyRows {
position: sticky;
}
Here is the stackblitz
https://stackblitz.com/edit/angular-o2ukfs
th {
padding: 7px;
position: sticky;
left: 0px;
min-width: 250px;
width: 250px;
background-color: #f5f7f7;
}
td {
padding: 7px;
min-width: 250px;
/* max-width: 300px; */
}
.fundClassesTable {
table-layout: fixed;
}
.cellbgcolor {
color: transparent;
}
.btn {}
.tableItem {
text-align: left;
border-left: solid 1px lightgrey;
border-top: solid 1px lightgrey;
border-right: solid 1px lightgrey;
border-bottom: solid 1px lightgrey;
}
.rowItem:hover {
background-color: #f5f7f7;
}
label {
margin-left: 0.5rem;
vertical-align: middle
}
.panel-heading {
color: black;
border-color: #ddd;
overflow: hidden;
padding-top: 5px !important;
padding-bottom: 5px !important;
}
.panel-heading .left-label {
display: inline-block;
padding-top: 5px !important;
}
.scrollClass {
overflow-x: scroll;
display: grid;
overflow-y:hidden;
height: 100%;
}
.panel-heading label {
margin-bottom: 0px !important;
}
#FundClass tr:hover {
background-color: #ECF0F1;
}
.headcol {
position: absolute;
min-width: 300px;
max-width: 300px;
width: 5em;
left: 0;
top: auto;
border-top-width: 1px;
/*only relevant for first row*/
margin-top: -1px;
/*compensate for top border*/
}
.headcol:before {
content: 'Row ';
}
.collapsed {
color: #d6630a;
font-size: 22px;
text-decoration: none;
font-weight: bold;
}
.expanded {
color: #d6630a;
font-size: 22px;
text-decoration: none;
font-weight: bold;
}
.fixed-side {
border: 1px solid #000;
background: #eee;
visibility: visible;
}
.card-body {
flex: 1 1 auto;
padding: 0px;
margin: 10px 0;
background-color: white;
}
<div class="card">
<div class="card-header panel-heading">
<span class="left-label" style="font-size: 18px; font-weight: bold; ">Accounting Fund Classes</span>
</div>
<div [ngClass]="{'show': isExpanded}" id="fundClass" class="collapse" role="tabpanel" aria-labelledby="fundClass_heading"
data-parent="#fundClass" [attr.aria-expanded]="isExpanded">
<div class="card-body scrollClass" *ngIf="data">
<table id="FundClass" class="fundClassesTable table-striped">
<tr *ngFor="let c of ColumnNames">
<th Fund Name scope="col" [ngClass]="c != 'Buttons1'? 'tableItem bold' : 'tableItem cellbgcolor'"> {{ c }}</th>
<ng-container *ngFor="let f of data let i=index">
<td class="tableItem" style="font-weight: bold" *ngIf="c == 'Fund Name'">
{{ f.FundName}}
</td>
<td [attr.id]="'f.Id'" *ngIf="c == 'Accounting Class Name'"
class="tableItem">
{{ f.FundName}}
</td>
<td class="tableItem" *ngIf="c == 'Class ID'">{{f.Id}}</td>
<td [attr.id]="'f.Id'" *ngIf="c == 'Legal Fund Class'"
class="tableItem">
{{ f.LegalFundClassName}}
</td>
<td [attr.id]="'f.Id'" *ngIf="c == 'Invested Amount'"
class="tableItem">
{{ f.InvestedAmount | number : '.2-2'}}
</td>
<td [attr.id]="'f.Id'" *ngIf="c == 'Vehicle Type'"
class="tableItem">
{{ f.VehicleTypeName}}
</td>
<td [attr.id]="'f.Id'" *ngIf="c == 'Closure Status'"
class="tableItem">
{{ f.ClosureStatusName}}
</td>
<td class="tableItem" *ngIf="c == 'Buttons1'">
<button *ngIf="!EditMode[f.Id]" type="button"
class="btn btn-primary btn mr-1 "
(click)="buttonClicked(f.Id)">Edit</button>
<button *ngIf="EditMode[f.Id]" type="button"
class="btn btn-primary btn mr-1"
(click)="buttonClicked(f.Id)">Cancel</button>
</td>
</ng-container>
</tr>
</table>
</div>
</div>
</div>
I hope this is what you were looking for:
app.component.css
/* Container should define how tall the scrollable content is */
.scrollClass{
height: 500px;
}
/* tagetting the first <th>; to ensure <th> are scrolled along with <td> */
.fundClassesTable tr:nth-child(1) th{
z-index: 3;
position: sticky;
position: -webkit-sticky;
top: 2px;
}
/* target all <td> in the first row to be sticky */
.fundClassesTable tr:nth-child(1) td{
color: red;
position: sticky;
position: -webkit-sticky;
top: 2px;
z-index: 2;
background-color: white;
font-weight: bold;
}
/* Same as above but with top property as 36px
because the 2nd "row" is 36px from the top of <table> */
.fundClassesTable tr:nth-child(2) th{
z-index: 3;
position: sticky;
position: -webkit-sticky;
top: 38px;
}
.fundClassesTable tr:nth-child(2) td{
color: red;
position: sticky;
position: -webkit-sticky;
top: 38px;
z-index: 2;
background-color: white;
font-weight: bold;
}
Forked Stackblitz
EDIT:
Riv's solution has worked for me but i am left with one nagging problem. As I scroll through the fixed rows , I can see the data of the rows visible between gaps of the fixed rows and border of the fixed rows arent visible
Probably not the best solution out there but I would use ::after pseudo selector to create a background for your stickied table cells to hide the background cells when scrolling down.
.fundClassesTable tr:nth-child(1)::after{
content: '';
position: absolute;
height: 71px;
width: 96.7%;
top: 55px;
left: 19px;
z-index: 1;
background-color: white; //create a white background to cover your other cells when scrolled down
border: solid 1px deeppink;
}
try adding this to your styling
.card-body{
height:200px;
position:relative!important;
overflow-y:scroll;
}
table tr:nth-child(1){
position :sticky;
top:0;
z-index:999;
left:0;
background-color:#fff;
}
table tr:nth-child(2){
position :sticky;
top:35px;
z-index:999;
background-color:#fff;
left:0;
}
I have a dynamically resizing table for small browser windows. It resizes great! It looks great under 810px, but the problem is that I want it to lock the size of the table once its over 800px. Right now when I get over 810px, I lose the Arial font and the border-collapse. I don't know why this isn't working!
Please take a look and see if a new set of eyes can spot what's going on.
#formatscreen {
font-family: Arial;
width: 800px;
border-collapse: collapse;
}
th {
background: black;
color: white;
font-size: 20px;
}
th,
td {
border: 1px solid #000;
border-bottom: 2px solid #fff;
// padding-left: 5px;
// padding-right: 5px;
}
#screen_symbol {
font-size: 40px;
font-weight: bold;
text-align: center;
display: inline-block
}
#screen_price {
font-size: 32px;
font-weight: bold;
display: inline-block
}
#screen_net_pct {
font-size: 24px;
font-weight: bold;
display: inline-block
}
#screen_expiry.header,
#screen_type.header,
#screen_dist.header,
#screen_short_leg.header,
#screen_long_leg.header {
font-size: 20px;
display: inline-block
}
#screen_change.header,
#screen_delta.header,
#screen_short_leg_vol.header,
#screen_long_leg_vol.header,
#screen_net.header {
font-size: 14px;
display: inline-block
}
#screen_expiry,
#screen_type,
#screen_dist,
#screen_short_leg,
#screen_long_leg {
font-size: 24px;
display: inline-block
}
#screen_change,
#screen_delta,
#screen_short_leg_vol,
#screen_long_leg_vol,
#screen_net {
font-size: 16px;
display: inline-block
}
#media only screen and (max-device-width: 480px),
(max-width: 810px) {
#formatscreen {
font-family: Arial;
width: 100%;
border-collapse: collapse;
}
th {
background: black;
color: white;
font-size: 2.5vw;
}
th,
td {
border: 1px solid #000;
border-bottom: 2px solid #fff;
// padding-left: 5px;
// padding-right: 5px;
}
#screen_symbol {
font-size: 5vw;
font-weight: bold;
text-align: center;
display: inline-block
}
#screen_price {
font-size: 4vw;
font-weight: bold;
display: inline-block
}
#screen_net_pct {
font-size: 3vw;
font-weight: bold;
display: inline-block
}
#screen_expiry.header,
#screen_type.header,
#screen_dist.header,
#screen_short_leg.header,
#screen_long_leg.header {
font-size: 2.5vw;
display: inline-block
}
#screen_change.header,
#screen_delta.header,
#screen_short_leg_vol.header,
#screen_long_leg_vol.header,
#screen_net.header {
font-size: 1.75vw;
display: inline-block
}
#screen_expiry,
#screen_type,
#screen_dist,
#screen_short_leg,
#screen_long_leg {
font-size: 3vw;
display: inline-block
}
#screen_change,
#screen_delta,
#screen_short_leg_vol,
#screen_long_leg_vol,
#screen_net {
font-size: 2vw;
display: inline-block
}
}
#screen_change.up {
background: green;
color: white;
}
#screen_change.down {
background: red;
color: white;
}
.center {
text-align: center;
}
.right {
text-align: right;
}
tr[data-bau="Bull Put"] {
background: #99ff99;
}
tr[data-bau="Bear Call"] {
background: #ff9999;
}
tr:hover[data-bau="Bull Put"] {
background-color: #00b300;
cursor: pointer;
}
tr:hover[data-bau="Bear Call"] {
background-color: #ff0000;
cursor: pointer;
}
<div id="prescreen">
<table id="formatscreen">
<tr>
<th>
Symbol</th>
<th>Price Action</th>
<th>Expiry Date
<br>Type</th>
<th class="right">
<div id="screen_dist" class="header">Distance</div>
<div id="screen_delta" class="header">Delta</div>
</th>
<th class="right">
<div id="screen_short_leg" class="header">Short Leg</div>
<div id="screen_short_leg_vol" class="header">Volume</div>
</th>
<th class="right">
<div id="screen_long_leg" class="header">Long Leg</div>
<div id="screen_long_leg_vol" class="header">Volume</div>
</th>
<th>Return</th>
</tr>
<tr data-bau="Bull Put">
<td>
<div id="screen_symbol">IBB</div>
</td>
<td class="center">
<div id="screen_price">$1260.39</div>
<div id="screen_change" class="down">-$12.36 (0.91%)</div>
</td>
<td class="center">
<div id="screen_expiry">20160819</div>
<div id="screen_type">Bull Put</div>
</td>
<td class="right">
<div id="screen_dist">15.5%</div>
<div id="screen_delta">0.077</div>
</td>
<td class="right">
<div id="screen_short_leg">$1220.00</div>
<div id="screen_short_leg_vol">1420</div>
</td>
<td class="right">
<div id="screen_long_leg">$1915.00</div>
<div id="screen_short_leg_vol">20</div>
</td>
<td class="right">
<div id="screen_net_pct">3.00%</div>
<div id="screen_net">$0.25</div>
</td>
</tr>
<tr data-bau="Bear Call">
<td>
<div id="screen_symbol">NFLX</div>
</td>
<td class="center">
<div id="screen_price">$1260.39</div>
<div id="screen_change" class="up">+$12.36 (0.91%)</div>
</td>
<td class="center">
<div id="screen_expiry">20160819</div>
<div id="screen_type">Bull Put</div>
</td>
<td class="right">
<div id="screen_dist">15.5%</div>
<div id="screen_delta">0.077</div>
</td>
<td class="right">
<div id="screen_short_leg">$1220.00</div>
<div id="screen_short_leg_vol">20</div>
</td>
<td class="right">
<div id="screen_long_leg">$1915.00</div>
<div id="screen_short_leg_vol">20</div>
</td>
<td class="right">
<div id="screen_net_pct">3.00%</div>
<div id="screen_net">$0.25</div>
</td>
</tr>
</table>
words words
</div>
You are using vw for font sizes. Size of vw changes according to the device width.
Check this: https://jsfiddle.net/LtLmr5s5/1/
All you need here is one simple CSS property: max-width
#formatscreen {
max-width: 800px;
width: 100%;
/* ... */
}
Your code works fine if you remove the in CSS not allowed // comments:
//# width:800px
//2.5vw = 20px
//1.75vw = 14px
//1vw = 8px
They can be used in SCSS only.
So this is enough:
#formatscreen {
font-family: Arial;
width: 800px;
border-collapse: collapse;
}
/* ... */
#media only screen and (max-device-width: 480px),
(max-width:810px) {
#formatscreen {
width: 100%;
}
/* ... */
}
/* ... */
Furthermore there is no need to set a media query for this as you can see in TheThirdMans answer.