Good Morning,
I am developing a four column footer using pure CSS, but I have ran into some issues:
1) I can't institute a vertical 1px white rules alongside each colum
2) The background does not cover the entire four colums
3) In Chrome, the columns do not appear across a single width, the fourth one being bumped below.
Here is my code: http://jsfiddle.net/eLzPk/
If you know the exact width of the footer you can do this with pure css. I just added a right border to the first 3 columns. FYI you forgot to declare the color of the border in your css. I also changed the width of the columns to 235px which is 940 / 4. First 3 have a 1px border so it's width: 234px plus the border. Here is the fiddle http://jsfiddle.net/eLzPk/7/
#footer dl {
background: black;
float: left;
margin: 0;
padding: 10px 0 5px 0;
width: 234px;
border-right: 1px solid #fff;
}
#footer dl + dl + dl + dl {
width: 235px;
border-right: none;
}
EDIT
To further explain one of the problems with css is that with borders and margins are added to the declared width, so if you have four columns with a width: 25% and a border of 1px to create a dividing line, it's actually 100% + 3px, which of of course larger than 100% so it causes the css to wrap.
There are 2 new solutions to this in css, one of them is fairly supported, it's called box-sizing, here is a good article to reference. http://css-tricks.com/box-sizing/ Basically it sizes the box to the declared width and adds the borders and margin inside of that. The downside is that it's not supported by IE7 and back. So to use it properly it's best to use an IE conditional statement and implement some css/js hack for just those browsers.
The other solution is the flexbox model, and it has very little support yet. But it's worth taking a look at. It allows you to have a container of any size, and size the children inside of it using ratios, to place them vertically or horizontally with ease, etc. It solves the box model issues as well as positioning and centering issues of all kinds.
How about something like this? Adding another Div Container with a fixed size inside of one that will adjust to the size of the browser. The Background can then be stretched using the commented code in #footer. You have to be aware of your margins, padding & borders when creating div sizes.
Every pixel counts ;)
Anywho hope this helps! Link for jsFiddle at bottom
#footer {
background: black
/* This would be your Background Image code for whole Footer.
background: url(FOOTER IMAGE) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
*/
padding-right: 15px;
position: relative;
min-height: 250px;
text-align: center;
width:100%;
margin-left:auto;
margin-right:auto;
} /*IE6*/
#footerContainer {
width:940px;
height:250px;
display:block;
}
#footer dl {
display:inline-block;
background: black;
float: left;
text-align: left;
margin: 0px;
padding: 10px 0 5px 10px;
width: 224px; /* Take into account the 1px Border & padding*/
height:inherit;
border-left: 1px solid white;
}
Something like this: http://jsfiddle.net/GFargo/eLzPk/1/
As ACJ mentioned:
The border width (1 pixel) is added to the width, so four times 25%
plus 4 pixels is always more than 100%
You're better off defining a few set values to solve this.
Your shorthand border property was not working because although you defined a width (1px), its type (solid), you were missing (color).
If you're also working in HTML5, you can use the tag too...
Roughly, with some tweaking:
http://jsfiddle.net/eLzPk/8/
Related
better way of making a vertical divider in a centre of 2 divs. I want the divider to be in middle the "why choose" and "gallery"
like my example
This is what I've tried but if you have a better solution than this that'd be great. Giving 75px padding seems ok but I don't think its the best practice.
.why-choose-us{
padding: 0 10px;
width: 500px;
float: left;
ul li{
list-style-type: none;
margin-left: -30px;
line-height: 2;
clear: both;
}
}
.gallery{
width: 400px;
float: left;
padding-left: 75px;
border-left: 1px solid #c1c1c1;
img{
border-radius: 3px;
padding: 5px
}
}
So if divs are 400px each then few more px are still available for the divider, so let say .
http://jsfiddle.net/21g2Lona/1/
May be use CSS multicolumn layout?
-webkit-column-count: 2;
You would just need to place all the markup in one column, let the CSS create the separator for you.
PS: You would need to use appropriate vendor prefixes along with -webkit.
I am a huge fan of the CSS flexbox module for these kinds of layouts. You can read about it here. It's currently supported by 86% of the browsers people use according to http://caniuse.com/#feat=flexbox.
To make it show up correctly in all browsers you can use fallbacks and prefixes.
However, your solution is also fine. I just would use margin instead of padding if you're doing it this way. And of course, using float for these kinds of major layouts can lead to many problems and could require lots of additional CSS rules to fix.
I'm a fan of using box-sizing: border-box sizing whenever you need to divide a page vertically and include padding, margings, or borders.
The default box-sizing is content-box which will apply the width rule only to the content of the element--if borders, padding, or margin are added they will be in-addition to the width. border-box changes this so the width rule applies to the entire element--if borders, padding, or margin are added they will not increase the element's size, but rather consume space within the element.
Here's an updated Fiddle: http://jsfiddle.net/21g2Lona/5/
Here's the salient bits:
section {
float: left;
padding-left: 10px;
width: 50%;
box-sizing: border-box;
}
.gallery{
float: left;
border-left: 1px solid #c1c1c1;
...
}
The section rule does pretty much everything but add the border. The key bit is the combination of box-sizing: border-box and width: 50%. Together they mean that each <section> will be 50% of the width of their parent element, and that their width includes their border, margin, and padding. Regular box-sizing uses content-box, in which case the width rule applies only to the content--adding any padding, border, or margin will further widen the element's overall size on page.
I want to create the layout of this textbox:
The one for email (or where he's writing his phone number) using HTML5 and CSS3.
The problem is the requirements for this textbox:
it has to be responsive (width: 100%)
I don't want anything on hover (no need for the bottom border to become blue)
I don't want to use JavaScript
Any suggestions? I tried several ways but I'm always having problem.
The problem you were having is that an element's width is composed of the defined width plus the padding (of both sides) and the border-width (of both sides).
To work around this, in compliant browsers, use the box-sizing property set to border-box (which includes the padding and border-width inside the defined width), therefore:
.textbox{
border: 0;
border-bottom: 1px solid rgb(160,160,160);
background-color: transparent;
width: 100%;
margin-left: -1px;
margin-right: -1px;
/*padding-left: 5px;*/
float: left;
}
Needs to have the following added:
.textbox {
/* the above not changed, the following added */
padding-left: 2em; /* an arbitrary dimension to demonstrate, adjust to taste */
box-sizing: border-box;
}
JS Fiddle demo.
References:
box-sizing.
I have a div with these properties
#content {
background-image: url('img/cbg.png');
background-position: center top;
background-repeat: repeat-y;
width: 960px;
margin: auto;
padding-bottom:50px;
margin-bottom: 20px;
}
The background only shows up for 70px (I think) and then stops, then the rest of the stuff inside the div just goes on down the page like normal. If I set display:inline-block, it works correctly but uncenters my div.
If you have elements in the container which are floating, it's possible that the floats aren't properly being cleared. If this is your problem there are a bunch of work-arounds - they're called "clearfixs".
One of my favorite write-ups was here. The css they used in this example was here.
div.container {
border: 1px solid #000000;
overflow: hidden;
width: 100%;
}
div.left {
width: 45%;
float: left;
}
div.right {
width: 45%;
float: right;
}
Well, you're doing repeat-y which means it'll only repeat vertically. If the background image is 70px, that would support the issue. Either use repeat-x or just repeat.
It wouldn't expand any longer because you have set your #content width to 960px in your browser window.
In the case of your image expanding only up to 70px, it is probably because that's the actual height of the image you've used. but mistakenly used repeat-y (repeat vertically).
Here's a simple concept in background-repeat:
If you want to repeat the image vertically, create an image that is horizontally wide.
If you want to repeat the image horizontally, create an image that is vertically tall.
I have a div(InnerDiv) which contains a grid with paging enabled...
After some user actions , data inside that grid will load and we will have a big grid!
The problem is when grid's data loads , overflow the div's bottom portion(InnerDiv) and some of those data get's displayed out of the div.
my css of body and html like below :
html, body
{
margin: 0; /* get rid of default spacing on the edges */
padding: 0; /* get rid of default spacing on the edges */
border: 0; /* get rid of that 2px window border in Internet Explorer 6 */
height: 100%; /* fill the height of the browser */
border:3px solid red;
}
i need 100% height of body when page loads...
OuterDiv inside body like below :
div#OuterDiv
{
position:absolute;
width: 100%;
height: 100%;
/*height: auto;*/
margin: 0px;
padding: 0px;
top: 0;
bottom: 0;
left: 0;
right: 0;
border:5px solid green;
}
InnerDiv Inside OuterDiv Is Like Below :
div#InnerDiv
{
position: relative;
width: 100px;
height: 100%;
margin: 0 auto;
background: transparent url('../Images/Blue.png') repeat scroll left top;
}
Content Inside InnerDiv Like Below :
#Content
{
position: relative;
top: 10px;
background: transparent url('../Images/Red.png') repeat scroll left top;
width: 550px;
height: 1080px; /*>>>>>>>>>>>>>>>>>>> plz see this line*/
top: 10px;
right: 10px;
padding: 7px;
border: 10px ridge #ce004e;
color: black;
}
that grid(Content) is inside InnerDiv...
EDIT 1
the below example can show my situation :
Here's an example at jsFiddle
we can not remove position:absolute of OuterDiv , by doing that height:auto or height:100% on it does not work at page start -> outerDiv should be 100% because Of InnerDiv Background and remember InnerDiv height is not 1080px at start -> it is only 200px at page load and dynamically it will change to 1080px!
i want to force yellow area (InnerDiv) to fill entire Purple Area...
also InnerDiv Should Have 100% Height Because Of It's Background At Page Start...
i know this problem is about 100% height / but how can i fix that ?
EDIT 2 :
AT LAST HERE IS MY WEB SITE :
MY WEB SITE
plz change the height of red area with firebug - so by changing it to 1080px body and OuterDiv And InnerDiv Will grow.
but at page load i want body and OuterDiv And InnerDiv 100% height.
how can i do that?
thanks in advance
You need less constraints on #OuterDiv. By specifying top, bottom, left, and right, you're locking the edges of #OuterDiv to the edges of body; and your body rule locks body to the same size as the viewport.
Try changing your div#OuterDiv rule like this:
div#OuterDiv
{
position:absolute;
margin: 0px;
padding: 0px;
border: 5px solid green;
}
Here's an example at jsFiddle
From what I could gather from your explanation and styles you basically want this:
http://jsfiddle.net/sg3s/zXSXx/
If this is correct I will also explain what is happening to each div. Else please tell me what div is behaving not as you would like and why.
By the way if possible use absolute paths (whole links) to images. Seeing how they need to fit together will help us all to find something that works for you.
Strangly enough, my website is rendering fine in Internet Explorer but fails in Mozilla based browsers.
Here is a screenshot:
Does anyone see why "right-panel" does not go all the way to the right? You can see how it is not lined up with the right edge of "top-panel":
#container
{
margin: 0 auto;
width: 750px;
background-color: #ffffff;
}
#top-panel
{
padding-left: 10px;
background-color: #000000;
text-align: left;
width: 100%;
height: 88px;
}
#left-panel
{
padding-top: 10px;
text-align: center;
background-color: #ffffff;
border-right: 1px dashed #000000;
float: left;
width: 250px;
}
#right-panel
{
background-color: #ffffff;
float: right;
width: 449px;
}
.clear
{
clear:both;
line-height:0;
}
If anyone wants to see the actual site it is: Math Relay
When you apply width:100% and use padding-left:10px also, it computes the width first, and then applies the padding, so actually your #top_panel CSS declaration is the problem. Try setting it to a fixed width for that.
it is the padding-left:10px; in the #top-panel
Set that to 0 and you'll see them line up.
Try using FireBug, that's how i found the issue.
The Padding-Left:10px is causing an extra 10 pixels to appear on the right hand side.
Along the lines of the other answers, but hopefully explaining what's happening behind the scenes, too:
The width: 100% on #top-panel refers to the width of the div's content area, excluding borders, padding and margin. Thus, when you specify both width: 100% and padding-left: 10px the width of #top-panel including padding is actually 10px + 750px (the padding plus 100% of the width of #container.)
The best solution in my opinion is to remove width: 100% from #top-panel. This will make the div take up the entire width of the parent element withut overflowing the #container.
The page looks ok in Internet Explorer since IE incorrectly includes padding and border when calculating the width of the div if the page is rendered in quirks mode. More details about this bug can be found here.
It's your #top-panel that's 10px bigger that your #container because of your padding-left: 10px;
Just add 10px to your #container and it will be good.
Remove the width: 100% from #top-panel.