user1157751
user1157751

Reputation: 2457

HTML and CSS, extra space and column heights

Currently I'm trying to design an index page.

I came across an issue of having two columns being the same height, furthurmore, there is always an extra space on the left, about 5~10px.

Problems:

  1. Columns does not have the same height
  2. Extra space on the left

Solutions I tried:

  1. I tried to set height = 100%, or to a specific amount of px, however, the columns get seperate heights.

  2. I've also tried to remove all the padding and margins, but the left side would always have an extra space, causing the body and the h1 header to "blend" together since they have the same background color.

Code: Jsfiddle

<!DOCTYPE html>
<html>
    <head>
        <title>Web Based Metrics</title>
        <style type="text/css">
            body {
                width: 100%;
                font-family: Arial, Verdana, sans-serif;
                color: #665544;
                background-color: #74AFAD}
            .column1 {
                float: left;
                width: 21%;
                padding: 0px 5px 5px 5px;
                margin: 0px 5px 0px 0px;
                background-color: #AACECD;
                color: #D9853B;}
            .column2 {
                float: left;
                width: 76%;
                padding: 0px 0px 5px 5px;
                background-color: #ECECEA;
                color: #000000;}
            h1 {
                float:left
                position: relative;
                padding: 50px 0px 0px 5px;
                margin: 0px 0px 0px 0px;
                top: 0%;
                right: 100%;
                left: 0%;
                width: 100%;
                background-color: #74AFAD;
                color: #ffffff;}
            h2 {
                float:left
                position: relative;
                padding: 15px 0px 0px 5px;
                margin: 0px 0px 5px 0px;
                top: 0%;
                right: 100%;
                left: 0%;
                width: 100%;
                background-color: #558C89;
                color: #ffffff;}
            h4 {
                color: #ffffff;}
            p {
                position: relative;
                bottom: 100%}
        </style>
    </head>
    <body>
        <h1>Web Based Metrics</h1>
        <h2>Title 2!</h2>
        <div class="column1">
            <h4> something </h4>
            <p>In 1817 Baron von Drais invented a walking machine that would help him get around the royal gardens faster: two same-size in-line wheels, the front one steerable, mounted in a frame upon which you straddled. The device was propelled by pushing your feet against the ground, thus rolling yourself and the device forward in a sort of gliding walk.</p>
            <p>The machine became known as the Draisienne (or "hobby horse"). It was made entirely of wood. This enjoyed a short lived popularity as a fad, not being practical for transportation in any other place than a well maintained pathway such as in a park or garden.</p>
            <p>The next appearance of a two-wheeled riding machine was in 1865, when pedals were applied directly to the front wheel. This machine was known as the velocipede (meaning "fast foot") as well as the "bone shaker," since its wooden structure combined with the cobblestone roads of the day made for an extremely uncomfortable ride. They also became a fad and indoor riding academies, similar to roller rinks, could be found in large cities.</p>
            <p>In 1870 the first all-metal machine appeared. (Prior to this, metallurgy was not advanced enough to provide metal which was strong enough to make small, light parts out of.) The pedals were attached directly to the front wheel with no freewheeling mechanism. Solid rubber tires and the long spokes of the large front wheel provided a much smoother ride than its predecessor.</p>
            <p>The front wheels became larger and larger as makers realized that the larger the wheel, the farther you could travel with one rotation of the pedals. For that reason, you would purchase a wheel as large as your leg length would allow. This machine was the first one to be called a bicycle ("two wheel"). These bicycles enjoyed a great popularity during the 1880s among young men of means. (They cost an average worker six month's pay.)</p>
            <p>Because the rider sat so high above the center of gravity, if the front wheel was stopped by a stone or rut in the road, or the sudden emergence of a dog, the entire apparatus rotated forward on its front axle and the rider, with his legs trapped under the handlebars, was dropped unceremoniously on his head. Thus the term "taking a header" came into being.</p>
        </div>
        <div class="column2">
            <p>In 1817 Baron von Drais invented a walking machine that would help him get around the royal gardens faster: two same-size in-line wheels, the front one steerable, mounted in a frame upon which you straddled. The device was propelled by pushing your feet against the ground, thus rolling yourself and the device forward in a sort of gliding walk.</p>
            <p>The machine became known as the Draisienne (or "hobby horse"). It was made entirely of wood. This enjoyed a short lived popularity as a fad, not being practical for transportation in any other place than a well maintained pathway such as in a park or garden.</p>
            <p>The next appearance of a two-wheeled riding machine was in 1865, when pedals were applied directly to the front wheel. This machine was known as the velocipede (meaning "fast foot") as well as the "bone shaker," since its wooden structure combined with the cobblestone roads of the day made for an extremely uncomfortable ride. They also became a fad and indoor riding academies, similar to roller rinks, could be found in large cities.</p>
            <p>In 1870 the first all-metal machine appeared. (Prior to this, metallurgy was not advanced enough to provide metal which was strong enough to make small, light parts out of.) The pedals were attached directly to the front wheel with no freewheeling mechanism. Solid rubber tires and the long spokes of the large front wheel provided a much smoother ride than its predecessor.</p>
            <p>The front wheels became larger and larger as makers realized that the larger the wheel, the farther you could travel with one rotation of the pedals. For that reason, you would purchase a wheel as large as your leg length would allow. This machine was the first one to be called a bicycle ("two wheel"). These bicycles enjoyed a great popularity during the 1880s among young men of means. (They cost an average worker six month's pay.)</p>
            <p>Because the rider sat so high above the center of gravity, if the front wheel was stopped by a stone or rut in the road, or the sudden emergence of a dog, the entire apparatus rotated forward on its front axle and the rider, with his legs trapped under the handlebars, was dropped unceremoniously on his head. Thus the term "taking a header" came into being.</p>
        </div>
    </body>
</html>

Upvotes: 0

Views: 66

Answers (2)

Asim Nadeem
Asim Nadeem

Reputation: 151

for deeper understanding see this http://jsfiddle.net/PhilippeVay/sFBGX/2/

simply display div as table cells.

container {display: table;}
child1{display: cell;}
child2 {display: cell;}

Here is solution

1. CSS

.container{

               display: table;
            table-layout: fixed;
}
body {
            width: 100%;
            font-family: Arial, Verdana, sans-serif;
            color: #665544;
            background-color: #74AFAD}
.col {
display: table-cell;
vertical-align: top;}
.column1 {

            width: 21%;
            padding: 0px 5px 5px 5px;
            margin: 0px 5px 0px 0px;
            background-color: #AACECD;
            color: #D9853B;}
        .column2 {

            width: 76%;
            padding: 0px 0px 5px 5px;
            background-color: #ECECEA;
            color: #000000;}
        h1 {
            float:left
            position: relative;
            padding: 50px 0px 0px 5px;
            margin: 0px 0px 0px 0px;
            top: 0%;
            right: 100%;
            left: 0%;
            width: 100%;
            background-color: #74AFAD;
            color: #ffffff;}
        h2 {
            float:left
            position: relative;
            padding: 15px 0px 0px 5px;
            margin: 0px 0px 5px 0px;
            top: 0%;
            right: 100%;
            left: 0%;
            width: 100%;
            background-color: #558C89;
            color: #ffffff;}
        h4 {
            color: #ffffff;}
        p {
            position: relative;
            bottom: 100%}

2.HTML

    <h1>Web Based Metrics</h1>
    <h2>Title 2!</h2>
<div class="container">
    <div class="column1 col">
        <h4> something </h4>
        <p>In 1817 Baron von Drais invented a walking machine that would help him get around the royal gardens faster: two same-size in-line wheels, the front one steerable, mounted in a frame upon which you straddled. The device was propelled by pushing your feet against the ground, thus rolling yourself and the device forward in a sort of gliding walk.</p>
        <p>The machine became known as the Draisienne (or "hobby horse"). It was made entirely of wood. This enjoyed a short lived popularity as a fad, not being practical for transportation in any other place than a well maintained pathway such as in a park or garden.</p>
        <p>The next appearance of a two-wheeled riding machine was in 1865, when pedals were applied directly to the front wheel. This machine was known as the velocipede (meaning "fast foot") as well as the "bone shaker," since its wooden structure combined with the cobblestone roads of the day made for an extremely uncomfortable ride. They also became a fad and indoor riding academies, similar to roller rinks, could be found in large cities.</p>
        <p>In 1870 the first all-metal machine appeared. (Prior to this, metallurgy was not advanced enough to provide metal which was strong enough to make small, light parts out of.) The pedals were attached directly to the front wheel with no freewheeling mechanism. Solid rubber tires and the long spokes of the large front wheel provided a much smoother ride than its predecessor.</p>
        <p>The front wheels became larger and larger as makers realized that the larger the wheel, the farther you could travel with one rotation of the pedals. For that reason, you would purchase a wheel as large as your leg length would allow. This machine was the first one to be called a bicycle ("two wheel"). These bicycles enjoyed a great popularity during the 1880s among young men of means. (They cost an average worker six month's pay.)</p>
        <p>Because the rider sat so high above the center of gravity, if the front wheel was stopped by a stone or rut in the road, or the sudden emergence of a dog, the entire apparatus rotated forward on its front axle and the rider, with his legs trapped under the handlebars, was dropped unceremoniously on his head. Thus the term "taking a header" came into being.</p>
    </div>
    <div class="column2 col">
        <p>In 1817 Baron von Drais invented a walking machine that would help him get around the royal gardens faster: two same-size in-line wheels, the front one steerable, mounted in a frame upon which you straddled. The device was propelled by pushing your feet against the ground, thus rolling yourself and the device forward in a sort of gliding walk.</p>
        <p>The machine became known as the Draisienne (or "hobby horse"). It was made entirely of wood. This enjoyed a short lived popularity as a fad, not being practical for transportation in any other place than a well maintained pathway such as in a park or garden.</p>
        <p>The next appearance of a two-wheeled riding machine was in 1865, when pedals were applied directly to the front wheel. This machine was known as the velocipede (meaning "fast foot") as well as the "bone shaker," since its wooden structure combined with the cobblestone roads of the day made for an extremely uncomfortable ride. They also became a fad and indoor riding academies, similar to roller rinks, could be found in large cities.</p>
        <p>In 1870 the first all-metal machine appeared. (Prior to this, metallurgy was not advanced enough to provide metal which was strong enough to make small, light parts out of.) The pedals were attached directly to the front wheel with no freewheeling mechanism. Solid rubber tires and the long spokes of the large front wheel provided a much smoother ride than its predecessor.</p>
        <p>The front wheels became larger and larger as makers realized that the larger the wheel, the farther you could travel with one rotation of the pedals. For that reason, you would purchase a wheel as large as your leg length would allow. This machine was the first one to be called a bicycle ("two wheel"). These bicycles enjoyed a great popularity during the 1880s among young men of means. (They cost an average worker six month's pay.)</p>
        <p>Because the rider sat so high above the center of gravity, if the front wheel was stopped by a stone or rut in the road, or the sudden emergence of a dog, the entire apparatus rotated forward on its front axle and the rider, with his legs trapped under the handlebars, was dropped unceremoniously on his head. Thus the term "taking a header" came into being.</p>
    </div>
        </div>

Upvotes: 1

Mohamed El Mahallawy
Mohamed El Mahallawy

Reputation: 13852

Firstly:

body{
   margin: 0px;
}

Will fix the margin on the ends.

Your columns will never be the same size given you have different amount of text and set different amount of width for both of them.

Upvotes: 1

Related Questions