/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] 2Column Test Page-Sidebar width adjusts on window resize but main content shifts down

Hi, I think I only need to make a minor adjustment but with the ones I’ve tried I haven’t found a solution. HTML and CSS coding below. Thank you to those who can assist.

Details:
~ 2-column test page with: left sidebar with a width of 20%, main content, header, footer
~ Page width is 960px
~ 1 image in the sidebar

Problems:
~ The left sidebar width adjusts accordingly when the browser window size is changed from wide to narrow. However, the main content eventually shifts down quite a bit on the page as the browser window becomes more narrow leaving an empty space to the right of the sidebar. For the container I used max-width: 960px; instead of width: 960px because the sidebar did not change size accordingly with just using width: 960px.
~ Ideally I would like the sidebar height and main content height to always both be the same height but haven’t been able to accomplish this. Is this possible given they contain different amounts of text? Would I be best to set both with a fixed px height instead of using 100%?

[code=html]
<!doctype html>
<html>
<head>
<meta charset=”utf-8″>
<title>Test Page</title>
<link href=”screen.css” rel=”stylesheet” type=”text/css”>
</head>

<body>

<div id=”container”>

<header id=”header”>
<p>Alice In Wonderland</p>
</header>

<aside id=”sidebar”><img class=”imgalice” src=”alice.jpg” alt=”Alice in Wonderland”>

<p>Alice’s Adventures in Wonderland (commonly shortened to Alice in Wonderland) is an 1865 novel written by English author Charles Lutwidge Dodgson under the pseudonym Lewis Carroll. It tells of a girl named Alice falling through a rabbit hole into a fantasy world populated by peculiar, anthropomorphic creatures. The tale plays with logic, giving the story lasting popularity with adults as well as with children. It is considered to be one of the best examples of the literary nonsense genre. Its narrative course and structure, characters and imagery have been enormously influential in both popular culture and literature, especially in the fantasy genre.</p>
</aside>

<main id=”main”><p>The Caterpillar and Alice looked at each other for some time in silence. At last the Caterpillar took the hookah out of its mouth, and addressed her in a languid, sleepy voice.</p>

<p>”Who are YOU?” said the Caterpillar.</p>

<p>This was not an encouraging opening for a conversation. Alice replied, rather shyly, “I&mdash;I hardly know, sir, just at present&mdash;at least I know who I WAS when I got up this morning, but I think I must have been changed several times since then.”</p>

<p>”What do you mean by that?” said the Caterpillar sternly. “Explain yourself!”</p>

<p>”I can’t explain MYSELF, I’m afraid, sir” said Alice, “because I’m not myself, you see.”</p>

<p>”I don’t see,” said the Caterpillar.</p>

<p>”I’m afraid I can’t put it more clearly,” Alice replied very politely, “for I can’t understand it myself to begin with; and being so many different sizes in a day is very confusing.”</p>

<p>”It isn’t,” said the Caterpillar.</p>

<p>”Well, perhaps you haven’t found it so yet,” said Alice; “but when you have to turn into a chrysalis&mdash;you will some day, you know&mdash;and then after that into a butterfly, I should think you’ll feel it a little queer, won’t you?”</p>

<p>”Not a bit,” said the Caterpillar.</p>
</main>

<footer id=”footer”>sidebar @ <a href=”https://en.wikipedia.org/wiki/Alice%27s_Adventures_in_Wonderland” title=”Wikipedia” target=”new”>Wikipedia</a> | lorem ipsum @ <a href=”http://www.fillerati.com/” target=”new”>www.fillerati.com</a></footer>

</div> <!– end .container –>
</body>
</html>

[/code]

[CODE]
@charset “utf-8”;

#container {
max-width: 960px;
margin: 0 auto;
}

body {
height: 100%;
margin: 0;
padding: 0;
background-color: #000;
font-family: Baskerville, “Palatino Linotype”, Palatino, “Century Schoolbook L”, “Times New Roman”, serif;
color: #000;
}

#header {
background-color: #D6C2FF;
font-family: Baskerville, “Palatino Linotype”, Palatino, “Century Schoolbook L”, “Times New Roman”, serif;
font-size: xx-large;
font-weight: bolder;
text-align: center;
text-shadow: 0px 0px;
color: #FFFFFF;
letter-spacing: 2px;
word-spacing: 2px;
border: thin solid #000000;
clear: both;
width: 100%;
}

#sidebar {
width: 20%;
background-color: #FFCFDF;
margin-top: 20px;
margin-right: 5px;
margin-left: 0;
margin-bottom: 10px;
float: left;
clear: none;
font-family: Segoe, “Segoe UI”, “DejaVu Sans”, “Trebuchet MS”, Verdana, sans-serif;
font-size: small;
line-height: 18px;
padding: 5px;
border: thin solid #000000;
height: 100%;
}

.imgalice {
max-width: 100%;
height: auto;
}

#main {
width: 75%;
background-color: #CAFFED;
margin-top: 20px;
margin-right: 0;
margin-left: 0;
margin-bottom: 10px;
float: right;
font-family: Baskerville, “Palatino Linotype”, Palatino, “Century Schoolbook L”, “Times New Roman”, serif;
padding: 10px;
border: thin solid #000000;
height: 100%;
}

#footer {
background-color: #F0FFB7;
padding: 10px 0;
font-family: Constantia, “Lucida Bright”, “DejaVu Serif”, Georgia, serif;
position: relative;
clear: both;
text-align: center;
border: thin solid #000000;
width: 100%;
}
[/CODE]

to post a comment
CSS

2 Comments(s)

Copy linkTweet thisAlerts:
@jedaisoulSep 26.2015 — Basically, what you are seeking to do is impossible without full newspaper-style multi-column layouts which, as far as I am aware, no current browser support. Even if they did, there would be problems with legacy browsers.

A partial solution which you may wish to investigate uses the CSS3 "calc" facility. E.g.
<i>
</i>body {
width: 100%;
max-width: 960px;
min-width: 720px;
margin: 0 auto;
}
#sidebar {
width: calc(100% - 640px);
}
#main {
width: 640px;
}}

This allows main to have a fixed width of 640px, with sidebar varying beetween 80px and 320px wide.

However this only accommodates window widths down to 720px, and additional code would be needed to accommodate legacy browsers (e.g. IE8). To be compatible with smartphones, the layout must accommodate screen widths down to 320px wide. At that width, side bars are a no-no. So your layout really needs to be redesigned if it is to be fully responsive...
Copy linkTweet thisAlerts:
@BlondieCauthorSep 26.2015 — I'm not familiar with "calc" so thank you for brining that to my attention and for looking at my problem. I changed a few things around and both the HTML and CSS validated and I tried it in several browsers and have the test page the way I was trying to get it - after searching and reading for quite some time. I wish I could paste a screen capture.

I changed my HTML and CSS as follows:

[code=html]
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>asg03Part2Stringle</title>
<link href="screen.css" rel="stylesheet" type="text/css">
</head>

<body>

<div class="wrapper">

<header id="header">
<p>Alice In Wonderland</p>
</header>

<div class="container"> <!-- container clearfix -->

<div class="sidebar">
<aside>
<img class="imgalice" src="alice.jpg" alt="Alice in Wonderland">
<p>Alice's Adventures in Wonderland (commonly shortened to Alice in Wonderland) is an 1865 novel written by English author Charles Lutwidge Dodgson under the pseudonym Lewis Carroll. It tells of a girl named Alice falling through a rabbit hole into a fantasy world populated by peculiar, anthropomorphic creatures. The tale plays with logic, giving the story lasting popularity with adults as well as with children. It is considered to be one of the best examples of the literary nonsense genre. Its narrative course and structure, characters and imagery have been enormously influential in both popular culture and literature, especially in the fantasy genre.</p>
</aside>
</div> <!-- end aside.sidebar -->

<div class="content">
<main>
<p>The Caterpillar and Alice looked at each other for some time in silence. At last the Caterpillar took the hookah out of its mouth, and addressed her in a languid, sleepy voice.</p>
<p>"Who are YOU?" said the Caterpillar.</p>
<p>This was not an encouraging opening for a conversation. Alice replied, rather shyly, "I&mdash;I hardly know, sir, just at present&mdash;at least I know who I WAS when I got up this morning, but I think I must have been changed several times since then."</p>
<p>"What do you mean by that?" said the Caterpillar sternly. "Explain yourself!"</p>
<p>"I can't explain MYSELF, I'm afraid, sir" said Alice, "because I'm not myself, you see."</p>
<p>"I don't see," said the Caterpillar.</p>
<p>"I'm afraid I can't put it more clearly," Alice replied very politely, "for I can't understand it myself to begin with; and being so many different sizes in a day is very confusing."</p>
<p>"It isn't," said the Caterpillar.</p>
<p>"Well, perhaps you haven't found it so yet," said Alice; "but when you have to turn into a chrysalis&mdash;you will some day, you know&mdash;and then after that into a butterfly, I should think you'll feel it a little queer, won't you?"</p>
<p>"Not a bit," said the Caterpillar.</p>
</main>
</div> <!-- end main.content -->

</div> <!-- end .container clearfix -->

<footer id="footer">sidebar @ <a href="https://en.wikipedia.org/wiki/Alice%27s_Adventures_in_Wonderland" title="Wikipedia" target="new">Wikipedia</a> | lorem ipsum @ <a href="http://www.fillerati.com/" target="new">www.fillerati.com</a>
</footer>


</div> <!-- end .wrapper -->
</body>
</html>

[/code]



[CODE]
@charset "utf-8";

*
{
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}

div.wrapper {
max-width: 960px;
margin: 0 auto;
}

body {
height: 100%;
margin: 0;
padding: 0;
background-color: #000000;
font-family: Baskerville, "Palatino Linotype", Palatino, "Century Schoolbook L", "Times New Roman", serif;
color: #FFFFFF;
}

#header {
width: 100%;
background-color: #D6C2FF;
font-family: Baskerville, "Palatino Linotype", Palatino, "Century Schoolbook L", "Times New Roman", serif;
color: #FFFFFF;
font-size: xx-large;
font-weight: bolder;
text-align: center;
text-shadow: 0px 0px;
letter-spacing: 2px;
word-spacing: 2px;
border: thin solid #000000;
}

.wrapper .container {
padding-right: 0px;
overflow: hidden;
}

.sidebar {
width: 20%;
float: left;
background-color: #FFCFDF;
margin-top: 10px;
margin-right: 0;
margin-left: 0;
margin-bottom: 10px;
font-family: Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
font-size: small;
color: #000000;
line-height: 18px;
padding: 5px;
border: thin solid #000000;
}

.imgalice {
max-width: 100%;
height: auto;
}

.content {
width: 78%;
float:right;
background-color: #CAFFED;
margin-top: 10px;
margin-right: 0px;
margin-left: 0;
margin-bottom: 10px;
font-family: Baskerville, "Palatino Linotype", Palatino, "Century Schoolbook L", "Times New Roman", serif;
color: #000000;
padding: 10px;
border: thin solid #000000;
}

.content,
.sidebar {
padding-bottom: 999999px;
margin-bottom: -999999px;
}

main,
aside {
padding: 0px;
}

#footer {
width: 100%;
background-color: #F0FFB7;
padding: 10px 0;
font-family: Constantia, "Lucida Bright", "DejaVu Serif", Georgia, serif;
color: #000000;
position: relative;
clear: both;
text-align: center;
border: thin solid #000000;
}
[/CODE]
×

Success!

Help @BlondieC 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.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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