List movie info in columns that collapse into one column - html

I'm trying to show movie info for a website, but I'm having issues with the CSS and HTML. I want the title (Director:, Cast:, etc) to be in line with the first item in the list, and then have all others follow below. I tried a definition list, but couldn't figure out the css to make it responsive. Now I have a table, but I'm starting to suspect a regular list might be better.
Here is my fiddle which looks how I want it to when the window is wide enough, but gets ruined when shrunk down to mobile (which is when I want the Cast: columns to become one column)
Any help would be super appreciated, I've been playing with this for months.
Here's my html:
<div class="movieinfo">
<table>
<tr class="spaceUnder">
<td class="workheader">Director:</td>
<td>John Carney</td>
</tr>
<tr class="spaceUnder">
<td class="workheader">Writer:</td>
<td>John Carney</td>
</tr>
<tr>
<td class="workheader">Cast:</td>
<td>Keira Knightly</td>
<td class="spacedRight">James Corden</td>
</tr>
<tr>
<td></td>
<td>Mark Ruffalo</td>
<td class="spacedRight">CeeLo Green</td>
</tr>
<tr>
<td></td>
<td>Hailee Steinfeld</td>
<td class="spacedRight">Catherine Keener</td>
</tr>
<td></td>
<td>Adam Levine</td>
</table>
</div>
and my CSS:
.movieinfo {
color: #333333;
font-size: 24px;
line-height: 1.1;
font-weight: 300;
padding: 20px;
background-color: rgba(255,255,255,.7);
-moz-border-radius: 20px;
-webkit-border-radius: 20px;
border-radius: 20px;
margin-bottom: 20px;
}

You are partially misusing the table for layout here by putting the cast names in separate cells. Don't let your design requirements influence your decision on how to markup the data. This includes using appropriate HTML elements such as <th> for header cells:
<div class="movieinfo">
<table>
<tr class="spaceUnder">
<th>Director:</th>
<td>John Carney</td>
</tr>
<tr class="spaceUnder">
<th>Writer:</th>
<td>John Carney</td>
</tr>
<tr>
<th>Cast:</th>
<td>
<ul>
<li>Keira Knightly</li>
<li>James Corden</li>
<li>Mark Ruffalo</li>
<li>CeeLo Green</li>
<li>Hailee Steinfeld</li>
<li>Catherine Keener</li>
<li>Adam Levine</li>
</ul>
</td>
</tr>
</table>
</div>
To format the cast in columns there are two options depending on if you want to order the items primely vertically or horizontally. For vertical ordering use columns:
.movieinfo ul {
-webkit-columns: 3 10em;
-moz-columns: 3 10em;
columns: 3 10em;
}
EDIT: When using both a width and a number form columns, then the number is the maxmium number of columns displayed. The gap between the columns can be set with column-gap.
More complete example: http://jsfiddle.net/owdz2m0m/
Or for horizontal use floats:
.movieinfo ul > li {
float: left;
width: 10em;
}
EDIT: Limiting the number of columns with floats is a bit trickier. You'll need to set the max-width of the surrounding element (in this case the ul) to the "column width * maximum Number of columns". So to limit the columns to 2 set .movieinfo ul { max-width: 20em; }
More complete example: http://jsfiddle.net/tr9e8bmv/
In either case you can use media queries at adjust the widths depending on screen size.

I think, You need #media queries. Something like this:
#media only screen and (max-width: 640px){ your style }
And You can build your HTML width <dl> and <ul>
DEMO
If You change window size on demo, You can see how 2 columns become 1 column. Screen 1, Screen 2

Related

HTML table: Wrap multiple rows to new line

I am using HTML and CSS to display sentences aligned with word-by-word IPA transcriptions:
<table>
<tr class="eng">
<td>This </td>
<td>is</td>
<td>an</td>
<td>example</td>
<td>sentence.</td>
</tr>
<tr class="ipa">
<td>ðɪs</td>
<td>ɪz</td>
<td>ən</td>
<td>ɪɡˈzæmpl̩</td>
<td>ˈsɛntəns</td>
</tr>
</table>
tr.eng {
font-weight: bold;
}
tr.ipa {
font-style: italic;
}
td {
white-space: nowrap;
text-align: center;
}
.eng td:first-child {
text-align: left;
}
.eng td:last-child {
text-align: right;
}
http://jsfiddle.net/2ab9pgmd/
If a sentence is too long for the screen, I would like both rows to wrap to a new line, so that it could look like following hard-coded example:
<table>
<tr class="eng">
<td>This </td>
<td>is</td>
<td>an</td>
<td>example</td>
</tr>
<tr class="ipa">
<td>ðɪs</td>
<td>ɪz</td>
<td>ən</td>
<td>ɪɡˈzæmpl̩</td>
</tr>
</table>
<table>
<tr class="eng">
<td>sentence.</td>
</tr>
<tr class="ipa">
<td>ˈsɛntəns</td>
</tr>
</table>
Is it possible to set up an HTML table to wrap multiple rows to new lines dynamically depending on the screen size, rather than manually defining the line lengths in advance?
I found a similar example of what I would like to do here, but this solution does not keep the columns aligned for tables with more than one row.
If possible, I would rather not use JavaScript so the text can be viewed as an eBook.
I prefer you go with the CSS Grid cause when you use table row for wrapping it wont get wrapped up and wont provide you the desired output . You can add wrapping rules but I don't think it will work.

Ignoring gaps in between table data

I have a table and what I want is to not make the space between the content as big. This is what the page looks like right now:
So this is some of the code for the table (I'm not posting it all because it's repetitive, all the tags are closed at the end too).
I have tried changing the padding and margin and it doesn't work. This is the CSS:
/*styling the table for the add ons*/
table,
tr,
td,
input {
margin: 30px;
padding: 10px;
margin-right: 20px;
margin-left: 45px;
line-height: 1.4em;
font-size: 17px;
}
.pushRight {
position: relative;
left: 10px;
bottom: 75px;
}
<table style="width:100%">
<tr>
<td><label><input type="checkbox" name="example" value="Value"><span><b>Voice over artist</b>   €475</span>
<table>
<tr>
<td class="pushRight">If you require a voice artist for your video project<br>please select this option.</td>
</tr>
</table>
</td>
<td><label><input type="checkbox" name="example" value="Text"><span><b>Creative Concept</b>  €1200</span>
<table>
<tr>
<td class="pushRight">We are bursting with ideas, so if you don't have one of<br>your own please select this option.</td>
</tr>
</table>
</td>
</div></tr>
<tr><div class="secondRow">
<td><label><input type="checkbox" name="example" value="Value"><span><b>Script</b>   €850</span></label>
<table>
<tr>
<td class="pushRight">If you would like us to allocate our scriptwriter to your project<br>please select this option.</td>
</tr>
</table>
</td>
<td><label><input type="checkbox" name="example" value="Text"><span><b>Storyboarding</b>  €875</span>
<table>
<tr>
<td class="pushRight">It is not essential to storyboard every video project, <br>however if you would like to include this process,<br>please select this option.</td>
</tr>
</table>
</td>
</div></tr>
First of all, you have some divs that don't do much in your html(div with class second row), when you use tables, the tr tags define the rows automatically, so you don't have to put a div to say that's my first row etc...
Using a lot of margin, and padding everywhere will make your table look ugly depending on which browser you're using, i tried to reorganize your code and just added this in your css :
td{
padding : 20px
}
table{
margin: 0 auto;
}
All you have to do now is to play with the padding to change the space as you want. you can also change the width of the table if you want a bigger table.
Here's a jsfiddle :
https://jsfiddle.net/rfroq680/2/
I had this recently, you need to use border-spacing in css.
Try this:
table{
border-collapse:separate;
border-spacing:0 6px;
}
You'll get 6px between rows with the above code.
This should help too: https://www.w3schools.com/cssref/pr_border-spacing.asp

Table contents change depending on window size

I've got a simple table
<table>
<thead>
<tr>
<td>Name</td>
<td>Age</td>
<td>Photo</td>
</tr>
</thead>
</tbody>
<tr>
<td>John Doe</td>
<td>Eighteen</td>
<td>Img</td>
</tr>
<tr>
<td>Peter Stevens</td>
<td>Twenty</td>
<td>Img</td>
</tr>
<tr>
<td>Elizabeth Olsen</td>
<td>Twenty Six</td>
<td>Img</td>
</tr>
</tbody>
</table>
I'd like to hide the photos column if, say, width of the window is less than 1000 px. And I'd like the Age to show as a number ("Eighteen" -> "18") if the width is less than 800 px.
How do I do that? (preferably with HTML + CSS only)
I'd like to hide the photos column if, say, width of the window is less than 1000px.
Use a CSS Media query to check the screen size and hide it if the screen width is less than 1000px.
<td class="photo">Img</td>
#media (max-width:1000px) {
.photo {
display: none
}
}
And I'd like the Age to show as a number ("Eighteen" -> "18") if the width is less than 800px.
This also uses a media query, but it requires a CSS Pseudo Element and an HTML Custom Data Attribute as well.
<td class="age" data-age="18">Eighteen</td>
#media(max-width:800px) {
.age {
font-size: 0;
}
.age:before {
content: attr(data-age);
font-size: 12pt; /* Set this to your desired font size */
}
}
Full Demo:
#media(max-width:1000px) {
.photo {
display: none
}
}
#media(max-width:800px) {
.age {
font-size: 0;
}
.age:before {
content: attr(data-age);
font-size: 12pt; /* Set this to your desired font size */
}
}
<table>
<thead>
<tr>
<td>Name</td>
<td class="age" data-age="?">Age</td>
<td class="photo">Photo</td>
</tr>
</thead>
<tbody>
<tr>
<td>John Doe</td>
<td class="age" data-age="18">Eighteen</td>
<td class="photo">Img</td>
</tr>
<tr>
<td>Peter Stevens</td>
<td class="age" data-age="20">Twenty</td>
<td class="photo">Img</td>
</tr>
<tr>
<td>Elizabeth Olsen</td>
<td class="age" data-age="26">Twenty Six</td>
<td class="photo">Img</td>
</tr>
</tbody>
</table>
To hide photos column in window width < 1000px
simply apply media query like that:
#media(max-width : 1000px) {
td:nth-child(3) {
display:none;
}
}
To display age as number in window width < 800px
you'll need to add the age in numbers somewhere in HTML, so the table row may look like that
<tr>
<td>John Doe</td>
<td>
<span class="age-in-text">Eighteen</span>
<span class="age-in-numbers">18</span>
</td>
<td>Img</td>
</tr>
then you set your style / media query simply like:
.age-in-numbers {
display:none;
}
.age-in-text {
display:block;
}
#media(max-width : 800px) {
.age-in-numbers {
display:block;
}
.age-in-text {
display:none;
}
}
You can use a #media query to write CSS that only applies to screens of certain sizes.
Hiding the column is quite easy. You can just hide the nth-child. td:nth-child(3) matches each third cell.
Hiding the text is a bit harder. CSS cannot transform written text to numbers like that, but in your server side script (PHP?) you may be able to add those numbers already. Now, you could add an extra column with the numeric age, and hide one when you show the other, but personally I think it's a neat trick to add the age as an attribute, and use CSS to display the numeric age instead of the textual content.
Use can use attr() to get the attribute of an element. In the snippet below, I 'hide' the textual content by making the font size 0. Then, I show the data-age attribute in the ::before pseudo element.
The advantage of this method is that it requires no significant changes to the HTML. Semantically it's still just a simple table.
#media (max-width: 800px) {
/* Hide the third column */
td:nth-child(3) {
display: none;
}
/* Hide the text in the second column by setting the font-size to 0 */
td:nth-child(2) {
font-size: 0;
}
/* Show the numeric value from the attribute instead. */
td:nth-child(2)::before {
font-size: 17px;
content: attr(data-age);
}
}
<table>
<thead>
<tr>
<td>Name</td>
<td>Age</td>
<td>Photo</td>
</tr>
</thead>
<tbody>
<tr>
<td>John Doe</td>
<td data-age="18">Eighteen</td>
<td>Img</td>
</tr>
<tr>
<td>Peter Stevens</td>
<td data-age="20">Twenty</td>
<td>Img</td>
</tr>
<tr>
<td>Elizabeth Olsen</td>
<td data-age="26">Twenty Six</td>
<td>Img</td>
</tr>
</tbody>
</table>

How do I limit the number of cells on a row in CSS

I'm editing my forum for mobile devices. So, I'm using media queries to format the front page based on device width.
My issue is that all of the categories have this style, which puts the td elements all in a row.
<tr class="windowbg2">
<td class="icon windowbg">
</td>
<td class="info">
</td>
<td class="stats windowbg">
</td>
<td class="lastpost">
</td>
</tr>
I don't want to get into the PHP that creates the rows, and my attempts/searches so far haven't worked how I want.
I want have the icon td and the info td squished onto one row, and under it have the stats and lastpost tds. How would I separate this row into two using CSS alone?
HTML
<table>
<tr class="windowbg2">
<td class="icon_windowbg">
icon windowbg
</td>
<td class="info">
info
</td>
<td class="stats_windowbg">
stats windowbg
</td>
<td class="lastpost">
lastpost
</td>
</tr>
</table>
CSS
table ,td {
border: 1px solid #000;
}
table {
width: 100%;
}
td {
width: 49%;
float: left;
display: block;
}
The border on the table is just so you can see it. You can take that off.
DEMO
http://codepen.io/anon/pen/xbdjoW?editors=110
You'll want to use a grid framework like Twitter's bootstrap or Thoughtbots "Bourbon neat". These allow you to specify how large an area will be with a main container. Then how much an each element will take up in that container.
with bourbon neat you could use
tr {
display:block # you're probably better off using div's though
#include outer-container;
}
ele {
#include span-columns(6);
}
this would effectivily in a 12 column grid put the two side by side in a row if your elements were
<tr>
<td class="ele"></td>
<td class="ele"></td>
</tr>
you can use this logic to make the other ones span the full 12 columns in the next row.
of course this can all be done in regular css with max-widths and more. grids just have done alot of the work for you. bootstrap is even easier to use. i just prefer bourbons more hands-off approach.

Creating tables with different sized cells

I want to make my form to look neat and I want my cells to be different sizes depending on the information in the cell. How do I make a cell width different then the one above it?
OK now i also want to know how to make 1 cell tall and have a lot of small cells to the right of it.
Example:
<html>
<table border="1"><td width="50">some info</td><td width="50">some more info</td>
<tr>
<td width="250">Lots more text and information in this box then the first cell</td><td> other information</td>
I don't want the first cell in the first row to automatically resize to the length of the first cell in the second row.
Example:
|some info|some more info|
|Lots more text and information in this box then the first cell|other information|
or is there at least another way to lay this out that would look clean?
All column in table always have similar width (you can't change it), you can only add one more cell and span some amount of cells in second row.
<html>
<table border="1">
<tr>
<td width="50">some info</td>
<td width="50">some more info</td>
<td></td>
<td></td>
</tr>
<tr>
<td width="250" colspan="3">Lots more text and information in this box then the first cell</td>
<td> other information</td>
Try this -- use DIVs to simulate table rows and columns, and the CSS min-width property to create "cells" that can stretch as needed.
http://jsfiddle.net/HN4YS/1/
html:
<div class="row"><div class="col1">some info</div><div class="col2">some more info</div></div>
<div class="row"><div class="col1">Lots more text and information in this box then the first cell</div><div class="col2">other information</div></div>
css:
.col1, .col2 {
display: inline-block;
min-width: 150px;
border: 1px solid;
padding: 4px;
}
.row {
white-space: nowrap;
}