/    Sign up×
Community /Pin to ProfileBookmark

3 equal columns in dimensions, but not on display

Hi,

I’m trying to create 3 columns with 3 divs, and their CSS code is:

.col1,.col2,.col3
{
float: left;
margin-left: 3%;
}

.col1 { width: 30%; }
.col2 { width: 30%; }
.col3 { width: 30%; }

But they do not spread equally on the screen: the right-most column has much more space to its right than the other, what am I doing wrong?

to post a comment
CSS

6 Comments(s)

Copy linkTweet thisAlerts:
@cootheadOct 02.2016 — Hi there lioshi,

[indent]

This forum is not working to well, again. :eek:

[/indent]

[i]coothead[/i]
Copy linkTweet thisAlerts:
@cootheadOct 02.2016 — Hi there lioshi,

[indent]

[b]Second Attempt[/b]

Here are two examples...

[b]display: table[/b]

[color=navy]
<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1">

<title>untitled document</title>

<link rel="stylesheet" href="screen.css" media="screen">

<style media="screen">
body {
background-color: #f0f0f0;
font: 1em/150% arial,verdana,helvetica,sans-serif;
color: #666;
}

h1,h2 {
text-align: center;
}

#container {
display: table;
border-spacing: 0.5em;
border: 0.06em solid #999;
background-color: #fcfcfc;
box-shadow: 0.5em 0.5em 0.5em #999;
}

#container div {
display: table-cell;
width: 33.33%;
padding: 1em;
border: 0.06em solid #999;
box-sizing: border-box;
background-color: #fff;
box-shadow: inset 0 0 1em #999;
}

#container div div {
width: auto;
padding: 0;
border: 0;
box-sizing: border-box;
box-shadow: none;
}

@media screen and (max-width: 40em) {

#container {
display: block;
padding: 0;
}

#container div {
display: block;
width: auto;
margin: 0.5em; <br/>
}
}
&lt;/style&gt;

&lt;/head&gt;
&lt;body&gt;

&lt;h1&gt;Page Information&lt;/h1&gt;

&lt;div id="container"&gt;

&lt;div&gt;
&lt;h2&gt;Column One Information&lt;/h2&gt;
&lt;p&gt;
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sit amet sem sed libero
bibendum tempus faucibus quis mi. Nulla rhoncus vel ipsum in volutpat. Nam tortor nibh,
posuere ac lorem ut, suscipit tincidunt leo. Duis interdum justo ac justo vehicula consequat.
Curabitur et volutpat nibh. Phasellus rutrum lacus at dolor placerat feugiat. Morbi porta,
sapien nec molestie molestie, odio magna vestibulum lorem, vitae feugiat est leo sit amet
nunc.
&lt;/p&gt;
&lt;div&gt;a div element&lt;/div&gt;
&lt;/div&gt;

&lt;div&gt;
&lt;h2&gt;Column Two Information&lt;/h2&gt;
&lt;div&gt;a div element&lt;/div&gt;
&lt;/div&gt;

&lt;div&gt;
&lt;h2&gt;Column Three Information&lt;/h2&gt;
&lt;div&gt;a div element&lt;/div&gt;
&lt;/div&gt;

&lt;!-- #container --&gt;&lt;/div&gt;

&lt;/body&gt;
&lt;/html&gt;[/color]


[b]display: flex[/b]

[color=navy]
&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;

&lt;meta charset="utf-8"&gt;
&lt;meta name="viewport" content="width=device-width,height=device-height,initial-scale=1"&gt;

&lt;title&gt;untitled document&lt;/title&gt;

&lt;link rel="stylesheet" href="screen.css" media="screen"&gt;

&lt;style media="screen"&gt;
body {
background-color: #f0f0f0;
font: 1em/150% arial,verdana,helvetica,sans-serif;
color: #666;
}

h1,h2 {
text-align: center;
}

#container {
display: flex;
justify-content: space-between;
padding: 1%;
border: 0.06em solid #999;
background-color: #fcfcfc;
box-shadow: 0.5em 0.5em 0.5em #999;
}

#container div {
width: 32.33%;
padding: 1em;
border: 0.06em solid #999;
box-sizing: border-box;
background-color: #fff;
box-shadow: inset 0 0 1em #999;
}

#container div div {
width: auto;
padding: 0;
border: 0;
box-sizing: border-box;
box-shadow: none;
}

@media screen and (max-width: 40em) {

#container {
display: block;
padding: 0;
}

#container div {
width: auto;
margin: 0.5em; <br/>
}
}
&lt;/style&gt;

&lt;/head&gt;
&lt;body&gt;

&lt;h1&gt;Page Information&lt;/h1&gt;

&lt;div id="container"&gt;

&lt;div&gt;
&lt;h2&gt;Column One Information&lt;/h2&gt;
&lt;p&gt;
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sit amet sem sed libero
bibendum tempus faucibus quis mi. Nulla rhoncus vel ipsum in volutpat. Nam tortor nibh,
posuere ac lorem ut, suscipit tincidunt leo. Duis interdum justo ac justo vehicula consequat.
Curabitur et volutpat nibh. Phasellus rutrum lacus at dolor placerat feugiat. Morbi porta,
sapien nec molestie molestie, odio magna vestibulum lorem, vitae feugiat est leo sit amet
nunc.
&lt;/p&gt;
&lt;div&gt;a div element&lt;/div&gt;
&lt;/div&gt;

&lt;div&gt;
&lt;h2&gt;Column Two Information&lt;/h2&gt;
&lt;div&gt;a div element&lt;/div&gt;
&lt;/div&gt;

&lt;div&gt;
&lt;h2&gt;Column Three Information&lt;/h2&gt;
&lt;div&gt;a div element&lt;/div&gt;
&lt;/div&gt;

&lt;!-- #container --&gt;&lt;/div&gt;

&lt;/body&gt;
&lt;/html&gt;[/color]


[/indent]

[i]coothead[/i]
Copy linkTweet thisAlerts:
@lioshiauthorOct 03.2016 — Thanks guys ?!
Copy linkTweet thisAlerts:
@cootheadOct 03.2016 — [indent]

No problem, you're very welcome. ?

[/indent]

[i]coothead[/i]
Copy linkTweet thisAlerts:
@Alicia78Oct 03.2016 — I was having same problem same coothead
×

Success!

Help @lioshi spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...