Centering a page - css

I have an issue with my page centering. Everything centers correctly except the left and right border.I believe the issue is with the border-right-width:300px; border-left-width:300px; lines but I am not sure of another way to set that up. Is there another solutuion to having a left and right border that also centers with the page. Any ideas?
Here is my CSS:
body {
margin:auto;
padding: 0;
background: #FFFFFF;
font: 12px/1.4 Verdana, Helvetica, sans-serif;
font-size: 12px;
color: #000000;
border-right-style:solid;
border-left-style:solid;
border-right-width:300px;
border-left-width:300px;
border-color:#E8E8E8;
}

When you use margin:auto you must also specify a width. I think you are trying to center the contents of the body with a background #E8E8E8. Do this instead
body {
margin:auto;
padding: 0;
font: 12px/1.4 Verdana, Helvetica, sans-serif;
font-size: 12px;
color: #000000;
width: 1020px; //or anything else you want
background:#E8E8E8;
}

You cant center anything that has no width, or is the parent-div with 100% because it cant relate to anything.
If you are going to use your body you need something like this:
body{
width:980px;
height:100%:
}
what most people do is using a container or wrapper. That gives you bit more control.
.container{
width:980px;
height:100%;
position:relative;
}
as you can see I gave the container as classs and a position:relative. This allows you to use it multiple times on the same page.

You need to center div itself, something like this:
div.page {
margin: 0 auto;
}

Related

Controlling text length, without destroying center positioning

I have some body and page settings that are keeping everything nicely centered in my site, which is my objective.
However, I also have some text in the center, which currently is sprawled along the entire width of the page when it's long. Every time I try to set a css width property, like max width, it decides to go haywire with it's positioning, and land itself far left of the center.
I guess there's some issue with my overall page center positioning, and setting any type of width property to a div.
EX of things nicely centered, but sprawling text: https://www.flickr.com/photos/77598212#N03/34191523510/in/dateposted-public/
and when I try to set any sort of width:
https://www.flickr.com/photos/77598212#N03/34191523450/in/dateposted-public/
I'd appreciate any and all thoughts. Thank you. -Wilson
the css:
*{
margin:0;
padding:0;
}
body{
text-align:center; /*For IE6 Shenanigans*/
}
button {
color: #900;
font-weight: bold;
font-size: 150%;
text-transform: uppercase;
}
h1{
margin-top:20px;
font-size: 250%;
overflow:hidden; /* older browsers */
font-family: hobeaux-rococeaux-sherman, sans-serif;
}
img {
max-width:500px;
max-height:340px;
box-shadow: 1px 5px 5px grey;
border-style: groove;
border-width: 1px;
margin-top:20px;
}
#ShowText{
overflow:hidden; /* older browsers */
word-wrap: break-word;
padding-top: 100px;
font-size: 18px;
font-family: vendetta, serif;
line-height: 25px;
}
If you have a fixed width on a block element then simply give it margin: 0 auto; to center it.

How to remove a blank space on an element?

I have a h2 tag but the text isn't aligned with the left of the element as you can see on the picture.
Is it possible to remove this blank space or stick the text to the left?
Here are the CSS attributes:
h2 {
font-size: 5.2em;
font-family: UniSans;
word-spacing: 1px;
}
:** Here is a fiddle with my problem. And if there is a solution for the top blank space it would be great.
This is standard behaviour for sans-serif fonts I believe. The glyph has extra 'room' around it for ascender/decenders/serifs AFAIK.
Codepen.io example
HTML
<h1>Decent Test</h1>
<h1 class="serif" >Decent Test</h1>
CSS
* {
margin: 0;
padding: 0;
}
h1 {
font-size: 100px;
font-family:sans-serif;
word-spacing: 1px;
padding:0;
margin:0;
background: pink;
margin: 50px;
}
h1.serif {
font-family: serif;
}
You need to add margin:0 to your body and to your h2
Example : http://jsfiddle.net/LB2N5/3/
Update your CSS like below. Hopefully it will fix the issue.
body, html{margin:0; padding:0}
h2 {
font-size: 5.2em;
font-family: UniSans;
word-spacing: 1px;
margin:0px;
padding:0px;
}
DEMO
Just try to make the margin negative on your element like with -2px, you can adjust it to your Situation.

Title text wide as same as the block in CSS

I have this block:
For example: I add the text: Last News in the world.
I would like to have the width of the block as wide as the text, but the corners should still remain as a curve.
CSS:
.cat-box-title h2 {
background: transparent url(.../images/testtitle.png) repeat-y;
padding-left: 5px;
color:#5E5E5E;
float:left;
margin-right:10px;
font-size: 22px;
font-family: BebasNeueRegular, arial, Georgia, serif;
}
HTML:
<div class="cat-box-title">
title
</div>
Your solution will be more easy if you use the border-radius instead of background image.
.round-btn
{
background:#4679bd;
color: #FFF;
border-radius:5px;
padding : 10px;
border:none;
}
of-course you need to check the browser compatibility whether your browser supports this property or not. If not then you need to use some hack.
JsFiddle Demo
and if you goes with background-image solution then you need to use two images; one for left side border-radius and another one for right side and use the background-color for rest of the button.
CSS:
.cat-box-title {
background-color: #4679bd;
color:#5E5E5E;
float:left;
border-radius:5px;
margin-right:10px;
font-size: 22px;
padding: 5px;
font-family: BebasNeueRegular,arial,Georgia, serif;
}

Having trouble with css navigation bar

I have gone from this:
www.gofar.org
To this:
www.gofar.org/homepagetest.html
I have tried to remove the one block seperator on the far right end of the nav bar. I am lost.
I tried putting it in a div but what I really need to do is make the background image (green) go from the left side of the header to the edge of the right side.
Just do not know how.
here is the css
ul#saturday{
margin:0;
padding:0;
list-style-type:none;
width:100%;
position:relative;
display:block;
height:36px;
text-transform:uppercase;
font-size:12px;
font-weight:normal;
background:transparent url("bgOFF.gif") repeat-x top left;
font-family:"Palatino Linotype", "Book Antiqua", Palatino, serif;
border-bottom:4px solid #336666;
overflow: hidden;
color: #003;
text-align: center;
z-index: auto;
}
I even tried putting it in a table but it never fits across the entire header.
This may help.
/* Remove left padding from header */
.twoColFixLtHdr #header {
padding: 0 10px 0 0px;
/* padding: 0 10px 0 20px; OLD - Delete this line*/
}
/* Add left padding to ul */
ul#saturday {
padding-left: 10px;
}
/* Remove border bg from last anchor */
ul#saturday li:last a {
background-image: none;
}
Also, Read/watch these on chrome inspector tools,
you can edit the CSS live in the browser which
makes things easier for beginners and experts alike.
https://developers.google.com/chrome-developer-tools/docs/videos
you can try instead of using width:100%, change it to the width of the white container. That way it would go all the way across. Width:100% only sets it to as large as the content.

Need help/suggestions to set max-width of 1st line of h1 to avoid overlapping absolutely positioned element

Below is what my design looks like
however with a long title, it looks like
How might I avoid the overlap? I created a fiddle to allow you to work on this (if you prefer)
http://jsfiddle.net/xhp7Q/
You can put the comment link first and float it to the right. That way the header will flow around it:
http://jsfiddle.net/xhp7Q/1/
.comments {
float: right;
height: 30px;
font-size: 26px;
font-weight: bold;
border: 5px solid #eee;
color: #000;
color: red;
}
Just change position:absolute; to position:relative; in .comments and add float:right;
Then move this:
10
To the top of the p and h1 elements:
Demo

Resources