Centering main next to a sidebar - html

I apologize in advance if this has been asked before but unfortunately I can't seem to find an answer - maybe I used the wrong terms while searching.
However. I am building a very simple website to display my portfolio and I decided to put a fixed sidebar on the left and the main contents scrolling on the right. Let's say the "active part" of the website begins where the sidebar ends, and I need my contents centered between the end of the sidebar and the end of the browser window.
I float the contents to the right and manage to make it look like I want it to but only by setting specific margins.
As you can see the result viewed on my laptop, which is correct on this resolution, but if the size of the window increases, the contents remain, obviously, on the right, and the left margin becomes bigger than the right margin which I don't want.
Is it possible to make the main setting itself at the center so that the two margins are even on different resolutions?
HTML
<div id="main">
<div class="title-contents">
<h1 class="page-name">Stuff I Make</h1>
<div class="gallery-icon"><img src="images/grid-icon.jpg"/></div>
<div class="gallery-icon"><img src="images/line-icon.jpg"/></div>
<div style="clear:both"></div>
</div>
CSS
#main {
background-color:#fff;
width:780px;
height:100%;
margin:60px;
float:right;
padding-left:40px;
padding-right:40px;
padding-top:40px;
padding-bottom:60px;
}
Thanks to everyone of you who will read and eventually answer and please forgive my clear lack of knowledge, I started doing this a couple of weeks ago so if this question is beyond stupid just try to understand, ahah ;) Thank you!
Veronica
EDIT: fiddle...I hope it's clear. As you can see the main sticks to the right because I set it to float:right, but if I set it to float:center it stays in the middle of the page goind UNDER the sidebar. I want it to always stay centered WITHIN the space next to the sidebar.
To answer the question, the sidebar has a fixed width. Thanks!!!! :)

When using a percentage layout, I suggest you to use TJ's answer.
If you want the sidebar to have a fixed width, I made you this solution, using absolute position on the main part:
HTML:
<div id="sidebar">
sidebar
</div>
<div id="main">
<div>
content
</div>
</div>
CSS:
#sidebar {
position: fixed;
top: 0;
left: 0;
width: 150px;
height: 100%;
background: lightblue;
}
#main {
position: absolute;
top: 25px;
right: 25px;
bottom: 25px;
left: 175px; /* width of #sidebar + extra margin */
}
#main > div {
width: 100%;
min-height: 100%;
background: lightgreen;
}
What it does: the sidebar has a fixed place and a fix width. If you want you can add margin to it by playing around with the top, left and bottom position.
The #main div is placed absolute. The top, right and bottom position are all set to the same number (in the example 25px). The left position is the width of the sidebar plus the extra margin (in the example 150 + 25 = 175px;
Also see this demo.
Footnote: the extra div inside #main is for when the length of the content is bigger than #main, and the background will expand. See this extra demo. In case it all fits inside it, just remove the div (and put a background on #main).

You need a container for the sidebar and content. You can fixed position the sidebar and center align the content in the remaining space by applying padding-left equal to the width of sidebar and margin:0 auto for the container.
Following is a quick responsive setup:
HTML
<div id="page">
<div id="sidebar"></div>
<div id="main"></div>
</div>
CSS:
#page{
height:100%;
padding-left:10%; // equal to the width of sidebar
}
#sidebar{
position:fixed;
top:10%;
left:0;
width:10%;
height:80%;
}
#main {
width: 80%;
height: 100%;
margin:0 auto; // center align horizontally
}
Try resizing the output window in following fiddle:
Demo

Not sure what you are looking for but maybe this?
HTML
<div class="one">
Here's room for the side menu
<ul>
<li>option 1</li>
<li>option 2</li>
<li>option 3</li>
<li>option 4</li>
<li>option 5</li>
<li>option 6</li>
<li>option 7</li>
<li>option 8</li>
<li>option 9</li>
</ul>
</div>
<div class="two">
<div id="main">
<div class="title-contents">
<h1 class="page-name">Stuff I Make</h1>
<div style="clear:both"></div>
</div>
</div>
</div>
CSS
#main {
border: 2px solid red;
width:80%;
height:100%;
margin: 0 auto;
padding-left:40px;
padding-right:40px;
padding-top:40px;
padding-bottom:60px;
box-sizing: border-box;
}
.one {
border: 2px solid green;
float: left;
width: 20%;
display: block;
box-sizing: border-box;
height: 100%;
}
.two {
border: 2px solid blue;
float: left;
width: 80%;
display: block;
box-sizing: border-box;
}
Here's a Fiddle

Related

How can I prevent my fixed positioned elements from scrolling when the browser is resized?

I must start off by saying I'm on a HUGE learning curve with this, and the website project is in my spare time as a present to somebody, so my knowledge is limited, although I think I understand the basics.
ALSO please note that I do have another more basic, less interesting site which is already built as a back-up so I won't be broken-hearted if I'm told all my code is rubbish and I need to start again!
I'm creating a one-page, horizontally-scrolling portfolio site for a make-up artist, which requires me to have a fixed banner with my menu listings on the left hand side, and with javascript, the page scrolls nice and smoothly to the relevant section.
Everything looks great on my screen resolution, with my browser at the right size, but I've noticed that if I shrink the browser window down, the fixed navigation banner starts to scroll out of place, while everything else stays together as it should.
The end result should be that everything stays in its place, with the only 'moving part' being the content on the scrolling section, so when the browser is resized, everything either re-sizes or at least scrolls together.
I've played around with wrapping everything in a content div and I've experimented with different positioning, but nothing seems to be working.
Here's my basic html layout for the sections:
<html>
<body>
<div id="banner"> <!--this is the fixed nav banner-->
<ul>
<li>PORTFOLIO</li>
<li>ABOUT</li>
<li>TESTIMONIALS</li>
<li>CONTACT</li>
</ul>
</div>
<div id="portfolio" class="bigpanel">
<div id="portfolioimages">
<!--IMAGES GO HERE-->
</div>
</div>
<div id="about" class="panel">
</div>
<div id="testimonials" class="bigpanel">
</div>
<div id="contact" class="bigpanel">
</div>
<div id="footer">
</div>
</body>
</html>
...and the CSS:
body {
width: 15000px;
height: 580px;
background-color: #fcf4f1;
position: absolute;
margin: 2% 0 5% 0;
}
#footer {
position: fixed;
left: 935px;
top: 645px;
margin: 10px;
}
#banner {
position: fixed;
height: 580px;
width: 200px;
background-color: #fff;
opacity: 0.8;
line-height: 20px;
margin: 45px 0px 0px 20px;
padding: 0;
z-index: 999;
}
.panel {
width: 930px;
float: left;
padding-left: 242px;
padding-right: 1040px;
margin-top: 45px;
}
.bigpanel {
float: left;
padding-left: 242px;
padding-right: 1040px;
margin-top:45px;
}
Pic of how the site is at the correct size
...and a pic of how it looks when it's squished in height!
I've tried to be as thorough as possible so sorry for the long one!
Any help would be greatly appreciated.
Ok, I don't know whether I have the answer that will work for everyone but it certainly has for me.
I basically had a long look at how I'd defined the widths and heights for basically all elements in my website and worked out that although the widths needed to be fixed for the main body and the banner, the height could be responsive depending on the viewport size.
I wrapped everything in a very wide wrapper div, with a height set to 100%, but set the body height to 84vh, with a max-height of 700px (so my images can have the same max-height and always look good).
This way I could also set the banner to height: 84vh with a max-height of 700px so it never overflows, but always sizes down.
I set the margin for my wrapper to centre it vertically, and now whilst everything fits inside its containers, there's no vertical scroll!
I'm sure a lot of it is an ugly solution, caused by my bad coding but it works now!
I thing you have to play with the top poperty on you #banner div by putting it to 0. This work only with positions like fixed, absolute, relative, etc. What it will do is to fix you div at the top of your browser window, no matter what. It is the "top padding" (disantce) you div will have relativly to the to of the screen.
So you should just add
top: 0;
to
#banner
and it should work!
If you want an exemple of it's efficacity, I recommend you to look at this codepen: http://codepen.io/Symsym/pen/LsjCK
Cheers! and tell me if it works.
<body>
<div class="banner"> <!--this is the fixed nav banner-->
<ul>
<li>PORTFOLIO</li>
<li>ABOUT</li>
<li>TESTIMONIALS</li>
<li>CONTACT</li>
</ul>
</div>
<div class='content'>
<div id="portfolio" class="bigpanel">
<div id="portfolioimages">
<!--IMAGES GO HERE-->
</div>
</div>
<div id="about" class="panel">
about
</div>
<div id="testimonials" class="bigpanel">
testimonials
</div>
<div id="contact" class="bigpanel">
contact
</div>
</div>
<div class="footer">
footer is here!!
</div>
css code:
body {
background-color: '#fcf4f1';
overflow:hidden;
}
a{
text-decoration:none;
}
li{
list-style:none;
}
.banner {
position: fixed;
width: 200px;
background-color: '#ccc';
opacity: 0.8;
padding: 0;
z-index: 999;
top:20px;
left:0;
}
.content{
width:800px;
margin-left:200px;
overflow:auto;
float:left;
}
.panel {
margin-top:10px;
width: 930px;
float: left;
}
.bigpanel {
float: left;
margin-top:20px;
}
.footer {
position: fixed;
bottom: 0;
left:0;
right:0;
background:red;
margin: 10px;
}
you can scroll on content.

HTML/CSS logo placement issue

I was wondering if someone could help me out with this (probably easy) issue that I am having.
What I am trying to do is place my logo on the left side of my site but have it above the two divs which contain the social media links in the top one and the website menu (aligned to the right) in the other div. I have supplied an image of what I am trying to achieve here: http://i59.tinypic.com/155j7tt.jpg (The blue image is the shape of the logo and how I want it too look above the divs)
I am using the getskeleton framework in case that helps at all.
Currently the code for the top two divs is the following:
<div class="bars social">
<div class="container">
<div class="sixteen columns right">
<img src="_img/social/facebook.png" alt="Facebook"> <img src="_img/social/twitter.png" alt="Twitter"> <img src="_img/social/youtube.png" alt="Youtube">
</div>
</div>
</div>
<div class="container">
<div class="sixteen columns right">
<ul>
<li>Home</li>
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
<li>Link 4</li>
</ul>
</div>
</div>
Now my question is where/how do I place my code so that the logo can float above those two divs (and also hang a little below them as seen in the pic).
Everything I do either places it on top of one or the other but not both.
UPDATE:
The CSS for the full screen version is as follows:
.container { position: relative; width: 960px; margin: 0 auto; padding: 0; }
.container .columns { float: left; display: inline; margin-left: 10px; margin-right: 10px; }
.container .sixteen.columns { width: 940px; }
.bars {backgound-color:#FFF;}
.right {text-align:right;}
.bars.social {background-color:#101116; color:#FFF; height:29px; padding-top:4px; border-bottom:2px solid #063;}
Here is a way to add a logo using absolute positioning to push it up and on top of the social media links. Of course, substitute with your own logo.
http://jsfiddle.net/bzoc9vbj/
#logo {
width:64px;
height:64px;
position: absolute;
top:0;
left:0;
background-image:url('https://asciinema.org/assets/bitcoin-logo-48563026498d25219c7e2ec2b978184b.png');
}

<li> dots placed on wrong side of picture next to <li> in IE11

I have a div with a picture in it, next to this is a div with some text including some lists (li) and the dots for the li's should be on the right side of the picture, but in IE11 it's shown in the div with the picture, on the left side.
Ive made a jsfiddle to explain it better here: http://jsfiddle.net/tD8an/6/
HTML:
<div id="container">
<div id="pic">
<img src="http://www.wallcore.net/wp-content/uploads/2013/09/funny_pic_of_a_monkey-280x280.jpg"/>
</div>
<div id="text">
<b>HEADLINE</b>
<ul>
<li>Li 1</li>
<li>Li 2</li>
</ul>
</div>
</div>
CSS:
#container {
width: 700px;
float: left;
}
#pic {
width: 300px;
float: left;
text-align: center;
margin: 0 15px;
}
#text {
width: 700px;
}
Is there any fix or something I can do? Am i doing something wrong?
First thing you can do is changing the position of the bulletpoints to inside. I don't see any downsides here.
ul {
list-style-position: inside;
}
Alternatively you could create a new block formatting context with overflow. But the text will not flow around the image then.
#text {
overflow: hidden;
}
<ul> is not a valid child element of <p>
Also, your widths are incorrect.
The container is 700px, but the pic is 300px and the text is 700px, so overflow issues are expected.
Setting the width of the text to 370px and float:left is one solution.

Inline-block parent not collapsing to child width

I'm using inline-block elements instead of floats to have a responsive box grid. When the elements are inline, the wrapper width works fine. When they shift to being vertical, the width of the wrapper expands to the width of its container instead of collapsing to the child width. Is there any hope for this?
Here's the code:
HTML:
<div class="container">
<div class="wrapper">
<div class="item item1">
<img src="http://www.noupe.com/wp-content/uploads/trans/wp-content/uploads/2010/07/th_IMG_1826s.jpg" />
</div>
<div class="item item2">
<h2>Text Div</h2>
<ul>
<li>Item one</li>
<li>Item two</li>
</ul>
</div>
</div>
CSS:
img {
width: 325px;
height: auto;
}
div.container {
display:block;
width: 100%;
max-width: 1000px;
}
div.wrapper {
display: inline-block;
background: #544;
text-align: center;
padding: 15px;
}
div.item {
display:inline-block;
width: 325px;
}
If I remove the img div, the wrapper works perfectly. I feel like I'm missing something very obvious.
EDIT: Forgot the jsfiddle: http://jsfiddle.net/U3hus/13/
It's to do with the container being a fixed width and the wrapper not have a width specified. You should specify a width for the wrapper to solve the problem.
.container {
width: 1000px;
}
.wrapper {
display: inline-block;
background: #544;
text-align: center;
padding: 15px;
width: 100%;
}
Rough Example: http://jsfiddle.net/U3hus/13/
Due to the wrapper element having display:inline-block, it will expand to fill the available space. Also as know width, or max-width, is set for the wrapper it will use all the available space. The best way to resolve this would be to use media queries to set a width on your wrapper element

Make div expand only horizontally when more floating divs are added to it

I am trying to make a div that contains other floating divs to adjust its width such that adding more floating divs (dynamically using jQuery) will only expand the div in its width, not allowing the floating divs to create a new line. Therefore, I want to fix this issue such that each div with class grid-row only expands in width, and so I will be able to scroll using the overflow: scroll for the parent grid div. I have searched a lot for answers, and it seems that it is a famous issue. However, non of the answer solved my problem.
I am currently doing this:
<div id="grid_container">
<div id="grid">
<div class="grid_row">
<div class="module" id="experience">
Experience
</div>
<div class="header">
Google
</div>
<div class="header">
Microsoft
</div>
</div>
<div class="grid_row">
</div>
</div>
</div>
CSS:
body {
}
#grid_container {
margin: 50px auto;
width: 500px;
height: 500px;
padding: 10px;
border: black solid 1px;
}
#grid {
overflow:scroll;
height: 100%;
}
.grid_row {
clear: both;
height: 50px;
}
.module, .header{
padding: 10px;
float: left;
border: gray solid 1px;
}
You can achieve this by making the row container float and have the style "white-space: nowrap;"
http://jsfiddle.net/UeNZr/3/
EDIT
An alternative is to make each item display inline and make each grid element float. http://jsfiddle.net/UeNZr/5/.
If you're making a list, consider using the more semantic ul.
Demo
HTML:
<ul class="grid">
<li>
<ul>
<li>One Mississippi</li>
<li>Two Mississippi</li>
<li>Three Mississippi</li>
<li>Four Mississippi</li>
<li>Five Mississippi</li>
<li>Six Mississippi</li>
</ul>
</li>
<li>
<ul>
...
</ul>
</li>
<li>
<ul>
...
</ul>
</li>
</ul>
CSS:
.grid ul{
margin:10px 0;
height:42px;
width:100%;
overflow-x:scroll;
background:white;
white-space:nowrap;
}
.grid li li {
list-style-type:none;
display:inline-block;
padding:10px;
border:1px solid gray;
height:20px;
}