Common CSS problems and questions and how to solve them
Q: My text is right next to the borders on my webpage how do i fix?
A: Using padding you can fix this. The most common way:
padding-left: 3px;
Q: How can i center my webpage using CSS?
A: Using margins that have a value of auto!
margin-left: auto; margin-right: auto;
Put that in the container css code.
Q: What are floats and what do they do?
A: Well floats are a much better way to position your content boxes where you want them. There are 2 values for them:
float: left; float: right;
!
Are these better than using position: absolute and stuff? By far, sometimes there are times when you do need position: absolute though.
Q: My webpage looks fine in firefox but horrible in internet explorer! help!
A: Well in my css expirence ive encountered this so many times. Most of the time it was because of the
position: absolute
code or something along those lines. I easily fixed it using floats. Also ive encountered some problems with the codes
top: 19px; left: 19px;
. Remember those numbers are just a example.
Q: Whats the best way to position things on a website in CSS?
A: First if you want something on the left or right, use
float: left; float: right;
. Now if you want to push stuff down, up, left, right use these:
margin-top: 5px; margin-bottom: 5px; margin-left: 5px; margin-right: 5px;
. Ive never encountered problems with these. Now if you want to push text down, left, right, top you would use:
padding: 5px;
Q: How do i make a banner go across the whole screen on multiple resolutions?
A: By using the css code:
width: 100%;
. The best way to use this is to have a gradient for the background image thats 1 px wide and say 100px high.
Q: How can i position a background image?
A: Using
background-image: url('yourbg.gif'); background-position: 25%;
change those values to whatever you want.
Q: How do i repeat a background horizontally?
A: By using:
background-repeat: repeat-x;
Q: Well now how can i repeat a background vertically?
A: Use
background-repeat: repeat-y;
Q: How do i make the first letter in a sentence special?
A: By using a div code like:
<div class="whatever">Hello world! The H is special!</div>
Then use a CSS code of:
.whatever:first-letter { color: #ff0000; font-size: xx-large; }