Display movie details in a responsive column layout that condenses into a single column

I'm having trouble displaying movie information on a website due to CSS and HTML issues. My goal is to align the title (Director:, Cast:, etc) with the first item in the list, and have all subsequent items follow below. I initially tried using a definition list but struggled with making it responsive using CSS. Currently, I am using a table, but I am starting to think a regular list might be more suitable.

Here is my sample code. It looks how I want it to when the window is wide enough, but breaks when viewed on mobile devices (specifically, the Cast: columns should become one column).

Any assistance would be greatly appreciated as I have been working on this for several months now.

Below is 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>  

Furthermore, here is 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;
}

Answer №1

Your table layout could be improved by reevaluating how you are structuring the data, especially when it comes to displaying cast names in separate cells. It's important not to let design preferences dictate how information should be marked up. Consider utilizing appropriate HTML elements like <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>  

If you prefer to display the cast in columns, you have two options based on whether you want a vertical or horizontal arrangement. For vertical alignment, consider using columns:

.movieinfo ul {
    -webkit-columns: 3 10em;
    -moz-columns: 3 10em;
    columns: 3 10em;
}

NOTE: When specifying both a width and number in the columns property, the number represents the maximum columns displayed. Adjust column gap with column-gap.

For a more detailed example, see: http://jsfiddle.net/owdz2m0m/

To utilize floats for horizontal placement:

.movieinfo ul > li  {
    float: left;
    width: 10em;
}

NOTE: Limiting columns with floats requires setting the max-width of the parent element (in this case, the ul) to "column width * max number of columns." To limit to 2 columns, use

.movieinfo ul { max-width: 20em; }

For a comprehensive example, visit: http://jsfiddle.net/tr9e8bmv/

Incorporating media queries allows for responsive adjustments based on screen size in either layout approach.

Answer №2

In my opinion, utilizing @media queries is the way to go. Consider implementing something similar to this:

@media only screen and (max-width: 640px){ your style }

Additionally, you could structure your HTML using <dl> and <ul>

Check out the demo here

If you adjust the window size in the demo, you will notice how the layout changes from 2 columns to 1 column. See Screen 1, Screen 2

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Adding a class to the following DIV and smoothly transitioning the current one out can be achieved using a dynamic number of items in multiple instances

Is there a way to create a scalable CSS slideshow for text divs without using images? Here is the current HTML structure: <div class="mb-panel-container cf"> <div class="mb-panel-section mb-slider"> <div class="mb-panel active" ...

Learn how to retrieve the current input value from a repeating form using Jquery

I have implemented a comment system with a delete option. Each comment has a POST form that posts a comment-id to delete.php. While this works in PHP, I am facing issues with it in jQuery. To delete a comment, the comment id needs to be passed to delete.p ...

Issue with overflow-auto not displaying scroll bar

In my layout, I have a grid parent with two columns. The left child has a height equal to the parent (100vh), while the right child is 1000px tall, which exceeds the parent's height. Here is the HTML structure: <body> <div class="le ...

Determine the exact scroll position needed to reveal the element when scrolling in reverse

I'm looking for a way to make my div disappear when I scroll down and reappear immediately when I start scrolling back up. Currently, it only works when I reach a certain position instead of taking effect right away. I need assistance in calculating t ...

Tips on halting the current animation and modifying styles upon hovering

Currently, I have a basic label featuring a contact number with a blinking animation. However, the animation is only a simple color transition at this time (see code below). I have managed to successfully pause the animation and revert the text back to it ...

Remove the background color from a semi-transparent circular CSS div when it is being dragged

My circular div is being dragged for a drag and drop operation, but there's always a translucent square around it. How can I remove this unwanted effect? body{ background : #BBD1DF; } .dragdemo { width: 170px; height: 170px; line-hei ...

Executing a JavaScript function when an HTML page is loaded within an OBJECT Tag

I have a situation where I am loading an HTML page inside an object tag. Since the iPad does not support iFrames, I decided to use the object tag to load external HTML pages into a container. Everything is working well so far, but now I want to be able t ...

Can using $.ajax to submit a form be considered contradictory?

Currently, I am engaged in developing an MVC application that heavily relies on jQuery and HTML forms. However, I have started to notice a conflict between the two... For instance, I have had to prevent the default form submission to execute my AJAX call ...

In Safari, an animated link does not respond to pointer-events, making it unclickable

Exploring the world of CSS animations, I have created a snippet where elements appear sequentially. Take a look at it first: .wrapper { pointer-events: none; /* disable pointer events until animation completes */ } .text { position: absolute; } ...

Elevation on Tab button from the upper side

On my website, I have a large form where pressing the tab key switches between input fields. The inputs will also jump to the top if we reach the bottom of the form. The issue is that I have a fixed header at the top, covering the first 60px. Is there a w ...

Steps to transfer the content of a label when the onclick event occurs

Seeking advice on how to send the dynamically varying value of a label upon clicking an anchor tag. Can anyone recommend the best approach to passing the label value to a JavaScript function when the anchor is clicked? Here is a sample code snippet: < ...

Initially, the OWL Carousel image is not displaying correctly due to incorrect sizing

I am currently working with OWL Carousel and have implemented a code that displays one image at a time, with the next image sliding in every 15 seconds. The width is set to occupy 100% of the screen and I have configured the JavaScript accordingly so that ...

How can I add divs to an HTML page with a Javascript animated background?

I am currently facing an issue with my JavaScript animated background, consisting of just 3 pictures. I am trying to display some Div elements on it with content inside. Here is the code snippet I have right now: In my CSS file, I have defined styles for ...

Leverage AJAX variables directly within the HTML page

In my application, I have incorporated an Input type="date" field to capture date values from users. However, I need to send the value of the date as "sdate" in the URL used in the action method, as illustrated below. My goal is to post the value of the In ...

Space in the middle of a body and a div

After extensively searching for a solution to the issue plaguing my website, I found that there was always an annoying gap at the top of the page. Despite trying various solutions, none seemed to work. Upon inspecting the website in Firefox, I discovered t ...

Transitioning React Hover Navbar Design

I'm currently revamping a click-to-open navbar into a hover bar for a new project. I have successfully implemented the onMouseEnter and onMouseLeave functions, allowing the navbar to open and close on mouse hover. However, I am facing an issue with ad ...

Avoid page refreshing when retrieving data using PHP and AJAX

In my current program, I am able to add data and insert it into the database. However, I am looking for a way to automatically send this data to another page or browser without refreshing. I have two browsers open, so how can I submit the data to the other ...

Use a JavaScript function on identical IDs

Can someone please help me figure out how to hide multiple divs with the same id using JavaScript? I attempted the following: <script> function filterfunc() { if(document.getElementById('filter_deductible').value == 'id_50'){ ...

What is the best way to eliminate the bottom border of an input field?

Seeking advice on how to eliminate the border-bottom of an input field when typing starts. .car-list-input { font-family: 'Source Sans Pro', sans-serif; border-radius: 3px; font-size: 14px; font-weight: 400 !important; height: 35px; ...

I came across a wlwmanifest.xml file while browsing through the source directory of my website

<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="../preload/wlwmanifest.xml"> I am curious about the purpose of including this code in my website. If I were to delete this file, how would it impact the f ...