Arrange divs in a stack fashion

Currently, I have a table-styled three-column set of divs.

I would like these columns to stack vertically on mobile devices.

I think this can be achieved using the float method, but the titles and descriptions for each column are in separate rows (divs), so I am unsure how to accomplish this?

Intension

Fiddle https://jsfiddle.net/8tv35jLL/

HTML

<p><img alt="Service-Desk-Team-heads-mini-min.png" height="212" src="/sites/default/files/pictures/Service-Desk-Team-heads-mini-min.png" title="The 2016 Workbooks Support Team" width="878" /></p>

<h4 style="text-align: left;">Please use the search tool above,&nbsp;the left-side menu or the links below to browse through our Knowledge Base.</h4>

<div class="rTable">
<div class="rTableBody">
<div class="rTableRow">
<div class="rTableCell">
<h4>New to Workbooks?</h4>
</div>

<div class="rTableCell">
<h4>Training videos</h4>
</div>

<div class="rTableCell">
<h4>System Admin</h4>
</div>
</div>

<div class="rTableRow">
<div class="rTableCell" style="border-right: 1px dashed grey;">Using Workbooks for the first time?</div>

<div class="rTableCell" style="border-right: 1px dashed grey;">Watch our short training videos to find out how to use Workbooks:</div>

<div class="rTableCell">System Administrator? Familiarise yourself with the following:</div>
</div>

<div class="rTableRow">
<div class="rTableCell" style="border-right: 1px dashed grey;">
<ul>
    <li class="nowrap"><a href="/help/introduction">Introduction to Workbooks</a></li>
    <li><a href="/help/navigation_and_editing">Workbooks Desktop</a></li>
    <li><a href="/help/importing">Importing Data</a></li>
</ul>
</div>

<div class="rTableCell" style="border-right: 1px dashed grey;">
<ul>
    <li class="nowrap"><a href="/help/training/videos#getting_started_with_workbooks_video">Getting started with Workbooks</a></li>
    <li class="nowrap"><a href="/help/training/videos#introduction_to_workbooks_outlook_connector_video">Workbooks Outlook Connector</a></li>
    <li class="nowrap"><a href="/help/importing">Introduction to Reporting</a></li>
</ul>
</div>

<div class="rTableCell">
<ul>
    <li><a href="/help/users/setting_up">Create new Users</a></li>
    <li class="nowrap"><a href="/help/own_organisation">Configure your Organisation</a></li>
    <li class="nowrap"><a href="/help/customising">Add Custom Fields</a></li>
</ul>
</div>
</div>
</div>
</div>

CSS

.rTable {
display: table;
width: 100%; 
} 

.content-section h4 {
text-align: center;
font-weight: 400;
margin: 0 0 0 0;
}

.content-section img {
margin-bottom: 0;
}

li.nowrap {
white-space: nowrap;
} 

.rTableRow {
display: table-row;
}

.rTableHeading {
display: table-header-group;
background-color: #ddd;
}

 .rTableCell, .rTableHead {
display: table-cell;
padding: 3px 10px;
} 

.rTableHeading {
display: table-header-group;
background-color: #ddd;
font-weight: bold;
} 

.rTableFoot {
display: table-footer-group;
font-weight: bold;
background-color: #ddd;
} 

.rTableBody {
display: table-row-group;
} 

Answer №1

Check out the example

I had to specify specific widths for the cells in order to ensure they were properly sized. Feel free to delete rows and edit as needed to achieve a similar look.
Here is the CSS I used:

width: 250px

Answer №2

Implementing flexbox and media queries:

  • The initial layout is set in a row direction using flexbox, as shown on line 15.
  • You can structure the 3 columns with minimal elements, avoiding the need for a div for each one. Define the layout visually using margins, padding, and borders.
  • Utilize media queries to switch the layout when necessary. For instance, if the screen width is 600px or less, the flexbox properties change to display as a column (refer to line 25).

To observe how flexbox behaves, view the Snippet in Full Page mode and resize the window.

SNIPPET

<!doctype html>
<html>

<head>
  <meta charset="utf-8">
  <title></title>
  <style>
    h4 {
      text-align: center;
      font-size: 2em;
    }
    p {
      font-size: 16px;
      margin: 0 10px 15px;
    }
    .flex {
      display: flex;
      justify-content: space-around;
      width: 100vw;
    }
    section {
      width: 30%;
      border-right: 1px dashed black;
      border-left: 1px dashed black;
    }
    @media only screen and (max-width: 600px) {
      .flex {
        flex-direction: column;
        flex-wrap: nowrap;
        align-items: center;
      }
      section {
        width: 100%;
      }
    }
  </style>
</head>

<body>
  <main>
    <figure class="img">
      <img alt="Service-Desk-Team-heads-mini-min.png" height="212" src="http://placehold.it/878x212/ace/001?text=The+2016+Workbooks+Support+Team" title="The 2016 Workbooks Support Team" width="100%" />
    </figure>
    <p>Please use the search tool above,&nbsp;the left-side menu or the links below to browse through our Knowledge Base.</p>
    <div class='flex'>
      <section>
        <h4>Title 1</h4>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio.</p>
        <ul>
          <li>Lorem</li>
          <li>ipsum</li>
          <li>dolor</li>
        </ul>
      </section>
      <section>
        <h4>Title 2</h4>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
        <ul>
          <li>Lorem</li>
          <li>ipsum</li>
          <li>dolor</li>
        </ul>
      </section>
      <section>
        <h4>Title 3</h4>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
        <ul>
          <li>Lorem</li>
          <li>ipsum</li>
          <li>dolor</li>
        </ul>

      </section>
    </div>
  </main>
</body>

</html>

Answer №3

Your implementation of div doesn't seem to be achieving the desired result. Check out the code snippet below:

.container{
  padding:0;
  padding:0;
}
.box{
  margin:0;
  padding:0 .5em 0;
  width:30%;
  float:left;  
}
.box h3{
  margin:0;
  padding:0;  
}
.box div{
    border-right:2px dotted #ccc;
    min-height:200px
}

@media(max-width:598px){
  .box{
    width:100%;
    
  }
  .box div{
    border-bottom:2px dotted #ccc;
    min-height:0px;
 }
<div class="container">
  <div class="box">
    <h3>New to Workbooks?</h3>
    <div>
        <p>Using Workbooks for the first time?</p>
    </div>
  </div>
  <div class="box">
    <h3>Training videos</h3>
    <div>
     <p>Watch our short training videos to find out how to use Workbooks:</p>
      </div>
  </div>
  <div class="box">
    <h3>System Admin</h3>
    <div>
      <p> System Administrator? Familiarise yourself with the following:</p></div>
  </div>
</div>

Test the responsiveness by changing the browser size.

Answer №4

If you want to create a responsive layout that adapts to different screen sizes, you can achieve this using CSS media queries. The concept is to have a standard design for devices with smaller screens that do not support CSS3 (resulting in vertical stacking), and a different design for larger screens that do support CSS3 (allowing for horizontal stacking). This approach is commonly used by many websites to ensure a consistent user experience across all devices:

Here's how it works: CSS

.container {
    width:1200px;
    margin: 0 auto;
}
.leftDiv {
    background-color:blue;
    width: 400px;
    height:200px;
}
.rightDiv {
    background-color:green;
    width: 400px;
    height:200px;
}
.centreDiv {
    width: 400px;
    height:200px;
    background-color: yellow;
}

@media only screen and (min-width:883px) {
    .leftDiv {
        float:left;
    }
    .centreDiv {
        float:left;
    }
    .rightDiv {
        float:right;
    }
}

And the HTML:

<div class="container">
<div class="leftDiv">Left</div>
<div class="centreDiv">Centre</div>
<div class="rightDiv">Right</div></div>

Answer №5

To achieve this layout, consider utilizing Bootstrap. Bootstrap offers a convenient way to style your webpage dynamically using a row/column structure. Visit the Bootstrap site for further details. It is recommended to opt for a row layout that seamlessly adjusts on mobile screens. Refer to this fiddle for a practical example.

<div class="row">
  <div class="col-md-4">
    <h2>
New to workbooks?
</h2>
    <br />
    <p>
      Are you new to using workbooks?
    </p>
    <ul>
      <li>link 1</li>
      <li>link 3</li>
      <li>link 2</li>
    </ul>

  </div>
  <div class="col-md-4">
    <h2>
System Admin
</h2>
    <br />
    <p>
      Get acquainted with system admin tasks
    </p>
    <ul>
      <li>link 1</li>
      <li>link 3</li>
      <li>link 2</li>
    </ul>
  </div>
  <div class="col-md-4">
    <h2>Training videos</h2>
    <br />
    <p>Explore our training video library</p>
    <ul>
      <li>link 1</li>
      <li>link 3</li>
      <li>link 2</li>
    </ul>
  </div>
</div>

Answer №6

This approach may not be the best, but it should work for you.

HTML

<p><img alt="Service-Desk-Team-heads-mini-min.png" height="212" src="/sites/default/files/pictures/Service-Desk-Team-heads-mini-min.png" title="The 2016 Workbooks Support Team" width="878" /></p>

<h4 style="text-align: left;">Please use the search tool above,&nbsp;the left-side menu or the links below to 
<div class="rTableRow">
<div class="cell">
<h4>New to Workbooks?</h4>
<div style="border-right: 1px dashed grey;">Watch our short training videos to find out how to use Workbooks:</div>
<ul>
    <li class="nowrap"><a href="/help/introduction">Introduction to Workbooks</a></li>
    <li><a href="/help/navigation_and_editing">Workbooks Desktop</a></li>
    <li><a href="/help/importing">Importing Data</a></li>
</ul>
</div>

<div class="cell">
<h4>Training videos</h4>
<div style="border-right: 1px dashed grey;">Using Workbooks for the first time?</div>
<ul>
    <li class="nowrap"><a href="/help/training/videos#getting_started_with_workbooks_video">Getting started with Workbooks</a></li>
    <li class="nowrap"><a href="/help/training/videos#introduction_to_workbooks_outlook_connector_video">Workbooks Outlook Connector</a></li>
    <li class="nowrap"><a href="/help/importing">Introduction to Reporting</a></li>
</ul>
</div>

<div class="cell">
<h4>System Admin</h4>
<div>System Administrator? Familiarise yourself with the following:</div>
<ul>
    <li><a href="/help/users/setting_up">Create new Users</a></li>
    <li class="nowrap"><a href="/help/own_organisation">Configure your Organisation</a></li>
    <li class="nowrap"><a href="/help/customising">Add Custom Fields</a></li>
</ul>
</div>
</div>

CSS

.rTable {
    display: table;
    width: 100%; 
} 

.content-section h4 {
    text-align: center;
    font-weight: 400;
    margin: 0 0 0 0;
}

.content-section img {
    margin-bottom: 0;
}

li.nowrap {
    white-space: nowrap;
} 

.cell {
    float:left;
    min-width:300px;
    width:30%;
    padding: 3px 10px;
    height:200px;
} 

No need to make divs act like tables. Use float to show them side by side and set a minimum width to ensure they stack vertically when needed. Including a height value helps prevent overlap issues. Hopefully, this solution works for you!

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

Substitute the information in the table with new data

I am working with an HTML table that has 5 columns, one of which contains dates. I need to convert the date format only if the data is not empty. To achieve this, I am utilizing moment.js for date formatting. While the date format conversion works perfect ...

Setting size using percentages in Semantic-UILet's explore how to define the size

Since discovering semantic-ui a few days ago, I've been impressed and have decided to switch my app from Bootstrap 3 to semantic-ui. I could use some assistance here. I'm attempting to split the body of the page into two parts. I would like the ...

switching the content of an element using Javascript

I'd like to switch between two icons when clicking on .switch and apply the style of .nightTextNight to .nightText, my JavaScript code is working well everywhere except here. Is there a simpler way to achieve this? I currently have to create two clas ...

Generating numerous variables simultaneously is a feature of SASS

Is it possible to utilize a SASS map in order to generate individual variables for each key-value pair? For instance, I aim to achieve the following: $heading: ( 1: 5rem, 2: 4.5rem, 3: 4rem, 4: 3.5rem, 5: 3rem, 6: ...

Tips for creating a navigation system that combines both horizontal and vertical bars

Is there a way for me to have both horizontal and vertical navigation bars on my website? I am new to design and struggling to understand why my CSS isn't working properly when applied to multiple links. <body> <div class="horizontallinks" ...

PHTML file IIS handler

I was surprised by the lack of online results when searching for a solution to my issue. In my local PHP project, I am encountering problems with PHTML files not being parsed correctly by IIS. The 'phtml' type is not included in the module mappin ...

When the div element reaches the top of the page, it sticks to the top and is only displayed when the user

In the center of a full-screen hero section, there is a form. When it reaches the top, its position becomes fixed and additional classes are added through a script - such as shrinking its height and adding a background. What I aim to achieve is for the fo ...

"Fixing the position of a div on the Samsung Galaxy S8 navigation bar to

Here is the HTML code I am working with: <div class="app-bar"> <a href="#'>icon</a> <a href="#'>icon</a> <a href="#'>icon</a> <a href="#'>icon</a> </div>' ...

Inheriting the viewBox attribute with SvgIcon

I have a collection of unique custom SVGs, each with its own distinct viewBox. First Custom SVG <svg viewBox="-4 -4 24 24"><path something/></svg> Second Custom SVG <svg viewBox="-5 -7 24 24"><path something ...

Adding turbolinks to an HTML document can be achieved without the need for a

Recently delving into the world of turbolinks, I discovered that it can be employed independently without relying on a client-side javascript framework. Eager to test this out, I created a bootstrap 4 template and attempted to install it. Firstly, I downl ...

What is the best way to align the items in the center of this container?

Check out this link: http://jsfiddle.net/zCXMv/18/ I'm having trouble getting this to work properly. Any assistance would be greatly appreciated. Here is the HTML code snippet: <div id="button" > <a class="button1 active" rel="1">&l ...

Locate the present position of the slider element

I am currently in the process of creating a website that features pages displayed in a slider format. Each page has its own unique ID, but all share a common class called 'section'. However, I am encountering difficulty in identifying the ID of t ...

What is the best way to interact with all the rendered DOM elements in React that were created using the map method

return <div> <div >{'Audios'}</div> {urls.map(url => <div > <audio controls src={url} ref={(element) => this.audioRefs.push(element)} /> </div>)} </div>; I a ...

Using JavaScript, append a hidden input field in Yii2 and retrieve it from the controller

Seeking assistance as a newcomer to yii2. I'm looking for help in resolving an issue that has arisen. I'm attempting to add a hidden input field to my form using JavaScript (not linked to a model). Subsequently, when I submit the form, I want to ...

How can I apply specific styling to certain cells within a table?

Is there a way to apply styles specifically to certain table headers in an HTML table without altering the HTML or introducing JavaScript? I need to target only 4 out of the total 8 table headers. To see the code and example for this question, visit: http ...

Set the height of the main div container to a fixed size

I am facing an issue with my div container (mapInfo-Container) which contains multiple div blocks. I want the container to have a fixed height of 250px, and be scrollable for any content exceeding this height. Here is the code snippet: http://jsfiddle.net ...

Struggling with identifying errors in the Javascript code for my assignment

My code is giving me trouble and I could really use some assistance You can find my code in this GitHub folder: link. To see the project in action, visit this page on GitHub Pages: link. The task involves iterating over an array of names and printing eit ...

Show data from a Mysql table column in a dropdown menu

I am trying to show the values from a MySQL table field in a select box. I attempted the code below but it only displays the specified field values in the echo function and not in the select box. I'm unsure where I made a mistake. $con = mysql_conne ...

Is it possible to alter preact-material-components to switch to mdc-theme--dark mode, thereby changing the CSS style of all descendant components?

I recently created a preact-cli app and added the following code in Header.js: document.body.classList.add('mdc-theme--dark'); However, when a user tries to switch from the light theme to the dark theme, only the background of the app changes. ...

Styling Drawn Elements on a Canvas Using CSS

Can CSS Animations be applied to a circle drawn on a canvas using JavaScript? Specifically, I am using an AngularJS directive for this purpose: https://github.com/angular-directives/angular-round-progress-directive/blob/master/angular-round-progress-direct ...