How to make one column fixed and the other one scrollable - html

I have tried to make a page where one column is fixed and the other one is scrollable. In the template "Os name" and "{{ i.os_name }}", I want to make it fixed. All the other ones should be scrollable.
I have tried some solutions but I'm facing issues. I have pasted the CSS which I have tried. Please tell me where I am going wrong so I can make it correct.
<div>
<table class="table accountTable" id="book-table" cellpadding="0" cellspacing="0" style="width: 91%;">
<thead>
<tr class="accountBorder">
<th class="osfix">Os Name</th>
<th class="">Browser</th>
<th>IP Address</th>
<th>Location</th>
<th>Session Time</th>
<th>Activity</th>
</tr>
</thead>
<tbody>
{% for i in account %}
<tr>
<td><div class="osfixName">{{ i.os_name }}</div></td>
<td>
<div class = "title_elipses accordion">{{ i.browser }}</div>
<div class="panel" style="display: none;"><p>{{i.browser}}</p></div>
</td>
<td>
<div>{{ i.ip_address }}</div>
</td>
<td>
<div>{{ i.city }}, {{ i.country }}</div>
</td>
<td>
{% for key,value in some_date.items %}
{% if i.id == key %}
<!-- here we are displaying the age of the ad -->
<span class="dealpagetext">{{ value }}</span><br>
{% endif %}
{% endfor %}
<!-- <div>{{ i.last_loggedin }}</div>-->
</td>
<td>
{% if i.activity == 1 %}
<div>Signout</div>
{% else %}
<div></div>
{% endif %}
</td>
</tr>
{% empty %}
<tr>
<td colspan="7" class="text-center">No History</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
css
#book-table {
width: 131% !important;
margin-left: 111px;
}
.osfix {
position: fixed;
left: 0;
background-color: #ddd;
padding-left: 4px;
}
.osfixName {
position: fixed;
left: 0;
padding-left: 4px;
z-index: 88;
background-color: #fff;
}

Related

(Django) HTML: Table columns are displaying vertically

I'm currently trying to display a bunch of Information of a model inside the template.
Therefore I've been creating a table to show all of the information horizontally for every "previous game" in the database:
<table style="height: 100%">
{% for previous_game in previous_games %}
<tr>
<th> {{ previous_game.name }}</th>
</tr>
<tr>
<td> <img id="Videogame_Picture" src="{{ previous_game.image.url }}"> </td>
</tr>
<tr>
<td> {{ previous_game.date }} </td>
</tr>
<tr>
<td> {% load static %} <img id= "Result_Icon" src="{% static previous_game.min_req %} "></td>
</tr>
<tr>
<td> {% load static %} <img id= "Result_Icon" src="{% static previous_game.rec_req %} " ></td>
</tr>
<tr>
<td> PC Rig {{ previous_game.config }}</td>
</tr>
{% endfor %}
</table>
It shall look like this:
But currently all the Table columns are displaying vertically underneath instead of horizontally next to each previous game and I can't figure out why.
Can you help me out here?
Thanks in Advance!
I would have all my headers in the first row and then start looping through my games with a row per game and cells (td) for each game attribute:
<table style="height: 100%">
<tr>
<th> previous game name </th>
<th> image </th>
<th> previous game date </th>
<th> previous game result 1 </th>
<th> previous game result 2 </th>
<th> PC Rig </th>
</tr>
{% for previous_game in previous_games %}
<tr>
<td> {{ previous_game.name }} </td>
<td> <img id="Videogame_Picture" src="{{ previous_game.image.url }}"> </td>
<td> {{ previous_game.date }} </td>
<td> {% load static %} <img id= "Result_Icon" src="{% static previous_game.min_req %} "> </td>
<td> {% load static %} <img id= "Result_Icon" src="{% static previous_game.rec_req %} " ></td>
<td>{{ previous_game.config }}</td>
</tr>
{% endfor %}
</table>
Alright I got a solution:
Since I created a Row for every Information of the "previous game" - Object, in every loop, I needed to put the loop inside the Row, for being able to only create the Row once.
Now it looks like this:
<table style="height: 150px; border: 1px solid black; width: 600px">
<tr>
{% for previous_game in previous_games %}
<th> {{ previous_game.name }}</th>
{% endfor %}
</tr>
<tr>
{% for previous_game in previous_games %}
<td> <img id="Videogame_Picture" src="{{ previous_game.image.url }}"> </td>
{% endfor %}
</tr>
<tr>
{% for previous_game in previous_games %}
<td> {{ previous_game.date }} </td>
{% endfor %}
</tr>
<tr>
{% for previous_game in previous_games %}
<td style="display: inline"> {% load static %} <img id= "Result_Icon" src="{% static previous_game.min_req %} "></td>
<td style="display: inline"> {% load static %} <img id= "Result_Icon" src="{% static previous_game.rec_req %} " ></td>
{% endfor %}
</tr>
<tr>
{% for previous_game in previous_games %}
<td> PC Rig {{ previous_game.config }}</td>
{% endfor %}
</tr>
</table>
It doesn't feel like the cleanest solution tbh, but it worked for me!

unable to remove white space from HTML view with Bootstrap

I'm having an issue with the template view below. I've added a scrollbar to the "Used in" table at the bottom, however I am getting a lot of whitespace underneath it. When I try removing each div/element one by one the issue seems to come from that table alone.
view.html
{% extends "includes/base.html" %}
{% load crispy_forms_tags %}
{% block body %}
<div class="container-fluid">
<div class="row">
<div class="col">
<form method="POST">
<br>
{% csrf_token %}
{% crispy partform %}
</form>
<br>
<table class="table table-hover">
<tbody>
{% for comment in partcomments %}
<tr>
<td>{{ comment }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<form method="POST">
<br>
{% csrf_token %}
{% crispy commentForm %}
</form>
<div>
{% for image in images %}
<img class="center img-responsive" src="{{ image.image.url }}"
style="height: 25%"/>
{% endfor %}
<br>
<form enctype="multipart/form-data" method="post">
{% csrf_token %}
{{ imageform.as_p }}
<button type="submit">Upload</button>
</form>
</div>
</div>
<div class="col">
<div class="table-wrapper-scroll-y my-custom-scrollbar">
<table class="table table-hover mb-0">
<thead>
<tr>
<th>Supplier</th>
</tr>
</thead>
<tbody>
{% for supplier in partsuppliers %}
<tr data-href="{% url 'info_supplier' supplier.supplier.id %}">
<td>{{ supplier }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<a class="btn btn-secondary btn-sm btn-pad" href="{% url 'addpartsupplier' part_id=part_id %}"
role="button">Add
Supplier</a>
<div class="table-wrapper-scroll-y my-custom-scrollbar">
<table class="table table-hover mb-0">
<thead>
<tr>
<th>Movements</th>
</tr>
</thead>
<tbody>
{% for movement in movements %}
<tr>
<td>{{ movement.history_date }}</td>
<td>{{ movement.history_user }}</td>
<td>{{ movement.change }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="table-wrapper-scroll-y my-custom-scrollbar">
<table class="table table-hover mb-0">
<thead>
<tr>
<th>Used in</th>
</tr>
</thead>
<tbody>
{% for activity in activities %}
<tr>
<td>{{ activity.group.groupName }}</td>
<td>{{ activity.activity.activityName }}</td>
<td>{{ activity.qty.quantity__sum }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
{% endblock %}
I have a custom.css file served in the static folder that is loaded in the base.html as per below. The issue arises only in this view as I've tried removing the base.html and haven't found any overflow issues in my other template views
custom.css
.my-custom-scrollbar
{
position: relative;
max-height: 25%;
overflow: auto;
}
.table-wrapper-scroll-y {
display: block;
}
.center {
display: block;
margin-left: auto;
margin-right: auto;
}
I think I'm not including something in the CSS. any help would be appreciated.
Edit: Picture added below for clarification. Lots of whitespace that extends to where the table ends without the y scroll.
Bootstrap applies a margin-bottom of 20px to the ".table" class. If you inspect the table in the console - you will be able to see that styling.
In order to remove this- you will need to over-ride the style rule in your own styling (note that this MUST be after the Bootsrtrap styles are imported).
.table {
margin-bottom: 0;
}

Stop HTML table "shunting" (page-break?) into next page when converted to PDF

I have a HTML page with CSS and I convert it to PDF. My HTML page contains a table which when small renders directly under the header at the top of the page but when the table is big, it is shunted (i.e. page break) down and starts at the 2nd page. It spills over into the 3rd page correctly - but how do i stop this page break on page 1? I've tried adding page-break-inside, page-break-before and page-break-after to the #page and table styles but it doesn't work.
I.e. this is happening:
The desired behaviour is as it is when the table is small, i.e.:
The code is:
<!DOCTYPE html>
<html>
<head>
<style>
#page {
margin: 0.2cm;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-size: 12px;
line-height: 1.25rem;
}
h1 {
line-height: 2rem;
}
img {
display: block;
float: right;
height: 120px;
margin-bottom: 0.25rem;
object-fit: cover;
width: 192px;
}
table {
border-collapse: collapse;
table-layout: fixed;
width: 100%
}
table, td, th {
border: 0.1rem solid black;
}
td {
overflow: hidden;
overflow-wrap: break-word;
padding: 0.2rem;
vertical-align: top;
}
th {
padding: 0.1rem 0.2rem;
font-size: 0.75rem;
text-decoration: underline;
}
tr.compact td {
padding: 0.05rem 0.2rem;
line-height: 1rem;
}
tr.spacer td {
background-color: lightgrey;
height: 0.2rem;
}
</style>
</head>
<title>Shopping Lists</title>
<body>
<img src="{{ url_for('static', filename='logo.png', _external=True)}}">
<h1>CLIENT SHOPPING LIST</h1>
{% set postcode = request['postcode'] %}
<h2>POSTCODE: {{ postcode }}</h2>
<b>REFERENCE #:</b> {{ request['reference_number'] }}
<table>
<tr>
<td colspan="2"><b>NAME:</b> {{ request['client_full_name'] }}</td>
<td colspan="2"><b>CONTACT:</b> {{ request['phone_number'] or '' }}</td>
</tr>
<tr>
<td colspan="2">
<b>ADDRESS</b><br>
{{ request['address_line_1'] }}, {{ postcode }}
</td>
<td colspan="2">
<b>EXTRA INFORMATION</b><br>
{{ request['extra_information'] or '' }}
</td>
</tr>
<tr>
<td colspan="2">
<b>HOUSEHOLD SIZE:</b> {{ request['household_size'] }}<br>
<b>GENDER:</b> {{ request['gender'] }}<br>
<b>NUMBER OF ADULTS:</b> {{ request['number_of_adults'] }}<br>
<b>NUMBER OF CHILDREN:</b> {{ request['number_of_children'] }}<br>
<b>AGE OF CHILDREN:</b> {{ request['age_of_children'] }}
</td>
<td colspan="2">
<b>FEMININE PRODUCTS REQUIRED:</b> {{ request['feminine_products_required'] }}<br>
<b>BABY PRODUCTS REQUIRED:</b> {{ request['baby_products_required'] }}<br>
<b>PET FOOD REQUIRED:</b> {{ request['pet_food_required'] }}<br>
<b>DIETARY REQUIREMENTS:</b> {{ request['dietary_requirements'] }}
</td>
</tr>
<tr class="spacer"><td colspan="4"></td></tr>
<tr>
<th>Item Description</th>
<th>Quantity</th>
<th>Notes</th>
<th>Completed?</th>
</tr>
{% for item in list["items"] %}
{% set quantity = item['quantity'] %}
{% if quantity != "0" %}
<tr class="compact">
<td>{{ item['item_description'] }}</td>
<td>{{ quantity }}</td>
<td>{{ item['notes'] or '' }}</td>
<td></td>
</tr>
{% endif %}
{% endfor %}
<tr class="spacer"><td colspan="4"></td></tr>
<tr>
<td colspan="4">
<b>Warehouse Manager Notes</b><br>
{{ list['notes'] }}
</td>
</tr>
<tr>
<td>
<b>Date Packed</b><br>
</td>
<td colspan="3"></td>
</tr>
<tr>
<td>
<b>Packer Name</b><br>
</td>
<td colspan="3"></td>
</tr>
<tr>
<td>
<b>Packer Signature</b>
</td>
<td colspan="3"></td>
</tr>
</table>
</body>
</html>

how to get elements in separated rows in html table?

Hey i am fetching data from excel file but all the data is returning in only one row box this is my html code
{% block body %}
# i am using bootstrap table class
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">Pensioner name</th>
<th scope="col">cnic</th>
<th scope="col">mobile</th>
<th scope="col">wallet</th>
</tr>
</thead>
<tr>
{% if 'm1' %}
<td><h6 >{{ m1 }}</h6></td>
{% endif %}
{% if 'm2' %}
<td><h6 >{{ m2 }}</h6></td>
{% endif %}
{% if 'm3' %}
<td><h6 >{{ m3 }}</h6></td>
{% endif %}
{% if 'm4' %}
<td><h6 >{{ m4 }}</h6></td>
{% endif %}
</tr>
</table>
{% endblock %}
this is my outputenter image description here
i want data into separate rows boxes now it looks to messy please help
To create a new row you would need to add a new <tr> element for each row.
Here is a working example
table,
tr,
th,
td {
border: solid 1px;
}
<table>
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Job Title</th>
</tr>
</thead>
<tbody>
<tr>
<td>James</td>
<td>Matman</td>
<td>Chief Sandwich Eater</td>
</tr>
<tr>
<td>The</td>
<td>Tick</td>
<td>Crimefighter Sorta</td>
</tr>
</tbody>
</table>
Each <tr> element inside the <tbody> element creates a new row.

HTML table truncate text but fit as much as possible

I find some posts in Stack Overflow but it doesn't work for me. I need some specific help.
This is my board page :
When I type long title post, it looks like this :
As you can see here, it ruins each table cell's width, as well as text not being truncated.\
What I want to do :
If text reaches the end of title field, it should be truncated
Anything should not ruin the table format (width..etc)
Here is my html code (used in django):
{% extends 'chacha_dabang/skeleton/base.html' %}
{% block content %}
<div class="container inner">
<div class="row">
<div class="col-md-8 col-sm-9 center-block text-center">
<header>
<h1> 차차다방 게시판 </h1>
<p> 회원들의 게시글을 볼 수 있는 페이지 입니다.</p>
</header>
</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- /.container -->
<div class="container inner-bottom">
<div class="table-responsive">
<table class="table">
<col width="65%">
<col width="15%">
<col width="13%">
<col width="7%">
<thead>
<tr>
<th>제 목</th>
<th>작성자</th>
<th>작성일</th>
<th>조회수</th>
</tr>
</thead>
<tbody>
{% for post in posts %}
<tr>
<td class="td-title-area"> {{ post.title}} </td>
<td> {{post.author}} </td>
<td> {{post.created_at|date:"SHORT_DATE_FORMAT"}} </td>
<td> 11 </td>
</tr>
{% endfor%}
</tbody>
</table>
</div>
<br>
<br>
{% if is_paginated %}
<div class="pagination text-center" style="position:center;">
<span class="page-links">
{% if page_obj.has_previous %}
previous
{% endif %}
<span class="page-current">
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
</span>
{% if page_obj.has_next %}
next
{% endif %}
</span>
</div>
{% endif %}
</div>
{% endblock %}
Need your helps. Thanks
Edit
Here is what I'm trying to do :
1. I made class named truncate and define css for it :
.truncate {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
And add truncate class to my table :
<tbody>
{% for post in posts %}
<tr>
<td class="td-title-area">
<a href="{{ post.get_absolute_url }}" class="td-title truncate">
{{ post.title}}
</a>
</td>
<td> {{post.author}} </td>
<td> {{post.created_at|date:"SHORT_DATE_FORMAT"}} </td>
<td> 11 </td>
</tr>
{% endfor%}
</tbody>
And result is :
You could try something like this:
.td-title-area {
position: relative;
}
.td-title-area a {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
<table class="table">
<col width="65%">
<col width="15%">
<col width="13%">
<col width="7%">
<thead>
<tr>
<th>제 목</th>
<th>작성자</th>
<th>작성일</th>
<th>조회수</th>
</tr>
</thead>
<tbody>
<tr>
<td class="td-title-area"> sdkjghbdslkjgbshdfjgbsdfjkhgbsdfjkghbsdgsdfhjkgbsdfkjhgbsdfkhjgbsdfkjghbsfdkjhg </td>
<td> author </td>
<td> date </td>
<td> 11 </td>
</tr>
<tr>
<td class="td-title-area"> sdkjg </td>
<td> author </td>
<td> date </td>
<td> 11 </td>
</tr>
</tbody>
</table>