I have a 2 column site: the left column is fluid and the right column is fixed. When I scale the browser in to check to see how the site responds the right column seems to collapse below the left column. I do not want this right column collapsing. I would like for the left main column to contract fluidly as the site is scaled in.
Here is the basics of my code: http://jsfiddle.net/kGkRD/
<section class="main">
Left
</section>
<aside class="sidebar">
Right
</aside>
body {
max-width: 500px;
width: 100%;
margin: 0 auto;
}
section.main {
float: left;
max-width: 300px;
width: 100%;
background-color: red;
}
aside.sidebar {
float: right;
width: 200px;
background-color: blue;
}
<aside class="sidebar">
Hello World
</aside>
<section class="main">
Hello World123
</section>
CSS
#media (max-width:500px){
section.main {
//display:block;
float:right;
}
}
Fiddle
EDIT: Please use the updated css. try both using display:block and float:right.
Put your right floated element first, remove the float: left; and width: 100%; from the section.main and add overflow: hidden;: http://jsfiddle.net/mdares/kGkRD/1/
HTML:
<aside class="sidebar">
Hello World
</aside>
<section class="main">
Hello World
</section>
CSS:
body {
max-width: 500px;
width: 100%;
margin: 0 auto;
}
section.main {
max-width: 300px;
background-color: red;
overflow: hidden;
}
aside.sidebar {
float: right;
width: 200px;
background-color: blue;
}
Update: Do I understand correctly and you are looking for this: http://jsfiddle.net/mdares/kGkRD/4/
body {
max-width: 500px;
width: 100%;
margin: 0 auto;
}
section.main {
max-width: 300px;
width: 100%;
background-color: red;
overflow: hidden;
float: left;
}
aside.sidebar {
float: left;
width: 200px;
background-color: blue;
}
If so you were just missing your overflow: hidden;
UPDATE 2: To address your comment try this: http://jsfiddle.net/mdares/kGkRD/5/
CSS:
body {
max-width: 500px;
width: 100%;
margin: 0 auto;
}
#container {
position: relative;
width: 100%;
}
section.main {
max-width: 300px;
width: 100%;
background-color: red;
overflow: hidden;
float: left;
}
aside.sidebar {
width: 200px;
background-color: blue;
position: absolute;
right: 0;
}
#media screen and (max-width: 350px) {
aside.sidebar {
position: static;
float: left;
}
}
HTML:
<div id="container">
<section class="main">
Hello World
</section>
<aside class="sidebar">
Hello World
</aside>
</div>
Related
How do I make the image responsive and keep it in between the containers left and right.
I have tried putting it all into another container and it doesn’t work.
I know it sounds basic but it really is not.
body {
background-color: black;
}
.left {
background-color: red;
width: 150px;
height: 800px;
float: left;
}
.right {
background-color: green;
width: 150px;
height: 800px;
float: right;
}
img {
display: block;
margin-left: auto;
margin-right: auto;
}
<div class="left"></div>
<div class="right"></div>
<img src="paintingOg.gif" style="width:50%">
How about this way? Is it (close to) what you need? Please check responsiveness too.
body {
background-color: black;
}
.left {
background-color: red;
width: 150px;
height: 800px;
float: left;
}
.right {
background-color: green;
width: 150px;
height: 800px;
float: right;
}
.center {
height: 800px;
background-color: blue;
overflow: auto;
text-align: center;
}
img {
max-width: 100%;
height: auto;
}
<div class="left"></div>
<div class="right"></div>
<div class="center">
<img src="https://picsum.photos/500/500?gravity=west">
</div>
You don't need containers to center something.
It's better to use 1 container that contains everything.
If you want to center your image into a div just use this code:
<div align="center">
<image src="whatever.png"/>
</div>
body {
background-color: black;
}
.left {
background-color: red;
width: 150px;
height: 800px;
float: left;
}
.right {
background-color: green;
width: 150px;
height: 800px;
float: right;
}
img {
width: 100%;
height: auto;
}
<div class="left"></div>
<div class="right"></div>
<div align="center">
<img src="paintingOg.gif" />
</div>
So I have 3 divs side by side inside the div element and another div after them. However, this div is overlapping the others. How can I make "footer" come after "main"?
.main {
height: 500px;
width: 100%;
position: absolute;
}
.filter {
background: red;
height: 100%;
float: left;
width: 20%;
}
.post-bar {
background: blue;
height: 100%;
float: left;
width: 60%;
}
.advertisment {
background: green;
height: 100%;
float: left;
width: 20%;
}
.footer {
height: 250px;
width: 100%;
background: black;
position: relative;
}
<div class="main">
<div class="filter">
</div>
<div class="post-bar">
</div>
<div class="advertisment">
</div>
</div>
<div class="footer"></div>
Just get rid off position:absolute in your main class:
.main {
height: 500px;
width: 100%;
}
.filter {
background: red;
height: 100%;
float: left;
width: 20%;
}
.post-bar {
background: blue;
height: 100%;
float: left;
width: 60%;
}
.advertisment {
background: green;
height: 100%;
float: left;
width: 20%;
}
.footer {
height: 250px;
width: 100%;
background: black;
position: relative;
}
<div class="main">
<div class="filter">
</div>
<div class="post-bar">
</div>
<div class="advertisment">
</div>
</div>
<div class="footer"></div>
Just remove the
position: absolute;
display: block;
from
.main
I think you will find your desired result. Please , inform if there are any other issues. Thank you.
Remove positions from main and footer.
.main {
height: 500px;
width: 100%;
float:left;
}
.footer {
height: 250px;
width: 100%;
background: black;
float:left;
}
I have some questions:
How can I get the nav, conversationList and conversation section expand to the bottom?
If one of these 3 expand their size (e.g. a long text). How can I apply the same size to all 3?
Fiddle Link.
HTML
<header>
Text
</header>
<main>
<nav>
Navigation
</nav>
<section id="contentWrapper">
<section id="contentTitle">
TITLE
</section>
<section id="conversationList">
List
</section>
<section id="conversation">
Conversation
</section>
</section>
</main>
CSS
html, body{
height: 100%;
width: 100%;
margin:0px !important;
}
header{
position: fixed;
top: 0;
height: 60px;
width: 100%;
background-color: #777;
z-index: 1;
}
main{
float: left;
padding-top: 60px;
background-color:black;
bottom:0px;
width:100%;
min-height: calc(100% - 60px);
}
nav{
float: left;
width: 15%;
min-height: 100%;
background-color: green;
}
#contentTitle{
float: left;
width: 98.5%;
height: 35px;;
padding-top: 25px;
padding-left: 1.5%;
background-color: red;
}
#contentWrapper{
float: left;
width: 85%;
min-height: 100%;
}
#pageTitle{
float: left;
width: 100%;
height: 40px;
padding-top: 20px;
padding-left: 3%;
background-color: red;
}
#conversationList{
float: left;
width: 30%;
background-color: white;
}
#conversation{
float: left;
width: 70%;
background-color: yellow;
}
Basic answer is to apply height: 100% to every element you want stretched. You have to remember to give each parent element a height of 100% as well, like #contentWrapper needs height: 100%.
Have a fiddle!
I have completely re-written this for you:
jsBin example!
Have a play with it so that you understand how it works.
CSS
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,body {
height: 100%;
}
header {
height: 60px;
background: green;
}
main {
display: table;
width: 100%;
height: calc(100% - 60px);
}
nav {
display: table-cell;
width: 60px;
background: green;
}
#contentWrapper {
display: table;
width: 100%;
height: calc(100% - 60px);
}
#contentTitle {
width: 100%;
height: 60px;
background: red;
}
#conversationList {
width: 80px;
float: left;
height: calc(100% - 60px);
background: yellow;
}
#conversation {
float: left;
width: calc(100% - 80px);
height: calc(100% - 60px);
background: pink;
}
HTML
<header>
Text
</header>
<main>
<nav>
Navigation
</nav>
<section id="contentTitle">
TITLE
</section>
<section id="conversationList">
List
</section>
<section id="conversation">
Conversation
</section>
</main>
I'm an amateur with CSS and have tried using some guides to get myself so far. I've set up a fiddle http://jsfiddle.net/defaye/X9t7M/1/ for anyone who may know what I'm doing wrong? I can't get the sidebar on the right-hand side as a right-most column of the main content.
CSS structure
#wrapper {
width: 100%;
min-width: 950px;
max-width: 1110px;
margin: 0 auto;
}
#header {
float: left;
height: 354px;
width: 100%;
}
#navigation {
float: left;
height: 40px;
width: 100%;
}
#container {
float: left;
width: 100%;
}
#main {
margin-right: 200px;
}
#sidebar {
width: 300px;
margin-left: -300px;
float: left;
}
#footer {
height: 40px;
width: 100%;
clear: both;
}
HTML structure
<body>
<div id="wrapper">
<div id="header"></div>
<div id="navigation"></div>
<div id="container">
<div id="main"></div>
<div id="sidebar"></div>
</div>
<div id="footer"></div>
</div>
</body>
Take a look at this fiddle how it works. Here is your updated fiddle
#main, #sidebar {
float: left;
}
#main {
width: 70%;
}
#sidebar {
width: 30%;
}
I got problem with centering the div #offer within the section .tight. I don't want to use position: absolute; because of possibility of correct displaying site in 1024px width screens.
Here's the HTML:
<section class="main">
<section class="tight">
<div id="offers">
<article class="offer">
<div id="offer_stats"></div>
text
</article>
<article class="offer">
<div id="offer_comp"></div>
text
</article>
<article class="offer last">
<div id="offer_time"></div>
text
</article>
</div>
</section>
</section>
And the CSS:
section.main {
min-width: 880px;
max-width: 1200px;
margin: 0 auto;
}
section.tight {
width: 100%;
margin: 0 auto;
float: left;
}
#offers {
float: left;
padding-bottom: 100px;
text-align: center;
}
article.offer {
float: left;
min-height: 178px;
width: 260px;
color: #59535e;
padding-right: 50px;
}
article.offer.last {
padding-right: 0;
}
article.offer div {
height: 178px;
}
#offer_stats {
background: url("../images/offer_stats.png") no-repeat;
}
#offer_comp {
background: url("../images/offer_comp.png") no-repeat;
}
#offer_time {
background: url("../images/offer_time.png") no-repeat;
}
The printscreen:
Any suggestions?
section.main {
width: 880px;
max-width: 1200px;
margin: 0 auto;
}
First, i suggest you to remove float: left; from #offers
#offers {
padding-bottom: 100px;
text-align: center;
}
Second, i suggest you to use display: inline-block; instead of float: left; in article.offer
article.offer {
display: inline-block;
min-height: 178px;
width: 260px;
color: #59535e;
padding-right: 50px;
}
See this jsfiddle