DIV styling problems - css

Hi I am currently working on a project that has lots of DIVs and sections and such.
I am currently having problems with my header. The search bar and the panes div are going down or going out from the "header" section when I'm trying to minimize the browser window.
Structure goes like this.
As you can see on the image above, the red part is the header and it has 3 divs inside it.
This is how it goes on the view:
<div id = "header" class = "fixed-top">
<div class = "wrapper">
<div id = "logo">
</div>
<div id = "search-box">
</div>
<div id = "panes">
</div>
</div>
</div>
The header's width is 100% and having a class of position-fixed.
The wrapper class has a width of 980px and margin is 0 auto/auto centre. I also made its position to absolute.
The logo style looks like this:
#logo {
width: 130px;
height: 45px;
float: left;
background:url(image.png);
position: relative;
margin: 4px 0 0 2px;
}
The search bar on the other hand looks like this:
#search-box {
width: 440px;
padding: 2px 8px;
float: left;
position: relative;
margin-left: 90px;
}
Lastly, the panes style is:
#panes {
float: right;
width: 170px;
height: 48px;
position: relative;
margin-right: 10px;
}
And by the way, the search-box div also have child divs. And panes div has a UL list and each LIs are floated left.
Is there anything I am missing out why this happens?
I also tried the "clearfix" but it is still happening.
Thanks.

Just Try This CSS code, it will work nice
*{
margin:0;
padding:0;
}
#header{
background-color:#ED1C24;
width:740px;
float:left;
}
#logo {
width: 124px;
height: 45px;
background:url(image.png);
position: relative;
margin: 4px 0 0 2px;
float:left
}
#search-box {
width: 420px;
margin-left:20px;
position: relative;
float:left
}
#panes {
width: 160px;
height: 48px;
position: relative;
margin-right: 10px;
float:left
}

Like this
DEMO
CSS
* {
margin: 0;
padding: 0;
}
#header {
background-color: #ED1C24;
display: table;
vertical-align: middle;
}
#logo {
width: 130px;
height: 45px;
background: url(image.png);
position: relative;
margin: 4px 0 0 2px;
display: table-cell;
}
#search-box {
width: 440px;
padding: 2px 8px;
position: relative;
margin-left: 90px;
display: table-cell;
}
#panes {
width: 170px;
height: 48px;
position: relative;
margin-right: 10px;
display: table-cell;
}

Related

make <sections> stay in place when shrinking window

I have two boxes inside my <header>-tag, which has a total width of 100%. When i align them up they fit perfect, but when i'm shrinking the window the right box jumps down beneath the left one. Here's the code:
header {
width: 100%;
height: 90px;
}
#head {
float: left;
background-image: url('img/header.jpg');
height: 120px;
margin-right: 10px;
width: 65%;
}
#userinfo {
float: left;
height: 100px;
width: 33.2%;
background-color: #202020;
padding: 10px;
position: relative;
}
<header>
<section id="head">
</section>
<section id="userinfo">
test
</section>
</header>
Any quick fixes? Imagining this happens with the rest of my design as I'm moving forward. Thanks in advance.
The problem here is you are using some values for padding and margin on your elements and those by default are added to the actual size of the element, since both elements are 98.2% of the container +20 of the values at some point they don't fit into the 100% and will break.
To solve it you can use box-sizing property which will make the padding and border values be inside the total declared size, and since that doesn't work with margin you will need an extra container to use padding and create the separation:
header {
width: 100%;
height: 90px;
}
#head {
float: left;
box-sizing:border-box;
padding-right: 10px;
width: 65%;
}
#head > div {
background-image: url('http://placehold.it/500');
height: 120px;
}
#userinfo {
box-sizing:border-box;
float: left;
height: 100px;
width: 35%;
background-color: #202020;
padding: 10px;
position: relative;
}
<header>
<section id="head">
<div></div>
</section>
<section id="userinfo">
test
</section>
</header>
Thanks DaniP, that solved it. But what about the content and sidebars part then?:
#container {
margin: 30px auto;
width: 70%;
min-height: 400px;
}
#leftmenu {
float: left;
box-sizing: border-box;
width: 20%;
min-height: 600px;
background-color: #202020;
}
#content {
float: left;
box-sizing: border-box;
width: 60%;
background-color: #202020;
min-height: 600px;
}
#content > div {
background-color: #202020;
min-height: 600px;
}
#rightmenu {
float: left;
box-sizing: border-box;
width: 20%;
min-height: 600px;
background-color: #202020;
}

Element Width Between Float Elements

I'm a noob to web dev and have a question:
I have a container that contains 4 inline elements: two buttons floating to the left, one button floating to the right, and a search box in the middle. The buttons have predefined dimensions (percentages of the container). I am trying to avoid giving the search box a predefined width, instead I would like the width of the search box to occupy as much space as it can between the floating elements on each side (refer to photo) such that it is more dynamic.
Is there any width setting technique to achieve this? I've tried adding all 3 buttons in HTML before adding the search box and then I've tried using the margin-left and margin-right value to hopefully stretch the search box. I've had no luck with this. Any help?
HTML
<div class = "SearchBox">
<input type="image" src="./Home Page Resources/ChapterIcon.png" onclick="alert('Trigger Upload Page')">
<input type="image" src="./Home Page Resources/UserSearchIcon-2.png" onclick="alert('Trigger Upload Page')">
<input type="image" src="./Home Page Resources/SearchIcon-2.png" onclick="alert('Trigger Upload Page')">
<input type="text" name="search">
</div>
CSS
.SearchBox {
display: inline-block;
position: relative;
float: right;
min-width: 35%;
height: 40px;
border: thin solid #80501F;
background-image: url("../Home Page Resources/WoodBackground-2.jpg");
border-top-right-radius: 5px;
border-top-left-radius: 5px;
}
.SearchBox input:nth-of-type(1) {
position: relative;
float:left;
width: 35px;
top: 3px;
margin-left: 1%;
margin-right: 0%;
}
.SearchBox input:nth-of-type(2) {
position: relative;
float: left;
width: 38px;
top: 0px;
margin-left: 0%;
margin-right: 0%;
}
.SearchBox input:nth-of-type(3){
height: 25px;
display: inline;
float: right;
position: relative;
top: 8px;
margin-left: 1%;
margin-right: 1%;
}
.SearchBox input:nth-of-type(4){
display: inline;
padding-left: 5px;
height: 25px;
font-family: 'Arial Black';
font-size: 100%;
margin-left: auto;
margin-right: auto;
width: auto;
position: relative;
top: 4px;
border-bottom-right-radius: 5px;
border-bottom-left-radius: 5px;
border-top-right-radius: 5px;
border-top-left-radius: 5px;
}
You could use a combination of display:table on a container and display: table-cell on each nested element.
For example, here's the HTML:
<div class="content">
<ul>
<li class="icon"> </li>
<li class="icon"> </li>
<li class="search"><input type="text"></li>
</ul>
</div>
And CSS:
.content {
width: 600px;
background: green;
}
ul {
background: gray;
display: table;
margin: 0;
padding: 10px;
width: 100%;
}
li {
list-style: none;
display: table-cell;
margin: 0;
padding: 0;
}
li.icon {
background: red;
width: 10%;
}
li.search {
width: 80%;
}
li.search input {
border: 0;
width: 100%;
}
Here's a JSFiddle to demonstrate: http://jsfiddle.net/mknkz32p/

css content goes out of div

Hi I have page http://rygol.cz/qlife/ and when Iam zooming out the content goes out of his div. If i you height: auto; or height: 100% its ok but leftcolumn is smaller then right, clear doesnt help me.
Have anybody some idea how to fix it?
#leftcolumn {
color: #333;
background: #fff;
background-image:url("./images/corner.png");
background-repeat:no-repeat;
padding: 10px;
height: 800px;
width: 244px;
float: left;
}
#rightcolumn {
float: right;
color: #333;
background: #fff;
padding: 10px;
height: 800px;
width: 638px;
display: inline;
margin-bottom: 10px;
}
If you need that extra space between header and the content you should just go ahead and place the #leftcolumn and #rightcolumn in an additional wrapper container with the background-color set and have the #container without the background-color set.
HTML structure:
<div id="container">
<div id="header"></div>
<div id="content-wrapper">
<div id="leftcolumn"></div>
<div id="rightcolumn"></div>
</div>
</div>
And CSS:
#container {
margin: 0 auto;
width: 922px;
}
#header {
color: #333;
background: #fff;
width: 902px;
padding: 10px;
margin-bottom: 10px;
height: 200px;
}
#content-wrapper {
background-color: #fff;
min-height: 1px;
overflow: hidden; /* clear hack :) */
}
#leftcolumn {
color: #333;
background: #fff;
background-image: url("./images/corner.png");
background-repeat: no-repeat;
padding: 10px;
width: 244px;
float: left;
}
#rightcolumn {
float: right;
color: #333;
background: #fff;
padding: 10px;
width: 638px;
margin-bottom: 10px;
}
Remove the height declarations in the columns. You could also use overflow-y: scroll though I would stick to removing the heights. Another thing to consider is that people generally don't zoom out that far anyway: the text becomes impossible to read at the zoom level it breaks at (chrome v24).
If you want equal height columns have the shorter column floated to one side then set position: relative and top: 0; bottom: 0; then set the other column to have overflow: hidden; to 'clear' the float. Note: the floated column should come first in the markup for this to work.

div template with 3 random size columns and bottom

I use this template
<style>
#block_center{
position: absolute;
right: 210px;
left: 210px;
text-align: left;
border: 1px solid #000;
overflow: auto;
height: auto;
}
#block_right{
width: 200px;
border: 1px solid #000;
position: relative;
right: 3px;
text-align: left;
float: right;
}
#block_left{
position: relative;
left: 3px;
width: 200px;
border: 1px solid #000;
text-align: left;
float: left;
}
#block_content{
clear: both;
float: none;
width: 100%;
text-align: center;
overflow-y:auto;
overflow-x:auto;
height: auto;
/* margin-bottom: -50px; */
margin: auto;
}
#block_buttom {
background-color: blue;
/* z-index: -10; */
width: 100%;
height: 50px;
clear: both;
}
.clear {
clear:both;
overflow:hidden;
}
</style>
<div id="block_content">
<div id="block_center"> ARTICLE <br> article_ajax_content </div>
<div id="block_right"> Artile links </div>
<div id="block_left"> banner </div>
<div class="clear"></div>
</div>
<div class="clear"></div>
<div id="block_buttom"> some text info about site and 31px height img </div>
Problem that I having is that Article not only can be random height size but also there is ajax block of random size content going after it and I simply can't absolutely stick bottom div to stay in bottom after all content regarding browser window size, content size, ajax block size...
Can any one help me with how css (I do not want to use jQuery to pin bottom block to a fix y coordinate) should look like for my pattern of use?
Make all blocks relatively positioned and give the heights and widths using percentage rather than pixels.
Make sure the sum of all your height percentages is 100%(in case you want to cover the whole screen).
This ensures your page content covers the whole screen, irrespective of the screen resolution.
The relative sizes of each block is also kept the same across all resolutions.
The key is to use PERCENTAGE values and not PIXEL values.
To solve the Dynamic sized article data, just CSS the article div to have a scroll bar.
this is currently does want i want
<style>
#block_buttom {
margin-top: 10pt;
/* z-index: -10; */
width: 100%;
display: inline-block;
height: auto;
clear: both;
}
.page-buffer {
padding-top: 50px inherit;
height: 50px;
clear: both;
width: 100%;
}
.clear {
clear:both;
font-size:0;
overflow:hidden;
}
#block_content {
width:100%;
text-align:center;
}
#block_left {
position: relative;
top: 0px;
text-align: left;
float:left;
width: 10%;
min-width:210px;
height: auto;
padding: 3px;
}
#block_center {
text-align: left;
display: inline-block;
margin:0 auto;
width:70%;
min-width: 640px;
height: auto;
padding: 3px;
}
#block_right {
position: relative;
text-align: left;
float:right;
width: 10%;
min-width:210px;
height: auto;
padding: 3px;
}
</style>
on high resolution it looking very nice, on lower - still require some tuning with finding balance of center block size and spaces between fixed size left\right blocks

Trying to get three divisions side by side

Here is my current code but i don't see what the problem is. I'm new to html so i'm not really sure. I'd like to have a column on the left at about 20% space, column in the center which takes 60% of the space and column on the right that takes 20% space.
#wrapper {
background-color: #788D9A;
padding-bottom: 1000px;
margin-bottom: -1000px;
}
#mainleft {
width: 20%;
float: left;
padding: 10px;
text-align: center;
background-color: #ABB8C0;
padding-bottom: 1000px;
margin-bottom: -1000px;
border-right: solid black;
display:inline-block;
}
#maincenter {
width: 60%;
float: left;
overflow: hidden;
text-align: center;
padding: 10px;
padding-bottom: 1000px;
margin-bottom: -1000px;
display:inline-block;
}
#mainright {
width: 20%;
float: left;
padding: 10px;
text-align: center;
background-color: #ABB8C0;
padding-bottom: 1000px;
margin-bottom: -1000px;
border-right: solid black;
}
You need to be mindful when using padding-left padding-right margin-left margin-right border-left and border-right when you want that type of layout.
Each of those styles affect the overall width of that element so adding a padding: 10px will actually make your div width = 20% + 20px.
If you want to have that inner padding and border style an inner div
Example: http://jsfiddle.net/b62Ju/2/
HTML
<div id="wrapper">
<div id="mainleft">
<div>L</div>
</div>
<div id="maincenter">
<div>C</div>
</div>
<div id="mainright">
<div>R</div>
</div>
</div>​
CSS
#wrapper {
background-color: #788D9A;
}
#wrapper > div
{
height: 1000px;
float: left;
text-align: center;
}
#mainleft {
width: 20%;
background-color: #ABB8C0;
}
#maincenter {
width: 60%;
}
#mainright {
width: 20%;
background-color: #ABB8C0;
}
#maincenter > div
{
height: 1000px;
border-left: solid black;
border-right: solid black;
}
#mainleft > div,
#maincenter > div,
#mainright > div
{
padding: 10px;
}
Alternatively you could use the box-model styles:
.box
{
box-sizing: border-box;
ms-box-sizing: border-box;
webkit-box-sizing: border-box;
moz-box-sizing: border-box;
}
more info: http://www.quirksmode.org/css/box.html
The display: table properties seem like the best choice here. You get your equal height columns (I assume that's what the crazy bottom margin/padding was for), no extra markup, and padding without having to worry about adjusting the box-model (learn more about the box-model here: http://css-tricks.com/the-css-box-model/).
http://jsfiddle.net/b62Ju/3/
#wrapper {
display: table;
width: 100%;
}
#wrapper > div
{
display: table-cell;
padding: 1em;
}
#mainleft {
width: 20%;
background-color: orange;
}
#maincenter {
width: 60%;
}
#mainright {
width: 20%;
background-color: green;
}
For your Reference if we need to place three dives side by side,
HTML:
<div class="main">
<div class="left">...</div>
<div class="center">...</div>
<div class="right">...</div>
</div>
CSS:
.main {
width: 1000px;
float: left;
display: inline-block;
}
.left {
width : 20%;
float: left;
display: inline-block;
}
.right {
width : 20%;
float: left;
display: inline-block;
}
.center {
width : 60%;
float: left;
display: inline-block;
}
it will work.
I think in your code you need set width for main wrapper div.

Resources