HTML & CSS Simple Crossword - html

I'm trying to design my own website, and I wanted to do a simple crossword puzzle to demonstrate some things about me. Like, every line is a diferrent word, but then there is the "middle" column that spells out another word. Here is an image of basically of what I want to do:
The words are pre-defined by me.
I would like to know the simplest way to do this using only HTML and CSS. I've thinked of using a table, but to make each line shift according to the word, each line would have to be a different table.
I'm not using an image and then putting it on the site, because I want it so everytime the user hovers each word, it shows it's meaning/description on the right/left.
I'm open to using Bootstrap if it helps in anyway.
Any ideas?

Since when do we use tables for layout? Just add 5 divs with a margin-left applied to them and style the nth-child. That way you could even add animation to it if you like.

I think that a table is actually your best bet and that you just need to add extra <td> tags for each empty square. You can make each square the same width by adding td {width: 40px} to the css.
table {
text-align: center;
}
td {
width: 40px;
height: 40px;
}
.letterData {
border: 2px solid #000;
}
<table>
<tr>
<td></td>
<td></td>
<td class="letterData">O</td>
<td class="letterData">N</td>
<td class="letterData">E</td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td class="letterData">T</td>
<td class="letterData">W</td>
<td class="letterData">O</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td class="letterData">F</td>
<td class="letterData">O</td>
<td class="letterData">U</td>
<td class="letterData">R</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td class="letterData">T</td>
<td class="letterData">H</td>
<td class="letterData">R</td>
<td class="letterData">E</td>
<td class="letterData">E</td>
</tr>
<tr>
<td class="letterData">E</td>
<td class="letterData">I</td>
<td class="letterData">G</td>
<td class="letterData">H</td>
<td class="letterData">T</td>
<td></td>
<td></td>
<td></td>
</tr>
</table>

I'd say the best way would be to first define a container that represents a square:
.square {
position: absolute;
height: 32px;
width: 32px;
}
You can then position each of these thus:
<div id="square-0" class="square" style="top: 32px; left: 32px;">
A
<div>
<div id="square-1" class="square" style="top: 32px; left: 64px;">
B
</div>
<div id="square-2" class="square" style="top: 64px; left: 64px;">
C
</div>
So long as you position them using top and left values that are exact multiples of the respective height and widths of your div, it should all fit together quite well.
Just an idea but that's how I'd probably do it. Give them sequential id's like square-0 and square-1 and it'll be easier to work with if you decide to expand on it programmatically in future.

Related

How to have a fixed interval between two columns?

We have a table as follows:
<table style="margin-top: 10px; float:right;">
<tr>
<td></td>
<td align="right">SubTotal</td>
<td align="right">${subtotal}</td>
</tr>
<tr>
<td></td>
<td align="right">Tax</td>
<td align="right">${tax}</td>
</tr>
<tr>
<td></td>
<td align="right">Total</td>
<td align="right">${total}</td>
</tr>
</table>
The third column should have a fixed interval to the second column no matter how long the value inside it is.
Can anybody give me some suggestion?
There are two ways to go about it:
using padding
using an empty column
It boils down to whether or not it matters if the space is added in between the columns or inside one of them.
padding-right on 2nd column example:
td:nth-child(2) {
padding-right: 30px;
}
padding-left on 3rd column example:
td:nth-child(3) {
padding-left: 30px;
}
empty column example:
td:nth-child(3) {
width: 30px;
}
<table>
<tr>
<td></td>
<td align="right">SubTotal</td>
<td></td>
<td align="right">${subtotal}</td>
</tr>
<tr>
<td></td>
<td align="right">Tax</td>
<td></td>
<td align="right">${tax}</td>
</tr>
<tr>
<td></td>
<td align="right">Total</td>
<td></td>
<td align="right">${total}</td>
</tr>
</table>
IMPORTANT (deprecation notice)
Do NOT use cellpadding.
It has been deprecated in HTML5, along with align, bgcolor, border, cellspacing, frame, rules, summary and width.
Current browser behavior for cellpadding is: disregard if padding has been defined. Which means it will be ignored if the cell element has a defined value for padding anywhere in currently applying CSS.
It is expected to be ignored by all major browsers in the future, regardless of padding value.
If, for any reason, you find yourself needing an obsolete HTML feature to work, you can specify the DOCTYPE attribute accordingly. While it will make the deprecated features work, it might disable more modern features, which were not available in the HTML version you want to use.

How best highlight (red border, outline, etc) a table cell. without taking up extra space

How can I best highlight a cell in a table, without taking up additional space. Just setting the background color is not good enough. (as it has to be a light color for the number/text to be readable).
CSS Outline would be OK if it could have rounded corners, but without them it doesn't have the same look/style as the rest of the document.
The best I have so far is putting a border around an absolute element positioned over the cell. But this requires the extra element, AND it's positioned OVER, not UNDER, so the color needs to have opacity, in case it is over text in adjacent cells.
<style>
td {
vertical-align:top; position:relative; text-align:right;
}
.bordered {
position: absolute;width:calc(100% + 20px)!important;left:-10px;top:-5px;border:6px rgba(255,0,0,0.7)solid;border-radius:8px;width:200%;
}
</style>
<body>
<table style="width: 100%">
<tr>
<td><span class="bordered"> </span>1 </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>12</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><span class="bordered"> </span>123</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td>1234</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><span class="bordered"> </span>123456789</td>
</tr>
</table>
a) Can Outline have rounded corners?
b) Can above be done without the extra element?
c) Can above be positioned Under, rather than Over the cell?
Background:
I have an html app. that produces a 'Picking List' (for operatives to pick the right products for an Order. It has a 'Quantity' field which css highlights yellow when it's greater than ONE (but operatives don't notice it - and just despatch one (which is the usual qty).
css highlights with a background Yellow - if we use Red - it's difficult to read the number (which is in black).
No cross-browser issues as operatives just use Chrome internally.
Just make ALL of the TDs have a 1px transparent border, then on the selected ones set the color.
td {
border: 1px solid transparent;
vertical-align:top;
text-align:right;
}
.bordered {
border-color: red;
border-radius: 4px;
}
<table style="width: 100%">
<tr>
<td class="bordered"> 1 </td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td>12</td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td class="bordered"> 123</td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td>1234</td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td class="bordered"> &nbsp123456789</td>
</tr>
</table>
In relation to Julie's answer, you can actually have the best of both worlds if you also apply a border-radius. For instance:
td {
border: 0px solid transparent;
box-shadow: 0 0 5px red;
border-radius: 10px;
}
The border itself is invisible and takes no space, but the box-shadow will now follow the curve of the would-be border. You can adjust the box shadow params to make the outline hard or fuzzy.
If you can not take up ANY space then try this:
var btn = document.querySelector('#toggle');
btn.addEventListener('click', () => {
document.querySelectorAll('[a]').forEach(
el => {
el.classList.toggle('bordered');
}
);
});
td {
vertical-align:top;
text-align:right;
}
.bordered {
position: relative;
z-index: 1;
}
.bordered::before {
border: 4px solid rgba(255,0,0,.5);
border-radius: 4px;
bottom: -2px;
content: '';
left: -4px;
position: absolute;
right: -4px;
top: -2px;
z-index: -1;
}
<table style="width: 100%">
<tr>
<td a class="bordered"> 1 </td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td>12</td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td a class="bordered"> 123</td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td>1234</td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td a class="bordered"> &nbsp123456789</td>
</tr>
</table>
<button id="toggle">Toggle</button>
I an using the pseudo-element ::before to show the border. Like your example it is position: absolute and then I tie the top, left, right and bottom to the cell.
Click on the toggle button to see the adding and removal of the borders.
UPDATED
Based on your question I changed top, left, right and bottom to negative numbers to avoid overlap
You could use a box shadow as a border.
.bordered {
box-shadow: 0 0 5px red;
}
It's not rounded, but it doesn't look quite as boxy either.

CSS - create table with fixed size and custom column sizes

I have created these CSS classes:
.table-c {
border: 1px solid black;
width:100%;
height: 30px;
table-layout: fixed;
}
.table-c td {
border: 1px solid black;
padding: 10px;
}
And this table:
<table class="table-c">
<tr>
<td>REFERENCE NO.</td>
<td>DESCRIPTION</td>
<td>Invoice DATE</td>
<td>INVOICE AMOUNT</td>
<td>DISCOUNT TAKEN</td>
<td>AMOUNT PAID</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>CHECK DATA</td>
<td>CHECK NO.</td>
<td>PAYEE</td>
<td>DISCOUNT TAKEN</td>
<td>CHECK AMOUNT</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
Table is fixed size as I wanted, but I also need to have different columns have different width. Those columns should not change with and always have it fixed. And also rows height should be fixed.
As in this example:
Here is my try:
http://jsfiddle.net/cbafseq6/
As you can see all columns have same width and all rows same height. If I would try for example set height on specific tr element (like style="height: 20px") all rows would still have same height.
If you want every row to have specific height and every column to have specific width, you can do something like the code below. I used your own code. You can tell me if that helps.
.table-c {
border: 1px solid black;
width:100%;
height: 30px;
table-layout: fixed;
}
.table-c td {
border: 1px solid black;
padding: 10px;
}
<table class="table-c">
<tr>
<td style="width: 10%">REFERENCE NO.</td>
<td style="width: 30%">DESCRIPTION</td>
<td style="width: 10%">Invoice DATE</td>
<td style="width: 10%">INVOICE AMOUNT</td>
<td style="width: 20%">DISCOUNT TAKEN</td>
<td style="width: 20%">AMOUNT PAID</td>
</tr>
<tr style="height: 200px">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
<table class="table-c">
<tr>
<td style="width: 20%">CHECK DATA</td>
<td style="width: 10%">CHECK NO.</td>
<td style="width: 40%">PAYEE</td>
<td style="width: 10%">DISCOUNT TAKEN</td>
<td style="width: 20%">CHECK AMOUNT</td>
</tr>
<tr style="height: 200px">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
Not sure the table element is what you want to go with.
Custom width of cells within columns would be available by using multiple tables (one for each row), perhaps, but a single table cannot have columns change width every row.
Maybe try a div layout.
Regarding the height set on tr - you chose a height too small, so there is no effect, a larger value would make the row larger. Again, because of table display settings this works differently and you should probably look for a different layout option.
Just use 2 tables:
table {
border: solid black;
border-width: 0 1px;
width: 100%;
height: 30px;
table-layout: fixed;
border-spacing: 2px;
margin-top: -2px; /* same value as border-spacing */
}
td {
border: 1px solid black;
padding: 10px;
}
table:first-child {
border-top-width: 1px;
margin-top: 0;
}
table:last-child {
border-bottom-width: 1px;
}
<div>
<table>
<tr>
<td>REFERENCE NO.</td>
<td>DESCRIPTION</td>
<td>Invoice DATE</td>
<td>INVOICE AMOUNT</td>
<td>DISCOUNT TAKEN</td>
<td>AMOUNT PAID</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
<table>
<tr>
<td>CHECK DATA</td>
<td>CHECK NO.</td>
<td>PAYEE</td>
<td>DISCOUNT TAKEN</td>
<td>CHECK AMOUNT</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</div>
Honestly, even though tables are meant to display tabular data, I would go with a div layout here.
You can easily do this with a wrapper and some floated div and then you can do any and all customization you like to any of the "cells". Just my .02

Strange behaviour with border-collapse and colspan

I am trying to make an organisational chart in HTML. The code is fairly simple, but I have some problems with the rendering in Chrome/Safari and Opera.
Here is what the result should look like, as it works in Firefox and IE:
Here is in Chrome and Safari
And here is in Opera:
The problem comes from the border-collapse: collapse property in CSS. If I use the old coding style cellspacing="0" cellpadding="0"it works more or less, but is not valid in HTML5.
I created a jsFiddle to show the problem: http://jsfiddle.net/aGVp4/7/
My HTML:
<table cellspacing="0" cellpadding="0">
<tr>
<td colspan="3"></td>
<td colspan="2" class="case"></td>
<td colspan="3"></td>
</tr>
<tr>
<td colspan="3"></td>
<td colspan="2" class="case"></td>
<td colspan="3"></td>
</tr>
<tr>
<td></td>
<td colspan="3" class="right bottom"></td>
<td colspan="3" class="bottom"></td>
<td></td>
</tr>
<tr> <!-- No colspan here, to make the layout symmetrical -->
<td class="right"></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td class="right"></td>
<td></td>
</tr>
<tr>
<td colspan="2" class="case"></td>
<td colspan="4"></td>
<td colspan="2" class="case"></td>
</tr>
</table>
And my CSS:
.orgchart {
border-spacing: 0;
border-collapse: collapse;
}
td {
width: 3em;
height: 1em;
}
td.case {
border: 1px solid black;
}
td.right {
border-right: 1px solid black;
}
td.bottom {
border-bottom: 1px solid black;
}
td.top {
border-top: 1px solid black;
}
The problems seems to be caused by different interpretations of the collapsing border model in browsers. The border conflict resolution is defined in terms of cells, not slots, and when you use colspan=3, one cell spans 3 slots.
The 2nd cell of the 2nd row has a solid bottom border, and the 2nd cell of the 3rd row has no top border. When borders collapse, solid wins none. But the cells are only partially adjacent, as they span different columns. Browsers hand this differently. Chrome makes the border span all the columns of the upper cell, whereas Firefox makes the border span only one column, the one that the cells share – which is more reasonable, but CSS 2.1 seems to leave the issue open.
I tried playing with border: hidden, which helps on Chrome but causes new problems on Opera.
It seems that there are two options. You could use the HTML attributes, if they do the job. Though declared obsolete and forbidden in HTML5 CR, the same document also requires continued support to them in browsers.
But a cleaner, and perhaps more robust, approach is to avoid the problem by adding more empty cells. This means dividing two 3rd row cells into two cells so that only one of them shares a border with the cell of the 2nd row. This makes the table even more grid-like, but not essentially more complex:
<table class="orgchart">
<tr>
<td colspan="3"></td>
<td colspan="2" class="case"></td>
<td colspan="3"></td>
</tr>
<tr>
<td colspan="3"></td>
<td colspan="2" class="case" ></td>
<td colspan="3"></td>
</tr>
<tr>
<td></td>
<td colspan="2" class="bottom"></td>
<td class="right bottom"></td>
<td class="bottom" ></td>
<td colspan="2" class="bottom" ></td>
<td></td>
</tr>
<tr> <!-- No colspan here, to make the layout symmetrical -->
<td class="right"></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td class="right"></td>
<td></td>
</tr>
<tr>
<td colspan="2" class="case"></td>
<td colspan="4"></td>
<td colspan="2" class="case"></td>
</tr>
</table>
Add a new empty row <tr></tr> under the colspan will fix this problem (not a beautiful solution but works).
I played with your jsfiddle, and found a hack to fix the issue in Chrome and Safari.
Also works on FF and IE, but didn't test on Opera.
Try this (jsfiddle):
td.bottom {
border-top: 1px solid white; // this is the hack
border-bottom: 1px solid black;
}
td.right.bottom {
border-top: none; // fix for IE
}
As this is a hack, it may not work as your chart grows complex, but hope this helps in short-term.

How to vertically and horizontally center a P of text in the page

I want to create a page that justs has a paragraph of text centered in the page vertically and horizonally. Any ideas on how? Thanks
Sure, here is how: http://jsfiddle.net/sl1dr/vAdzu/
If you know the paragraph width/height, you may use CSS with this method. I can only think of tables for dynamic content, maybe the CSS experts will have better options.
<table style="width: 100%; height: 100%; border: 0px; padding: 0px; margin: 0px;">
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td style="width: 30%;"></td>
<td>Test</td>
<td style="width: 30%;"></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</table>
Ajust the widths to your suiting. This is short of using complicated JavaScript.