Fixed div with padding increase width - html

I have a simple template where I show header, content and footer section in the centre, Header has background color and all the contents should have 30px padding on left & right.
I dint it following way but it increases the width.
http://codepen.io/anon/pen/xZapEE?editors=1100
html, body, form {
height: 100%;
background-color: #fff;
height:100%;
}
body {
font-family: "Open Sans","Trebuchet MS",Verdana,Arial,sans-serif;
-webkit-font-smoothing: antialiased;
font-size: 13px;
line-height: 18px;
height: 100%;
margin: 0;
padding: 0;
border: 0;
color: #687074;
height:100%;
background-color: #fff;
}
.main-wrapper{
width:1000px;
margin:0 auto;
position:relative;
height:100% !important;
padding:0 30px;
}
.header-wrapper{
width:100%;
min-height:200px;
background-color:#f5f5f5;
margin:0 auto;
position:relative;
padding:0 30px;
}
.content-main{
width:1000px;
min-height:400px;
margin:0 auto;
position:relative;
height:auto;
background-color:#ccc;
}
.footer-wrapper{
width:1000px;
min-height:200px;
background-color:#f5f5f5;
margin:0 auto;
position:relative;
}
.header-row1{
float:left;
width:100%;
height:150px;
margin-bottom:15px;
}
.header-col1
{
float:left;
width:132px;
width:50%;
}
.header-col2
{
float:right;
width:50%;
}
.header-col2 > h1{
font-size:60px;
text-align:right;
}
.header-logo{
}
.header-row2{
float:left;
width:100%;
height:30px;
margin-bottom:15px;
padding:0 30px;
}

You can use box-sizing to fit it in:
box-sizing: border-box;
Box-sizing values:
content-box: This is the initial and default value as specified by the CSS standard. The width and height properties are measured including only the content, but not the padding, border or margin.
border-box: The width and height properties include the padding and border, but not the margin.

Related

Unable to Center a div

I want img_manip_header_close block to be centered, but it's not.
CSS:
#img_manip_header_close {
display:inline-block;
cursor:pointer;
width:50px;
top:5px;
text-align:center;
margin-left:5px;
margin-right:5px;
left:125px;
}
#img_manip_header {
height:30px;
width:300px;
background-color:#DEDEDE;
margin: 0 auto;
display: block;
height: 20px;
line-height: 20px;
vertical-align: middle;
}
HTML
<div id="img_manip_header">
<div id="img_manip_header_close" onclick="window.location='index.php';">Close</div>
</div>
you are missing text-align:center; in #img_manip_header
#img_manip_header {
height:30px;
width:300px;
background-color:#DEDEDE;
margin: 0 auto;
display: block;
height: 20px;
line-height: 20px;
vertical-align: middle;
text-align:center;
}
http://jsfiddle.net/KS4Z3/
Just change the css for img_manip_header_close to this:
#img_manip_header_close {
cursor:pointer;
width:50px;
text-align:center;
margin: 0 auto;
}
Fiddle: http://jsfiddle.net/82Asv/
Specifically, you need to remove margins and display:inline-block, and add margin auto.
In fact, you don't even need text-align:center here.
Updated fiddle: http://jsfiddle.net/82Asv/1/
Lose the width on the #img_manip_header_close and change display:inline-block to display:block
Did for trick here
Try this:
http://jsfiddle.net/TFHv4/
<div id="img_manip_header">
<div id="img_manip_header_close" onclick="window.location='index.php';">Close</div>
</div>
#img_manip_header_close
{
cursor:pointer;
}
#img_manip_header
{
background-color:#DEDEDE;
margin: 0 auto;
display: block;
height: 20px;
text-align:center;
}
#img_manip_header_close
{
//lose this -> display:inline-block;
cursor:pointer;
width:50px;
top:5px;
//lose this -> text-align:center; (from what you said you want to align center 'img_manip_header_close' div not the text from inside div)
margin-left:5px;
margin-right:5px;
left:125px;
}
#img_manip_header
{
text-align:center; //add this line, in this way you will align center the content from 'img_manip_header' which is 'img_manip_header_close' div
height:30px;
width:300px;
background-color:#DEDEDE;
margin: 0 auto;
display: block;
height: 20px;
line-height: 20px;
vertical-align: middle;
}
That was the right CSS. Thanks for ideas:
#img_manip_header
{
height:30px;
width:300px;
background-color:#DEDEDE;
margin: 0 auto;
display: block;
height: 20px;
line-height: 20px;
vertical-align: middle;
text-align:center;
}
#img_manip_header_back
{
position:relative;
display:inline-block;
float:left;
cursor:pointer;
width:50px;
text-align:center;
margin-left:5px;
margin-right:5px;
}
#img_manip_header_close
{
position:relative;
display:inline-block;
cursor:pointer;
width:50px;
text-align:center;
margin-left:5px;
margin-right:5px;
margin: 0 auto;
}
#img_manip_header_next
{
position:relative;
display:inline-block;
float:right;
cursor:pointer;
width:50px;
text-align:center;
margin-left:5px;
margin-right:5px;
}

Move span to the center of footer div

I have next HTML code, I want to put copyright span to the center of footer but I am can just put them to the top center. What I need to change in my CSS ?
<div class="main">
<div class="footer">
<span class="copyright">some text block</span>
</div>
</div>
and next CSS
.main { width: 100%; height:1563px; background:url(../images/1.jpg) 50% 0 no-repeat ; overflow:hidden; position:relative;min-height:100%; }
.footer {position:absolute; bottom:0; width:100%; text-align:center; height:60px; background-color: #CDCBB8}
.copyright { font-family:"Myriad Pro", sans-serif; font-size:14px; color:#999; display: inline-block; vertical-align: middle; line-height: normal; }
set line-height:60px for copyright:
jsFiddle
.copyright {
font-family:"Myriad Pro", sans-serif;
font-size:14px; color:#999;
display: inline-block;
vertical-align: middle;
line-height: 60px; /* as the height of container */
}
or set line-height:60px to the continer like this:
.footer {
position:absolute;
bottom:0; width:100%;
text-align:center;
height:60px;
line-height:60px; /* as the height */
background-color: #CDCBB8
}
note: if you have more than one line in your copyright it is better that you set line-height:60px to the container and set line-height:1; to the copyright.
DEMO
Check it on http://jsfiddle.net/dfW66/
.main {
width: 100%;
height:1563px;
background:url(../images/1.jpg) 50% 0 no-repeat;
overflow:hidden;
position:relative;
min-height:100%;
}
.footer {
position:absolute;
bottom:0;
width:100%;
text-align:center;
height:60px;
background-color: #CDCBB8
}
.copyright {
font-family:"Myriad Pro", sans-serif;
font-size:14px;
color:#999;
line-height: 60px;
}
Set line-height to 60px.
vertical-align:middle can put into action by changing display properties of .footer and .copyright to table and table-cell, like this:
.footer{
display:table;
}
.copyright{
display:table-cell;
}
Then your vertical-align:middle will move the copyright text to vertically middle.
Write:
.footer{display:table;}
.copyright{display:table-cell;}
Fiddle here.
If it's just the text you want to center you can do:
text-align: center;
If you want to center the whole div give it a width and call
margin: 0 auto;
on it.

How can I achieve fluid margins on my site with CSS?

On my site, I have a fixed-width central wrapper, which I don't want to change in size, but I do want to margins to be resized depending on the size of the user's screen. I tried wrapping everything in one div called wrapper-outer and then centering it by margin: 0 auto but it doesn't seem to work.
Site: http://antonpug.com/mainepark/
CSS:
body {
font-family: "Nobile", sans-serif;
font-size:0.75em;
text-align:center;
min-width:1550px;
}
img#bg {
position:fixed;
top:0;
left:0;
width:100%;
height:100%;
z-index:-1;
}
h3 {
font-size:1.25em;
}
header h1, header h2 {
font-family: "Ubuntu", sans-serif;
}
header h1 {
font-size:3em;
margin:25px 0 0 0;
}
header h2 {
font-size:2em;
margin:0 0 25px 0;
}
#wrapper-inner {
margin:25px 100px 25px 100px;
padding:15px 0 15px 0;
background-color:rgba(255,255,255,0.75);
moz-border-radius: 10px;
webkit-border-radius: 10px;
border-radius: 10px;
}
#wrapper-outer {
width:1500px; -- that didn't work either!!!
margin: 0px auto;
}
#feature {
display:inline-block;
width:80%;
margin:15px;
}
.column {
display: inline-block;
vertical-align:top;
width:600px;
margin:15px;
}
#col-1 {
text-align:right;
}
#col-2 {
text-align:left;
}
.section {
margin:0 0 25px 0;
height:450px;
}
footer {
color:#909090;
}
footer a {
margin: 0 0 25px 0;
text-decoration:none;
color:#909090;
}
Remove min-width on the body. If the minimum width for the body is greater than your content wrapper, scrollbars will show before the fluid margins can do their thing.
Change the margins on div#wrapper-inner to:
margin: 25px 0; //previous values had 100px margins for left/right which add to width per box model
Finally, adjust div#wrapper-outer to the width of your content like SLaks suggested.
You need to add a fixed width to the centered wrapper.
Just add a percentage margin to your col-1 div so your margins adapt fluidly.
Something like 8% looks good.
CSS
#col-1 {
margin-right: 8%;
}
Also, remove the margin declaration on your col-2 div so your margins adapt proportionally.

Stick a DIV at TOP and middle using CSS

So far I have this:
<style>
#success_notification {
position:absolute;
top:0;
width:30%;
text-align:center;
font:20px Georgia;
color:#5C5C5C;
background:#F2FFED;
padding:10px;
}
</style>
<div style="margin:0 auto;"><div id='success_notification'>TESTING.</div></div>
and the div stays on the left... still. What am I doing wrong? Thanks.
You aren't setting left or right, causing your absolutely-positioned element to default to a left of 0. Try this:
#success_notification {
position: absolute;
top: 0;
left: 35%;
width: 30%;
text-align: center;
font: 20px Georgia;
color: #5C5C5C;
background: #F2FFED;
padding: 10px;
}
Here you go.
Removed the position: absolute, added the margin: auto to style, added width 100% to outer div. Works for me.
<style>
#success_notification {
top:0;
width:30%;
margin: auto;
text-align:center;
font:20px Georgia;
color:#5C5C5C;
background:#F2FFED;
padding:10px;
}
</style>
<div style="width: 100%; margin:0 auto;"><div id='success_notification'>TESTING.</div></div>
try this:
#success_notification {
position:absolute;
top:0;
left: 50%;
width:30%;
text-align:center;
font:20px Georgia;
color:#5C5C5C;
background:#F2FFED;
padding:10px;
}
...or even:
float:left;
...or:
float:right
this works great in all browsers

Is there a way to get a fixed width of 100% in CSS?

I am trying to make my site more scalable, and would like all of my divs to take up the whole width of the page. If not, I would like them all to be centered and 960px. The problem is that none of the divs are actually centered when I try margin-left:auto, margin-right:auto;. When I try to make the width 100%, and then try to resize the window, everything gets wacky.
Here is the site:
http://eitanrosenberg.com/newsite/index.html
Here is my CSS:
*
{
margin:0;
padding:0;
}
.everythang
{
margin-left:auto;
margin-right:auto;
}
.topbar
{
background-color:#000;
height:75px;
margin-left:auto;
margin-right:auto;
position:fixed;
width:100%;
z-index:10;
}
.logo
{
color:#FFF;
float:left;
font-family:HarabaraRegular,helvetica;
font-size:45px;
margin:15px auto 0 20px;
padding-left:100px;
position:relative;
width:160px;
}
.navbar ul
{
color:#FFF;
display:inline;
float:right;
list-style-type:none;
margin-right:25px;
margin-top:15px;
text-decoration:none;
}
.navbar ul li
{
display:block;
float:left;
margin:15px auto 0 5px;
padding-right:32px;
}
.navbar ul li a
{
color:#FFF;
font-family:HitchcockRegular, helvetica;
font-size:25px;
text-decoration:none;
}
.navbar ul li a:hover
{
color:#0CF;
}
.white
{
background-color:#F8F8F8;
background-image:url(gradients/radialg_200.png);
background-position:30% 0;
background-repeat:no-repeat;
height:300px;
margin:0;
padding:50px 0 0;
width:960px;
}
.hello
{
color:red;
font-family:CoolveticaRegular, helvetica;
font-size:50px;
margin-left:auto;
margin-right:auto;
padding-top:50px;
text-align:center;
}
.hello2
{
color:red;
font-family:CoolveticaRegular, helvetica;
font-size:35px;
margin-left:auto;
margin-right:auto;
padding-top:10px;
text-align:center;
}
.hello3
{
color:#0CF;
font-family:CoolveticaRegular, helvetica;
font-size:35px;
margin-left:auto;
margin-right:auto;
padding-top:10px;
text-align:center;
}
.orange
{
background-color:#F93;
background-image:url(gradients/radialg_400.png);
background-position:30% 0;
background-repeat:no-repeat;
height:500px;
margin:0;
padding:50px 0 0;
width:960px;
}
.workbar ul
{
color:#FFF;
float:left;
line-height:25px;
list-style-type:none;
margin-left:100px;
margin-right:25px;
margin-top:100px;
text-decoration:none;
}
.workbar ul li
{
margin:2px auto 0 35px;
padding-right:32px;
}
.workbar ul li a
{
color:#FFF;
font-family:helvetica;
font-size:25px;
font-style:bold;
text-decoration:none;
}
.workbar ul li a:hover
{
color:red;
}
.red
{
background-color:red;
background-image:url(gradients/radialg_400.png);
background-position:30% 0;
background-repeat:no-repeat;
height:500px;
margin:0;
padding:50px 0 0;
position:static;
width:960px;
}
.red h2
{
color:#FFF;
font-family:Helvetica;
font-size:45px;
margin-left:100px;
padding-top:40px;
}
.red ul
{
color:#FFF;
float:left;
list-style-type:none;
margin-left:100px;
margin-right:25px;
margin-top:15px;
text-decoration:none;
}
.red ul li a
{
color:#FFF;
font-family:helvetica;
font-size:20px;
font-style:bold;
text-decoration:none;
}
.faves img
{
display:inline;
float:left;
height:50px;
padding-top:15px;
position:relative;
width:50px;
}
.faves
{
padding-top:25px;
}
.faves h2
{
display:inline;
float:left;
margin-top:25px;
padding-top:15px;
}
.lists
{
margin-top:100px;
}
.list1
{
float:left;
width:320px;
}
.list2
{
float:left;
width:320px;
}
.list3
{
width:320px;
}
.gray
{
background-color:#2e3031;
background-image:url(gradients/radialg_400.png);
background-position:30% 0;
background-repeat:no-repeat;
height:700px;
margin:0;
padding:50px 0 0;
position:static;
width:960px;
}
.gray h2
{
color:#FFF;
font-family:Helvetica;
font-size:45px;
margin-left:100px;
padding-top:40px;
}
.resumeImg img
{
display:block;
height:550px;
margin-left:auto;
margin-right:auto;
width:900px;
}
Making an element centered using margin requires the element to have a layout. When using margin-left and margin-right, that would be the width property.
An alternate way to center your elements is :
position: absolute;
width: 800px;
left: 50%;
margin-left: -400px;
You would move the element 50% from the left and then 400px (half the width) back. This also works for heights.
Have your wrapper divs ('white', 'orange', etc) be set to width: 100%; and have your content inside (preferably in another div, set to width: 960px; margin: 0 auto;:
.white, .orange {
width: 100%;
}
.white-wrapper {
width: 960px;
margin: 0 auto;
}
And use the following HTML:
<div class="white">
<div class="white-wrapper">
-- content --
</div>
</div>
In this way, your backgrounds will appropriately fill the page, and your content will float in the center and work correctly when shrinking the page. I'd recommend against dynamically changing the width of your content, as it presents readability issues (and tends to look gross), but if you really want to, try min-width:
.white {
min-width: 960px;
}
This will ensure that your divs are always at least 960px wide;
If I understand your question correctly, you want a fixed centered layout that is 960px wide UNLESS the browser window is less than 960px, then you want the layout to be full width.
To do this, wrap your entire html code in a container, like so:
<body>
<div id="container">
<!-- your code here -->
</div>
</body>
And apply this css:
#container {margin:0 auto;max-width:960px;}
Internet Explorer 6 doesn't understand max-width, so if that's a concern you could either give IE6 a fixed width of 960px:
#container {margin:0 auto;max-width:960px;}
* html #container {width:960px;} /* IE6 hack */
or force max-width in IE6 with an even uglier hack:
* html #container {width: expression(document.body.clientWidth > 962? "960px");