When you look at columns of words online, such as spelling or vocabulary words, I’ve found almost no one programs such columns. Here’s a good example
When you get a long word above or below a short word, it seems to take a bit to figure how to get HTML and CSS to line up columns of words. How do you do it?.
If you have
Thiamin
Niacin
Potassium
Magnesium
Choline
* * B-6
… do you see how the terms in the middle and right don’t line up left to right, yet it’s the same exact code. If you shorten the word magnesium it changes the position of the word in the next cell.
How do you get these terms to line up left in all three columns without complicated programming?
I know you don’t want me to use the TH tag, but I’d like them bold and large without much programming.
CH,
I’m afraid not. CodePen just shows 3 blank blank panes. I shut off ghostery and it made no difference. Can you put it on this forum?
M Hutley,
They wouldn’t be rows as you add to the top or bottom. Consider my list a horizontal slice of the image. The programming should be the same for both.
Wow. I can’t believe all the code needed to do that. I was thinking about this this morning. Would it be simpler using something that uses justify left? Maybe create 3 columns using 3 tds and then tr after tr to create the height and use justify left in each td ?
When I searched td justify html this came up
Working on this I’ve found this difference. Why does the html compiler treat these two so differently when the code is essemtially the same? Look at that, in the first and second tables it “decides” the width of the box by the width of the text. Why would it do that. What practial use is it? To see what I’m saying just copy this code to a .txt file, then change .txt to .html and then drag it to a browser.
Ok. Let’s change my original question to :
Why is there such a big difference in the results in the last code I posted comparing the 2 table way to the 1 table way?
The html in all the examples given to you so far is much less than the html you have used in your 1999 example!
The examples do use css to style the HTML which is the way it should be done. The css is actually quite succinct and does include some suitable defaults for the page which are not actually part of the column code.
Note that the align attribute you are using was deprecated last century and should not be used these days (you can simply use css and set text-align:left on the cells.).
You should not be using tables for layout either as that is semantically incorrect as tables are to be used for tabular data and all you have is a list.
The css columns example seems to do what you want and is only a couple of lines of code at its basic level.
I’m afraid you’ve come to the wrong place if you want us to give you bad advice.
The th tag is for table headers and makes no semantic sense as you have it in your example. CSS doesn’t really care what the element looks like anyway as it can style it to suit in 99% of cases. Forget about the default appearance of an html element as you can easily style it to suit with css.
Html is the structure and css handles the look.
They are not the same!
The first example is two separate tables so there is no correlation between content in separate table cells. Why would there be?
The last example is a table with two rows and is one table so all columns will align naturally. The content in a cell must control the width of the columns because a table is rows and columns, You won’t have unequal cells in a table because that’s simply the way that tables work… Surely that last table is the look you were asking for anyway?
That inconsistency, cells don’t line up as expected, (and other iconsistencies) is probably why CSS was developed.
I wrote the code. Tell me why you don’t like it. I don’ need aesthetics, I’m just trying to get the structure.
Unfortunately, I can’t remeber the css for putting a line around all cells. so I can see if everything is as expected. Border:1px will work but you have to put it in each td. I guess that’s it: td.brdr{border-width=1px}
Please also note that the examples you’re given here has the DOC-type set, which is telling the browser to render in standard mode instead of falling back to quirks mode:
Just to clarify that (in most cases) there is no inconsistency in how table cells behave. Their behavior is defined and understandable.
It’s your understanding and knowledge level that is at fault and you do need to study the elements you use in a bit more detail. See the link that Erik posted as a start as there is a lot to learn.
The default behavior for table cells is to allocate space based on the content in each cell. That’s why your separate tables with only one row and different word lengths are not the same.
If you use multiple rows in the same tables the columns will all align naturally. The width of each column is governed by its content but you can set a width for the columns if you wish using the table-layout fixed algorithm.
That’s just a brief synopsis of table behavior so you should study them in more depth and then you can bend them to your will.
As I said above tables are only to be used for tabular data and using tables just for layout is very bad practice and indeed makes no sense to assistive technologies.
We can only point you in the right direction but you are of course free to do what you like
I see, tables don’t know eachother exist, where with tr the tr function coordinates the spacing in the td-s and th-s under tr.
I’m afaid I still don’t agree with your tabular data pont of view. CSS is supposed to be for aesthetics. Creating a table with css is creating structure with css.
border-width-and border-style in the table function works great.
Yes, CSS is for controlling layout and appearance, and the use of CSS display:table to create columns would be appropriate, if not necessarily the best way to achieve what you want.
What is not appropriate is to use HTML tables, which are specifically for presenting tabular data.
It’s not a ‘point of view’ but a simple statement of fact about the semantics of HTML elements.
You can misuse HTML elements to your hearts desire and they may on the surface appear to look as you want but that doesn’t mean it’s the correct way of doing it.
Html Elements are designed for a specific semantic purpose so that when correctly used the whole document makes logical and semantic sense. This means that purely from looking at the HTML e.g.authors, readers, search engines, assisted devices (such as screen readers ) can all make sense of the document and Produce an accurate document outline.
Css does not impart any structure on HTML elements. Css is creating the look of the element and does not change the semantic use of the element being used even if you make it look like something else.
It’s not clear what you are asking as there is no function in HTML but a ‘p’ element is made up of a start tag and closing tag and should be used for sections of text such as a paragraph.