Search code examples
csshtmllayoutcss-multicolumn-layout

Converting DIV-like page into blog-like layout within CSS?


This is my HTML page:

https://jsfiddle.net/62czmtvt/2/ (to actually see the HTML page working)

Code from JSFiddle:

:root {
  background-color: #FFFACD;
}

div.infoguide {
  width: 240px;
  font-family: Arial, sans-serif;
  font-size: 13px;
  background-color: #F0FFF0;
}

div {
  margin: 5;
  padding: 0;
  border: 0;
  outline: 0;
}

A:link {
  text-decoration: underline;
  color: rgb(204, 51, 51);
}

A:visited {
  text-decoration: underline;
  color: rgb(204, 51, 51);
}

A:active {
  text-decoration: underline;
  color: rgb(204, 51, 51);
}

A:hover {
  text-decoration: underline;
  color: rgb(204, 51, 51);
}

body {
  margin-left: 0px;
  margin-top: 0px;
}

body,
td,
th {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 12px;
  color: rgb(46, 46, 46);
  line-height: 16px;
}

h1 {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 20px;
  font-weight: bold;
  line-height: 20px;
  margin-bottom: 0px;
}

h2 {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
  font-weight: bold;
  margin-bottom: 0px;
}

h3 {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 13px;
  font-weight: bold;
  margin-bottom: 0px;
}

h3 A:link {
  text-decoration: none;
  color: rgb(204, 51, 51);
}

h3 A:visited {
  text-decoration: none;
  color: rgb(204, 51, 51);
}

h3 A:active {
  text-decoration: none;
  color: rgb(204, 51, 51);
}

h3 A:hover {
  text-decoration: underline;
  color: rgb(204, 51, 51);
}

ul {
  margin-left: 1.5em;
  padding-left: 0px;
}

.info_data {
  border-color: rgb(137, 137, 137);
  border-style: solid;
  border-width: 1px;
  font-size: 11px;
  padding: 4px;
  text-align: center;
}

.news_headline {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
  font-weight: bold;
  line-height: 22px;
}

.red {
  color: rgb(204, 51, 51);
}

.red_padded {
  color: rgb(204, 51, 51);
  padding: 4px 0px;
}

.redbg {
  background-color: rgb(220, 6, 0);
}
<title>First Drive: 2017 Porsche Panamera - Autos.ca</title>
<div class="infoguide">
  <H3>It works!</h3>
  <p>It works!</p>
</div>

<div class="info_data">
</div>
<div class="infoguide">
  <h2 class="red">A headline</h2>
  <p>It works!</p>
</div>

It's a sandbox page for a blog-like layout of a magazine site, and I'm trying to achieve this sort of look:

Magazine article

but so far I haven't quite managed to get it to look the way I want to of being a three-column DIV with a header in a pseudo-blog-style layout.

I've been trying the :root element in my CSS file, is this encouraged or discouraged in a HTML5 page?

I would appreciate any advice or help with this!


Solution

  • In order to achieve three columns, you will need to alter your code a bit.

    1. You need a wrapper/container around your three divs you are attempting to separate and give it a 100% width or whatever width you want.
    2. You need to give the three divs a similar second class name and apply a float and a width to those divs. (There are other ways, but this is the clean way).

    CSS:

    <style>
    .page-container {
        width: 100%;
    }
    
    .infoguide { 
        float: left;
        width: 30%; 
    }
    </style>
    

    HTML:

    <title>First Drive: 2017 Porsche Panamera - Autos.ca</title>
        <div class="page-container">
            <div class="infoguide">
                <H3>It works!</h3>
                <p>It works!</p>
            </div>
    
            <div class="infoguide">
                <h1>Test Content</h1>
            </div>
    
            <div class="infoguide">
                <h2 class="red">A headline</h2>
                <p>It works!</p>
            </div>
        </div>
    

    I would also consider reading into flexbox if you're unfamiliar with it. It's a great way to make responsive webpages with many divs in column format. https://css-tricks.com/snippets/css/a-guide-to-flexbox/