putting blocks of nav side by side vertically - html

I have Some dynamic size of nav with fix size of width: 25%; in a 100% page width.
<nav class="football fig1">
<header>Header</header>
<article>
<h3>P1</h3>
<img src="">
<p>This is a first News</p>
</article>
</nav>
you can see my code here.
because of dynamic length of nav, there is some blank space between P1 and P4. please help me to delete theme for all of blocks with css.
Also what is the problem with the code that 4 of blocks are not in a row?!

The reason you aren't fitting 4 divs across is because your display setting is inline-block. This creates some padding between the elements that you aren't in control of. Replace that with a float and all is solved:
nav {
display: block; <--this changed from inline-block
float: left; <--this line added
vertical-align: top;
margin-bottom: 4px;
overflow: hidden;
box-shadow: 0 0 2px #888;
}
Now the divs are hard up against each other, consuming exactly 100% of the width. If you want a margin between you will need to factor that in, i.e.:
nav {
display: block;
float: left;
vertical-align: top;
margin-bottom: 4px;
overflow: hidden;
box-shadow: 0 0 2px #888;
margin-left: 0.5%;
margin-right: 0.5%;
}
Since I have added 1% of margin, you would adjust the width to 24% to compensate. If you don't want the half-margins on the left and right you will have to get creative with :last pseudo classes, or add a last-column class to it.
As to the other part of the question, I suspect that unless you restructure your code that they will always line up at the top (I could be wrong). You could combat this by re-ordering the divs if you know that there will always be 4 across:
<div class='container-col'>
<div id='col1'></div>
<div id='col5'></div>
</div>
<div class='container-col'>
<div id='col2'></div>
<div id='col6'></div>
</div>
<div class='container-col'>
<div id='col3'></div>
<div id='col7'></div>
</div>
<div class='container-col'>
<div id='col4'></div>
<div id='col8'></div>
</div>
CSS:
.container-col {
float: left;
}
So now we have 4 vertical columns floated side-by-side, and the divs will stack with no space between them vertically. Here is a fiddle showing the result, which keeps the margins too.

Related

CSS DIVs Break On Zoom

I have been struggling with this for over 4 hours now and I can't figure this out.
Usually when I design a site I always have it centered so I never face the problems were divs break out of the layout.
ISSUE 1
I have a sidebar on the left, followed by a content block and then a sidebar on the right.
Each sidebar should be 180px wide and the content block should fill the empty space between those two sidebars.
I can't even get them to float next to eachother now, I could do so before but I am really getting crazy.
Even if I do get them to float next to eachother, when I zoom in the page the content block breaks layout and falls down below the left sidebar it is so super annoying I never had this issue before.
ISSUE 2
The div Block at the header should automatically size between the two logos, similar to what i need for the content_wrapper, how can i do this?
Can someone help me please?
Thanks
HTML
<div id="header">
<div id="left_logo" class="logo"></div> <!-- Logo on the Left -->
<div id="block">This is a block</div> <!-- Div block inbetween the two logos -->
<div id="right_logo" class="logo"></div> <!-- Logo on the Right -->
</div>
<div id="content_wrapper">
<div id="left_sidebar" class="sidebar">Left Sidebar</div>
<div id="middle_content">Middle Content</div>
<div id="right_sidebar" class="sidebar">Right Sidebar</div>
</div>
CSS
html,body {
height:100%;
}
body {
background-image: url('../bg.jpg');
}
#header {
width: 100%;
border: solid 1px;
overflow: hidden;
}
.logo {
width: 180px;
height: 180px;
background-image: url('../avatar.jpg');
border: solid 1px;
}
#block {
border: solid 1px;
float: left;
}
#left_logo {
float: left;
}
#right_logo {
float: right;
}
#content_wrapper {
width: 100%;
}
.sidebar {
width: 180px;
float: left;
}
#middle_content {
min-height: 500px;
width: 100%;
float: left;
}
There are several points to note
move the #right_sidebar before the #middle_content
#right_sidebar must float right not left
#middle_content must not float and not have width: 100%
if you want to have the #middle_content in its own column, i.e. not float below the left and right sidebar, add margin-left and margin-right
The same applies to #header.
See JSFiddle for how this could look like.
Although it's several years old, there's a nice overview of basic layout schemes with CSS at http://www.thenoodleincident.com/tutorials/box_lesson/boxes.html

How do I center align a div that contains floated elements?

I need inner_holder to have width of 960px and I need it to be centered. I tried using width: 960px and margin: 0px auto but it doesn't work. How can I center the divs inside inner_holder?
HTML:
<div class="parent_container">
<div class="inner_holder">
<div class="column column1">
<div class="inner_clip"></div>
</div>
<div class="column column2">
<div class="inner_clip"></div>
</div>
<div class="column column3">
<div class="inner_clip"></div>
</div>
</div>
</div>
CSS:
.parent_container {
 height: auto;
     margin: 15px auto;
     min-height: 500px;
     width: 960px;
}
.column {
float: left;
margin-right: 50px;
}
.inner_clip {
background-color: #333333;
height: 250px;
margin-bottom: 20px;
width: 250px;
}
As you can see here the "div that contains floated elements" is actually in the center (red).
I am assuming you want to center the floating elements themselves, not their parent. I'm afraid you can't do that (as far as I know). But in case you are not depending on your elements actually floating, you propably just want to display your .colum as inline-block with an text-align:center set to the parent.
Changes to your CSS:
.parent_container {
text-align:center; // added
}
.column {
display: inline-block; // added
margin: 0 25px; // added
float: left; // removed
margin-right: 50px; // removed
}
Result as Fiddle
I beat my head trying to figure this out forever.
The answer above about assigning "display:inline-block" to the elements in the div, and then assigning "text-align: center" to the parent div works
BUT BUT BUT... I had a class of "clearfix" on my parent div that apparently was mucking the whole thing up. As soon as I removed that clearfix class everything centered nicely (after hours of futile frustration, of course;).
Hope this helps someone.

How to centralise content on a website by wrapping it?

I have a website I am working I am struggling to center all of my content. Why won't the header center?
I tried the usual method of margin-left and right: auto; but it didn't work so I did the following by using this:
<div class="header-wrapper">
<div id="wrap">
<!---start wrap 960px--->
<h1>TITLE</h1>
<div class="box-full">
<h2>Our Cloud Development</h2>
<p>Welcome to company Feel free to follow us on twitter. We are a new company, focused on business development.</p>
<div class="button">
Learn More
</div>
</div>
</div>
</div> <!---end wrap 960px--->
But it is pushing to the right.
You have specified width of 960px for your .box-full <div>. Because you have also specified padding, you're extending beyond that 960px wrapper.
Change the width to: 960-30-30 = 900:
.box-full {
background: none repeat scroll 0 0 #F2F2F2;
border: 1px solid #CCCCCC;
border-radius: 7px 7px 7px 7px;
clear: both;
left: 0;
margin: 1cm auto 0;
padding: 30px;
position: relative;
text-align: center;
width: 900px;
}
On your site, the div#wrap element is actually 900px wide, not 960px. That in consideration, THAT div is actually centered as well. The thing that makes it not look centered, is the fact that the div.box-full element is 1022px wide (960 + 30(padding-left) + 30(padding-right) + 2(border left and right)) = 1022. Take the width of that .box-full element and set it to 898px and see if that makes it look right!

CSS/HTML 2x2 Grid Issue

This question has come up similarly before, but I have looked around and can't find this happening to anyone else.
I can make a 4x4 grid of divs together with images using in the HTML but one of the divs I want text in (top right). When I enter <p>Some text</p> within that div it goes below the div to the left and the bottom two are still aligned and under the moved text div.
I have tried making the height fixed but nothing changed, the div just moved up but the others remained where they were.
CSS:
/* Page Content */
.container
{width: 910px;
height: auto;
margin: 0px auto;
padding-top: 35px;
position: relative;}
/* Home Page Content */
.gridblock, .gridblock2, .gridtext
{width: 450px;
height: 200px;
padding: 0px;
position: relative;
display: inline-block;}
.gridblock
{margin: 2px;}
.gridblock2, .gridtext
{margin: 3px, 0px, 3px, 0px;}
.gridtext
{width: 450px;
height: 200px;
position: relative;
background-color: #f9f9f9;}
HTML:
<div class="container">
<div class="gridblock">
<img src="images/homegrid1.jpg" alt="3345 Mastering">
</div>
<div class="gridtext">
<p>Some Text</p>
</div>
<div class="gridblock">
<img src="images/homegrid2.jpg" alt="3345 Mastering">
</div>
<div class="gridblock2">
<img src="images/homegrid3.jpg" alt="3345 Mastering">
</div>
<ul class="footer">
</ul>
This is an online demo: http://jsfiddle.net/saidbakr/2LCwg/
If I'm getting your question right, the problem seems to be with the property display:inline-block.
Add vertical-align:top to your .gridtext class:
.gridtext {
vertical-align:top;
}
It should fix it. Here's a working fiddle.
And here's an interesting article about the display:inline-block property.
Alternatively, you could remove the display:inline-block property (your divs would then, by default, be displayed as block) and give them floats instead:
.gridblock, .gridblock2, .gridtext {
width: 450px;
height: 200px;
padding: 0;
position: relative;
float:left;
}
Also, as you are working with images, you could add overflow:hidden to the above classes, to make sure those images won't expand out of its container and mess up the grid.
.gridblock, .gridblock2 {
overflow:hidden;
}

Center content inside a div

I have the following markup. I am trying to have "Previous" all the way to the left, "Next" all the way to the right, and the numbers centered. I can't seem to get the numbers centered.
I tried margin: 0 auto; on .numbers to no avail. The closest I've come was to set the left margin on .numbers to something like 40%, but that seems hackish, because previous and next might not always be there, and there may be more or less than 4 numbers. I'm pretty flexible with the markup and css.
http://jsfiddle.net/dcsUc/15/
<div id="content">
<div class="pagination">
<div class="previous">Previous</div>
<div class="numbers">
1
2
3
4
</div>
<div class="next">Next</div>
<div class="clear"></div>
</div>
</div>​
And
#content {
width: 100%;
border: 1px solid #000;
}
.previous, .numbers {
float: left;
}
.next {
float: right;
}
.clear {
clear: both;
}
​
Move div.next to before div.numbers in the markup, don't float .numbers, and apply text-align: center to .numbers.
jSFiddle for those who don't think in css ;)
If you want to use "margin: 0px auto" you also have to set a width for the div.