DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Data Engineering
  3. Databases
  4. Display Long Dynamic Text Into Adjacent Columns Like Newspaper Layout

Display Long Dynamic Text Into Adjacent Columns Like Newspaper Layout

This article is a tutorial on formatting text with CSS and HTML for readability, usability, and performance.

Ashu Tomar user avatar by
Ashu Tomar
·
Oct. 28, 16 · Tutorial
Like (2)
Save
Tweet
Share
9.19K Views

Join the DZone community and get the full member experience.

Join For Free

If we have quite a long text and we want to show it into three adjacent columns, one way to implement it is via three <div>’s  or <p>’s in HTML and adding CSS properties.

For example, If we have a long text as following :

singlediv

And We want to show it into three separate adjacent columns for better readability, it can be done as follow:

HTML:

threedivs

And furthermore for adjacent view, we have to write this following CSS Code :

.main{
    display:inline-block;
}
.first{
    float: left;
    width: 400px;
    padding: 0 20px;
}

To apply vertical rule between these columns so that it can have better look&feel we have to write another CSS class as follow:

.vertical-rule{
    border-right: 1px solid #cccccc;
}

and add it to first two divs only,

Even though with these CSS and HTML code we can not manage the following scenario:

If the complete text to be displayed in P tag is rendered dynamically through a particular selector, in such a case it can be complicated to measure out how this text should be break to display in 3 divs/columns. 

Unfortunately, this is impossible to do with CSS and HTML without forcing column breaks at fixed positions, or restricting the markup allowed in the text, or using scripting.

CSS3 introduced some new property to make such layouts (if have noticed in newspaper, magazines, etc.)  have block layout mode because people have trouble reading text if lines are too long, if it takes too long for the eyes to move from the end of the one line to the beginning of the next, they lose track of which line they were on.

This limitation is solved by adding new following CSS3 properties to extend the traditional block layout mode.

These properties solve the above-discussed issue, the code becomes concise ,clear  and easy to implement instead of using complicated structure through JS. Here all those extra static divs are removed, using only single CSS class to manipulate display of content.

Multi-column Properties

  • column-width
  • column-count
  • column-gap
  • column-rule
  • column-span

For the above example context We just have write the following :

HTML :

singlediv

CSS:

.main {
    column-count: 3;
    column-gap: 40px;
    column-width: 300px;
}

h2 {
    column-span: all;
}

Its O/p will be:

multiplecolumnproperty

To apply vertical rule between these columns, we just have to add one more CSS property in main class i.e. column-rule, rather than adding an extra class for this.

Let’s explain the multiple column properties

  1. The column-width property specifies a suggested, optimal width for the columns.
  2. The column-count property specifies the number of columns an element should be divided into.
  3. The column-gap property specifies the gap between the columns. (e.g padding between columns)
  4. The column-rule property is a shorthand property for specifying color, width, and style of a vertical rule between all the columns. It displays a vertical rule between all the columns.
  5. The column-span property specifies how many columns an element should span across.
Column (database) Property (programming) CSS Newspaper

Published at DZone with permission of Ashu Tomar, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Simulate Network Latency and Packet Drop In Linux
  • Project Hygiene
  • How Observability Is Redefining Developer Roles
  • How To Convert HTML to PNG in Java

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: