HTML div in the cell - stretch, positioning etc - html

Have read a lot and even able to make some of this now, but not together ) Please help.
I need th that contains the caption and the "icon" that consists of one char. And I need caption to be aligned left and icon - right. In the same th. ANd they both must be in the middle of the cell vertically. And icon should be in the center/middle of the div as well. Please help. I cannot align caption and cannot align icon in their div. Dunno why, looks like html/css were invented by aliens, I don't understand that logic and how it was possible to make such a simple thing so stupidly complicated )
Here's the screenshot of what I need
table
{
border-collapse: collapse;
border-spacing: 0;
}
th
{
border: 1px solid #fff;
white-space: nowrap;
background: #000;
color: #fff;
padding: 0.5em;
text-align: center;
vertical-align: middle;
display: table-cell;
}
td
{
border: 1px solid #fff;
white-space: nowrap;
background: #eee;
width: 20em;
padding: 0.5em;
text-align: center;
vertical-align: middle;
}
div.left
{
display: inline-block;
text-align: left;
vertical-align: middle;
border: 1px solid #7f9;
}
div.right
{
text-align: center;
vertical-align: middle;
position: relative;
height: 2em;
border: 1px solid #f79;
display: inline-block;
float: right;
width: 2em;
}
div.reload
{
border: 1px solid #79f;
text-align: center;
vertical-align: middle;
width: 2em;
height: 2em;
position: absolute;
right: 0;
bottom: 0;
display: table;
}
<table>
<tr>
<th>
<div class="left">Title 1</div>
<div class="right">
<div class="reload">⟳</div>
</div>
</th>
<th>
<div class="left">Title 2</div>
<div class="right">
<div class="reload">⟳</div>
</div>
</th>
</tr>
<tr>
<td>
Some data
</td>
<td>
123.45
</td>
</tr>
</table>
Have found an answer (based on your advices, thank you!!!)
That was easy and still dumb:)
table
{
border-collapse: collapse;
border-spacing: 0;
}
th
{
border: 1px solid #fff;
white-space: nowrap;
background: #000;
color: #fff;
text-align: left;
vdrtical-align: middle;
line-height: 2em;
}
td
{
border: 1px solid #fff;
white-space: nowrap;
background: #eee;
width: 20em;
padding: 0.5em;
}
div.left
{
display: inline-block;
text-align: left;
vertical-align: middle;
border: 0px solid #7f9;
display: inline-block;
float: left;
}
div.reload
{
border: 1px solid #999;
text-align: center;
vertical-align: middle;
width: 1.5em;
margin: 0.2em;
line-height: 1.5em;
right: 0;
bottom: 0;
display: inline-block;
float: right;
}
<table>
<tr>
<th>
<div class="left">Title 1</div>
<div class="reload">⟳</div>
</th>
<th>
<div class="left">Title 2</div>
<div class="reload">⟳</div>
</th>
</tr>
<tr>
<td colspan=2>
Some data
</td>
<td colspan=2>
123.45
</td>
</tr>
</table>

Maybe something like this ?
CSS:
.view-table
{
display:table;
width:100%;
}
.view-row
{
display:table-row;
}
.view-row > div
{
display: table-cell;
}
.left
{
text-align:left;
background-color: lightblue;
}
.right
{
text-align:right;
background-color: pink;
}
HTML :
<div class="view-table">
<div class="view-row">
<div class="left">Title</div>
<div class="right">⟳</div>
</div>
</div>

If you want the icon on the right side of the th and the title on the left, you need text-align-last:justify instead of text-align:center in the th.
Please note that you also need another text-align-last on the div.reload, else its text-align will have no effect!
table {
border-collapse: collapse;
border-spacing: 0;
}
th {
border: 1px solid #fff;
white-space: nowrap;
background: #000;
color: #fff;
padding: 0.5em;
text-align: justify;
-moz-text-align-last: justify;
text-align-last: justify;
}
td {
border: 1px solid #fff;
white-space: nowrap;
background: #eee;
width: 20em;
padding: 0.5em;
text-align: center;
}
div.left {
display: inline-block;
vertical-align: middle;
text-align: left;
border: 1px solid #7f9;
}
div.right {
display: inline-block;
border: 1px solid #f79;
display: inline-block;
}
div.reload {
border: 1px solid #79f;
width: 2em;
line-height: 2em;
text-align: center;
-moz-text-align-last: center;
text-align-last: center;
}
<table>
<tr>
<th>
<div class="left">Title 1</div>
<div class="right">
<div class="reload">⟳</div>
</div>
</th>
<th>
<div class="left">Title 2</div>
<div class="right">
<div class="reload">⟳</div>
</div>
</th>
</tr>
<tr>
<td>
Some data
</td>
<td>
123.45
</td>
</tr>
</table>
Or, this fiddle.

Related

Html drawing horizontal and vertical lines connecting circle nodes

I would like to draw the following in my web page:
where the three buttons are submit buttons.
I managed to do most but having a problem drawing the vertical lines.
here is my code:
th,
td {
padding: 10px;
}
table.center {
margin-left: auto;
margin-right: auto;
border-collapse: separate;
border-spacing: 50px 0;
}
span {
border-bottom: 2px solid gray;
border-right: 2px solid gray;
padding: 2px;
display: inline-block;
width: 100%;
}
.button {
width: 100%;
padding: 10px;
font: bold;
font-size: 20px;
border: none;
}
.button_blue {
background-color: LightSkyBlue;
}
.button_red {
background-color: OrangeRed;
}
.button_yellow {
background-color: yellow;
}
.boxed {
width: 600px;
border: 3px solid green;
padding: 5px;
margin: 5px;
margin-left: auto;
margin-right: auto;
}
.circle {
width: 40px;
height: 40px;
line-height: 40px;
border-radius: 50%;
border: none;
font-size: 30px;
font: bold;
text-align: center;
display: inline-block;
;
}
<div style="text-align:center">
<u style="color:Red;">
<h1 style="color:DodgerBlue;font-size:3em;">
Hashi
</h1>
</u>
<form action="" method="post" novalidate>
{{ form.hidden_tag() }}
<p></p>
<div style="text-align:center">
<p></p>
<table class="center">
<tr>
<td></td>
<td style="border-bottom:4px solid black"></td>
</tr>
<tr>
<td style="text-align:center"><text style="color:DodgerBlue;font-size: 2em;"> Build bridges </text></td>
<td>
<span> {{ form.create(class_="button button_blue") }} </span>
</td>
</tr>
<tr>
<td style="text-decoration: line-through; text-decoration-thickness:5px;">
<div class="circle" style="background-color:yellow;">
3
</div>
<div class="circle" style="background-color:OrangeRed;">
2
</div>
<div class="circle" style="background-color:lightgreen;">
5
</div>
</td>
<td>
<span>{{ form.load(class_="button button_red") }}</span>
</td>
</tr>
<tr>
<td>
<div class="circle" style="background-color:blue;color:yellow;">
4
</div>
</td>
<td>
<span>{{ form.solve(class_="button button_yellow") }}</span>
</td>
</tr>
</table>
</div>
</form>
</div>
You shouldn't use tables to do design, but if that's what you want, then I will come up with a solution for it.
Don't use inline styles. Refactor them to classes, so the HTML is readable.
Set position: relative on all TDs.
Place each element in a TD of its own.
Make the circular buttons absolute to position them on top of bottom right corner.
Use colspan to place the elements relative to each other.
Use border to draw the lines.
/** UNCOMMENT TO REVEAL THE ENTIRE STRUCTURE OF THE TABLE **/
/*td {
border: 2px solid rgba(0, 0, 0, 0.3) !important;
}*/
body {
font-family: Helvetica;
}
h1 {
color: DodgerBlue;
font-size: 4em;
text-decoration: underline;
text-decoration-color: red;
text-decoration-thickness: 1px;
margin: 2rem auto 1rem;
}
table {
border-collapse: collapse;
margin-left: auto;
margin-right: 1rem;
}
td.subtitle {
color: DodgerBlue;
font-size: 3em;
padding: 1rem;
}
td {
position: relative;
text-align: center;
border: 4px none black;
}
td.right-line {
border-right-style: solid;
}
td.bottom-line {
border-bottom-style: solid;
}
td.double-stroke {
border-width: 4px;
border-style: solid;
}
button {
display: flex;
justify-content: center;
align-items: center;
}
button.big {
margin: 1rem;
padding: 1rem 2rem;
font-size: 1.3rem;
width: calc(100% - 2rem);
box-sizing: border-box;
}
button.circle {
position: absolute;
right: 0px;
bottom: 0px;
transform: translate(50%, 50%);
width: 40px;
height: 40px;
line-height: 40px;
border-radius: 50%;
border: none;
font-size: 1.1rem;
font-weight: bold;
}
.blue.big {
background-color: LightSkyBlue;
}
.red {
background-color: OrangeRed;
}
.yellow {
background-color: yellow;
}
.lightgreen.circle {
background-color: lightgreen;
}
.blue.circle {
background-color: blue;
color:yellow;
}
<form action="" method="post" novalidate>
<table>
<tr>
<td colspan="4"></td>
<td class="bottom-line"><h1>Hashi</h1></td>
</tr>
<tr>
<td> </td>
<td colspan="3" class="subtitle right-line">Build bridges</td>
<td><button class="blue big">Create a Puzzle</button></td>
</tr>
<tr>
<td><button class="yellow circle">3</button></td>
<td class="bottom-line"><button class="red circle">2</button></td>
<td class="bottom-line right-line" colspan="2"><button class="lightgreen circle">5</button></td>
<td><button class="red big">Upload External</button></td>
</tr>
<tr>
<td class="right-line double-stroke"><button class="blue circle">4</button></td>
<td colspan="3"> </td>
<td><button class="yellow big">Run Internal</button></td>
</tr>
</table>
</form>

What would be the most efficient way of going about making my one line of fields into two rows 4 fields in each

Basically right now I have everything in a straight line, I know it isn't responsive, not part of the task. I want to change it so I have 'clock hours, incentive, off clock, and regular hours' on the top row & overtime hrs, personal, vacation, and holiday' directly beneath it. And then have total hours off to the side near the signature area. I have some thoughts on how to do it but I feel like it could be done in a simple way so I don't know exactly the best way of tackling it.
/* *{
margin: 0;
padding: 0;
} */
/* #page {
size: 8.5in 11in;
} */
h2 {
text-align: center;
}
.signandauth {
/*div for authorized, signature & their textboxes*/
position: absolute;
top: 0;
right: 0;
margin-right: 20px;
margin-top: 20px;
}
.dateSection {
/*div for date script*/
position: absolute;
top: 0;
left: 0;
margin-left: 20px;
margin-bottom: 20px;
margin-top: 65px;
}
.section1 {
padding: 30px 0;
border: 4px solid black;
/* margin-right: 20px; */
}
.section2 {
padding: 70px 0;
border: 4px solid black;
}
label {
border: 1px solid black;
padding: 0.2em;
margin: 0.2em;
display: inline;
}
p {
margin: 0.3em;
padding: 0.3em;
font-weight: bold;
display: inline;
text-align: center;
}
#date {
float: left;
}
#authorized {
/*text box*/
width: 170px;
height: 30px;
float: right;
}
#authorizeP {
/*the label*/
float: right;
}
#signature {
width: 170px;
height: 30px;
float: right;
}
#signP {
float: right;
}
table,
th {
border: 1px solid black;
border-collapse: collapse;
padding: 5px;
float: right;
}
td {
width: 90px;
border: 1px solid black;
padding: 5px;
}
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="styles.css">
<body>
<title>Time Card</title>
<div class="section1">
<h2>Time Card: AWS</h2>
<div class="dateSection">
<p id="date"></p>
<script>
var date = new Date();
document.getElementById("date").innerHTML = date.toDateString();
</script>
</div>
<br>
<br>
<br>
<p>Clock Hours</p>
<label id="clockHours">0.00</label>
<p>Incentive</p>
<label id="Incentive">0.00</label>
<p>Off Clock</p>
<label id="offClock">0.00</label>
<p>Regular Hours</p>
<label id="regularHours">0.00</label>
<p>Overtime Hours</p>
<label id="overtimeHours">0.00</label>
<p>Total Hours</p>
<label id="totalHours">0.00</label>
<p>Personal</p>
<label id="personal">0.00</label>
<p>Vacation</p>
<label id="vacation">0.00</label>
<p>Holiday</p>
<label id="holiday">0.00</label>
<div class="signandauth">
<p id="authorizeP">Authorized</p>
<br>
<br>
<label id="authorized"></label>
<br>
<br>
<br>
<p id="signP">Employee Signature</p>
<br>
<label id="signature"></label>
</div>
</div>
<br>
<!-- --------------------------------------------------------------------------------------------- -->
<div class="section2">
<table>
<tr>
<td>000</td>
<td>000</td>
<td>000</td>
<td>000</td>
<td>000</td>
<td>000</td>
<td>000</td>
</tr>
</table>
</div>
</body>
</html>
How about putting them in a 2x4 table?
<br>
will break onto a new line, that should do what you're hoping.
<table >
<tr>
<th>Clock Hours</th>
<th>Incentive</th>
<th>Off Clock</th>
<th>Regular Hours</th>
</tr>
<tr>
</tr>
<tr>
<td style="border: 1px solid black; width: 90px; padding: 5px"><label id="clockHours">0.00</label></td>
<td style="border: 1px solid black; width: 90px; padding: 5px"><label id="Incentive">0.00</label></td>
<td style="border: 1px solid black; width: 90px; padding: 5px"><label id="offClock">0.00</label></td>
<td style="border: 1px solid black; width: 90px; padding: 5px"><label id="regularHours">0.00</label>
</tr>
</table>
<br>
<table >
<tr>
<th>Overtime Hours</th>
<th>Personal</th>
<th>Vacation</th>
<th>Holiday</th>
</tr>
<tr>
</tr>
<tr>
<td style="border: 1px solid black; width: 90px; padding: 5px"><label id="clockHours">0.00</label></td>
<td style="border: 1px solid black; width: 90px; padding: 5px"><label id="Incentive">0.00</label></td>
<td style="border: 1px solid black; width: 90px; padding: 5px"><label id="offClock">0.00</label></td>
<td style="border: 1px solid black; width: 90px; padding: 5px"><label id="regularHours">0.00</label>
</tr>
</table>

CSS Navigation Vertical Align

I am unaware of the best practice to get my desired result. I have used tables here which have got me close to what I want.
The result doesn't have vertically centered text and I cannot figure out how. Tried using UL to get this but had no luck:
#hotspotbg table {
margin-top: 1px;
}
#hotspotbg table tr td {
border-right: 1px solid #ccc;
border-left: 1px solid #ccc;
}
#hotspotbg table tr td a {
text-align: center;
text-decoration: none;
display: block;
font-family: Tahoma, Geneva, sans-serif;
color: #fff;
height: 51px;
}
#hotspotbg table tr td a:hover {
background: #FFF;
color: #000;
}
<table width="900" height="51px" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="25%" height="51" valign="middle">Home
</td>
<td width="25%">Products
</td>
<td width="25%">Reviews
</td>
<td width="25%">Contact
</td>
</tr>
</table>
Setting the line-height of the child (a element in your case) to the height of the parent, will vertically align the text of the a element. See below for more information.
.wrapper {
height: 70px;
width: 100%;
background: red;
overflow: hidden;
}
.wrapper a {
/*NOT AFFECTING THE VERTICAL ALIGN*/
display: block;
float: left;
height: 70px;
width: 50%;
color: #fff;
text-align: center;
/*AFFECTING VERTICAL ALIGN*/
line-height: 70px;
}
<div class="wrapper">
test
nice
</div>

How to fit CSS buttons into table cells?

I would like to put CSS buttons into several tables. Ideally, each button should fill the corresponding table cell. This presents a problem because if I hard-code the button width in CSS, I would need a separate class for each table dimension.
Is there a way to have the buttons fit into the table cells?
HTML:
<center>
<table border="1" width="90%" class="buttons">
<tr>
<td width="25%">Link1 goes here</td>
<td width="25%">Link2<br>goes<br>here</td>
<td width="25%">Link3<br>goes<br>here</td>
<td width="25%">Link4<br>goes<br>here</td>
</tr>
</table>
<p>
<table border="1" width="90%" class="buttons">
<tr>
<td width="20%">Link1 goes here</td>
<td width="20%">Link2<br>goes<br>here</td>
<td width="20%">Link3<br>goes<br>here</td>
<td width="20%">Link4<br>goes<br>here</td>
<td width="20%">Link5<br>goes<br>here</td>
</table>
</center>
CSS:
.buttons
{
overflow:auto;
text-align: center;
font-size: 1.0em;
font-weight: bold;
line-height: 200%;
}
.buttons a
{
display: inline-block;
width: 18em;
height: 6em;
margin-bottom: 0.5em;
padding-top: .6em;
padding-bottom: .6em;
color: #fff;
background-color: #aaabbb;
border-radius: 5px;
border: solid #cccccc 1px;
box-shadow: 2px 2px 1px #888888;
clear:right;
float:right;
}
.buttons a:active
{
box-shadow: 1px 1px 0px #888888;
}
Play with the code:
http://codepen.io/anon/pen/bIEtC
You should try to set height and width 100%. Like this:
.buttons a
{
display: inline-block;
width: 100%; /* set to 100% */
height: 100%; /* set to 100% */
margin-bottom: 0.5em;
padding-top: .6em;
padding-bottom: .6em;
color: #fff;
background-color: #aaabbb;
border-radius: 5px;
border: solid #cccccc 1px;
box-shadow: 2px 2px 1px #888888;
clear:right;
float:right;
}
Try not to hard code CSS into the HTML... it leads to a mess of trouble!
Taking the inline styling out of the html seems to fix most problems. Then, just like #ArmanVirdi said, add the width and the height of the link to be 100%.
The <center> tags don't seem to be doing anything, so those are removed in the below HTML, as well as an unclosed <p> tag.
HTML
<table class="buttons width-25">
<tr>
<td>Link1 goes here
</td>
<td>Link2<br>goes<br>here
</td>
<td>Link3<br>goes<br>here
</td>
<td>Link4<br>goes<br>here
</td>
</tr>
</table>
<table class="buttons width-20">
<tr>
<td>Link1 goes here
</td>
<td>Link2<br>goes<br>here
</td>
<td>Link3<br>goes<br>here
</td>
<td>Link4<br>goes<br>here
</td>
<td>Link5<br>goes<br>here
</td>
</table>
CSS
table {
width: 100%;
}
.width-20 td {
width: 20%;
}
.width-25 td {
width: 25%;
}
.buttons {
text-align: center;
font-size: 1.0em;
font-weight: bold;
line-height: 200%;
}
.buttons a {
display: inline-block;
height: 100%;
width: 100%;
margin-bottom: 0.5em;
padding-top: .6em;
padding-bottom: .6em;
color: #fff;
background-color: #aaabbb;
border-radius: 5px;
border: solid #cccccc 1px;
box-shadow: 2px 2px 1px #888888;
}
.buttons a:active {
box-shadow: 1px 1px 0px #888888;
}
JSFiddle for reference
Add to .buttons:
width:0;
Resut:

Aligning Tables Within a Div Table

I have replaced a table containing four tables (in a grid) with a div-table containing the four tables as cells. Two things that I absolutely can't seem to get to work are:
How do I get rid of the table border of the div tag using display: table?
The bottom left table insists on lining up with the far left edge of the cell and I want it to line up with the far right edge of the cell. Even relative positioning is having no impact on this one.
Here is the CSS:
<style type="text/css">
.Dashboard {
display: table;
border-collapse: collapse;
border-width: 0px;
}
.row1 {
display:table-row;
}
.row2 {
display:table-row;
height: 200px;
}
.cell1 {
display: table-cell;
padding: 2px;
border: 1px solid black;
}
.cell2 {
display: table-cell;
padding: 2px;
border: 1px solid black;
}
.cell3 {
display: table-cell;
padding: 2px;
border: 1px solid black;
text-align: right;
vertical-align: top;
}
.cell4 {
display: table-cell;
padding: 2px;
border: 1px solid black;
}
table.inner {
border-collapse: collapse;
border: 2px solid black;
text-align: center;
padding: 2px;
}
td {
border-collapse: collapse;
border: 2px solid black;
text-align: center;
padding: 2px;
}
td.image {
padding: 0;
margin: 0;
}
</style>
And the table layout looks like this:
<div runat="server" id="Dashboard" class="Dashboard">
<div class="row1">
<div class="cell1">
<table class="inner" id="t1">
<tr>...</tr>
...
<tr>...</tr>
</table>
</div>
<div class="cell2">
<table class="inner" id="t2">
<tr>...</tr>
...
<tr>...</tr>
</table>
</div>
</div>
<div class="row2">
<div class="cell3">
<table class="inner" id="t3">
<tr>...</tr>
...
<tr>...</tr>
</table>
</div>
<div class="cell4">
<table class="inner" id="t4">
<tr>...</tr>
...
<tr>...</tr>
</table>
</div>
</div>
</div>
Any advice is appreciated.
To get rid of the border use
border: none;
With the positioning, find the bottom left table id and use
float: right;
But your best option is to get rid of tables anyways. All of this can just as easily be done with straight css.