Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Please help me solve this CSS problem! :(

Featured Replies

I have centered my web page and given it a width of just under 1000px. I have positioned a few things relative and for some reason the browser is forcing a horizontal scroll bar. When I position the elements absolute everything is fine on my 22" PC monitor (which I am building the site on) but when I view the page on my 15" laptop the absolute elements are totally out of position.

What is going on?!

 

Thanks so much.

 

The URL is www.beattieglazing.co.uk

 

Here is my CSS:

 

 

 

a:link {color:white}

a:visited {color:white}

a:hover {color:#0033AB}

a:active {color:white}

a {text-decoration:none}

 

 

img{border:none;}

 

 

 

 

 

 

body

{

margin:0;

padding:0;

padding-top:0;

text-align:center;

}

 

 

.main

{

width:980px;

height:750px;

text-align:left;

border:0px;

padding:0;

margin:0 auto;

z-index:1;}

 

 

 

 

.pic

{position:relative;

left:-08px;

top:100px;

z-index:1;}

 

 

 

.fh

{position:relative;

left:300px;

top:0px;

z-index:1;}

 

 

.para

{position:relative;

left:770px;

top:-100px;

width:200px;

height:150px;

font-family:arial;

font-size:11px;

color:white;

text-align:right;

z-index:1;}

 

 

 

 

.pic3

{position:relative;

left:0px;

top:-75px;

z-index:1;}

 

 

 

 

 

 

.pic5

{position:relative;

left:50px;

top:-125px;

z-index:1;}

 

 

 

.pic75

{position:relative;

left:600px;

top:-150px;

z-index:2;}

 

 

 

.pic95

{position:relative;

left:350px;

top:-175px;

z-index:1;}

 

 

 

.pic105

{position:relative;

left:825px;

top:-200px;

z-index:1;}

 

.pic2

{position:relative;

left:-0px;

top:-450px;

width:30px;

height:30px;

z-index:0;}

 

 

div.ex1

{position:relative;

left:0px;

top:-100px;

width:635px;

padding:10px;

border:0px solid gray;

margin:0px;

z-index:1;}

 

 

 

.bsd

{position:relative;

left:650px;

top:-475px;

z-index:1;}

  • Author

Thanks but why couldn't you answer the question? Is it too difficult? That sincerely is not meant to sound as patronizing as it does. Your help is very much appreciated.

 

Many thanks :)

It's cos you're using position:relative. Your positioning the items next to each other (in theory) and it's creating the margins.

 

I would recommend using floats instead and use position:absolute if necessary. You're just overcomplicating an easy design.

 

I try not to use positioning unless absoloutely needed e.g. a fixed item or the use of z-index.

  • Author

Thanks. You're the second person to suggest floating to me but I read on w3schools.com that floating only goes left to right and not up or down so thought it was a more primitive way of positioning elements? Also am I right in saying you cant position an element to the pixel when floating as you can with absolute and relative positioning?

 

Is floating the bread and butter of positioning to all web designers then?

 

Thanks for your help! :)

Thanks. You're the second person to suggest floating to me but I read on w3schools.com that floating only goes left to right and not up or down so thought it was a more primitive way of positioning elements? Also am I right in saying you cant position an element to the pixel when floating as you can with absolute and relative positioning?

 

Is floating the bread and butter of positioning to all web designers then?

 

Thanks for your help! :)

 

You can still use margins with floats e.g.

 

#item {
float:left;
margin-top:-222222px;
margin-left:30px;
}

 

Floating can only be done left and right, but use the margins and you can place it wherever you want.

  • Author

I just tried floating an image (which is a link to another page) to sit on top another image (which is positioned relative with a z-index:-1;) and although the floated image is visible the link no longer works?!

You should make those gradient images background images of the Divs rather than using <img> tags. So in the CSS use "background:url(location/of/image.jpg) no-repeat;"

 

You should also split things into HEADER/CONTENT/FOOTER.

 

You can use absolute positioning if you want but I don't think it's so easy for beginners. If you really want to then use this: http://headless-studios.com/960.ls - Instructions = http://960.gs

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title>Your title here</title>
<style type="text/css">
/* Containers
----------------------------------------------------------------------------------------------------*/
.container_12 {
margin-left: auto;
margin-right: auto;
width: 960px;
}

/* Grid >> Global
----------------------------------------------------------------------------------------------------*/
.grid_1,
.grid_2,
.grid_3,
.grid_4,
.grid_5,
.grid_6,
.grid_7,
.grid_8,
.grid_9,
.grid_10,
.grid_11,
.grid_12{
display:inline;
float: left;
position: relative;
margin-left: 10px;
margin-right: 10px;
}

/* Grid >> Children (Alpha ~ First, Omega ~ Last)
----------------------------------------------------------------------------------------------------*/

.alpha {
margin-left: 0;
}

.omega {
margin-right: 0;
}

/* Grid >> 2 Columns
----------------------------------------------------------------------------------------------------*/
   .container_12 .grid_1 {
width:60px;
}
   .container_12 .grid_2 {
width:140px;
}
   .container_12 .grid_3 {
width:220px;
}
   .container_12 .grid_4 {
width:300px;
}
   .container_12 .grid_5 {
width:380px;
}
   .container_12 .grid_6 {
width:460px;
}
   .container_12 .grid_7 {
width:540px;
}
   .container_12 .grid_8 {
width:620px;
}
   .container_12 .grid_9 {
width:700px;
}
   .container_12 .grid_10 {
width:780px;
}
   .container_12 .grid_11 {
width:860px;
}
   .container_12 .grid_12 {
width:940px;
}




/* Prefix Extra Space >> 2 Columns
----------------------------------------------------------------------------------------------------*/
   .container_12 .prefix_1 {
padding-left:80px;
}
   .container_12 .prefix_2 {
padding-left:160px;
}
   .container_12 .prefix_3 {
padding-left:240px;
}
   .container_12 .prefix_4 {
padding-left:320px;
}
   .container_12 .prefix_5 {
padding-left:400px;
}
   .container_12 .prefix_6 {
padding-left:480px;
}
   .container_12 .prefix_7 {
padding-left:560px;
}
   .container_12 .prefix_8 {
padding-left:640px;
}
   .container_12 .prefix_9 {
padding-left:720px;
}
   .container_12 .prefix_10 {
padding-left:800px;
}
   .container_12 .prefix_11 {
padding-left:880px;
}


/* Suffix Extra Space >> 2 Columns
----------------------------------------------------------------------------------------------------*/
   .container_12 .suffix_1 {
padding-right:80px;
}
   .container_12 .suffix_2 {
padding-right:160px;
}
   .container_12 .suffix_3 {
padding-right:240px;
}
   .container_12 .suffix_4 {
padding-right:320px;
}
   .container_12 .suffix_5 {
padding-right:400px;
}
   .container_12 .suffix_6 {
padding-right:480px;
}
   .container_12 .suffix_7 {
padding-right:560px;
}
   .container_12 .suffix_8 {
padding-right:640px;
}
   .container_12 .suffix_9 {
padding-right:720px;
}
   .container_12 .suffix_10 {
padding-right:800px;
}
   .container_12 .suffix_11 {
padding-right:880px;
}


/* Push Space >> 2 Columns
----------------------------------------------------------------------------------------------------*/
   .container_12 .push_1 {
left:80px;
}
   .container_12 .push_2 {
left:160px;
}
   .container_12 .push_3 {
left:240px;
}
   .container_12 .push_4 {
left:320px;
}
   .container_12 .push_5 {
left:400px;
}
   .container_12 .push_6 {
left:480px;
}
   .container_12 .push_7 {
left:560px;
}
   .container_12 .push_8 {
left:640px;
}
   .container_12 .push_9 {
left:720px;
}
   .container_12 .push_10 {
left:800px;
}
   .container_12 .push_11 {
left:880px;
}




/* Pull Space >> 2 Columns
----------------------------------------------------------------------------------------------------*/
   .container_12 .pull_1 {
right:80px;
}
   .container_12 .pull_2 {
right:160px;
}
   .container_12 .pull_3 {
right:240px;
}
   .container_12 .pull_4 {
right:320px;
}
   .container_12 .pull_5 {
right:400px;
}
   .container_12 .pull_6 {
right:480px;
}
   .container_12 .pull_7 {
right:560px;
}
   .container_12 .pull_8 {
right:640px;
}
   .container_12 .pull_9 {
right:720px;
}
   .container_12 .pull_10 {
right:800px;
}
   .container_12 .pull_11 {
right:880px;
}


/* Clear Floated Elements
----------------------------------------------------------------------------------------------------*/


.clear {
clear: both;
display: block;
overflow: hidden;
visibility: hidden;
width: 0;
height: 0;
}


.clearfix:after {
clear: both;
content: ' ';
display: block;
font-size: 0;
line-height: 0;
visibility: hidden;
width: 0;
height: 0;
}

.clearfix {
display: inline-block;
}

* html .clearfix {
height: 1%;
}

.clearfix {
display: block;
}

</style>
</head>

<body>

<div class="container_12 clearfix">

       <div id="header" class="container_12 clearfix">

               <div class="grid_4 ">Logo
               </div>

               <div class="grid_4 ">Heading
               </div>

               <div class="grid_4 ">Address
               </div>

       </div>

       <div id="content" class="container_12 clearfix">

               <div class="grid_12 ">
                       <ul>
                               <li>Menu 1</li>
                               <li>Menu 2</li>
                               <li>Menu 3</li>
                       </ul>
               </div>

               <div class="grid_8 ">
                       <h2>Welcome to Beattie Glazing</h2>
                       <p>Paragraph one.</p>
                       <p>Paragraph two.</p>
                       <p>Paragraph three.</p>
               </div>

               <div class="grid_4 ">Rotating Image
               </div>

               <div class="grid_12">
                       <h2>Delivering quality for over 10 years</h2>
                       <p>Paragraph one.</p>
                       <p>Paragraph two.</p>
               </div>

       </div>

       <div id="footer" class="container_12">
               <ul>
                       <li>Footer Item 1</li>
                       <li>Footer Item 2</li>
                       <li>Footer Item 3</li>
               </ul>
       </div>

</div>

</body>
</html>

From the brief look I just had it seemed like you had loads of div's too many and I did not even seen a container/wrapper div.

 

I am unsure what you are trying to achieve, are you trying to position everything in the middle?

  • Author

It is the first website I have done and I am learning as I produce it. I want to get into web design as a career and am teaching myself. So I am happy to make mistakes as long as I learn from them. I am aware it is going to take time but time is the only thing I have! I have nothing to lose.

 

So with this site I have learned that positioning absolutely can be unpredictable. I wish I could place things where I like and it would have no effect what so ever on where the next element falls. I hate the way a space is preserved when positioning relatively effecting the next element. This is giving me dead space at the bottom of my page so users have a vertical scroll bar which leads to nothing!

 

Anyway, with this site I am trying to place images of squares which I can then place paragraphs of text on top of. Nothing complicated! Just html and css. I am getting there but am having a few herdals.

 

I must say that although I just said "just" html and css, css is poving to be a bit of a bitch! :)

 

Any help is appreciated, so thankyou :)

Hey there,

 

From my humble fellow amateur point of view, I would:

 

Remove all z-index, position:absolute and position:relative. Those ways seem to get really complicated.

 

Then working left-right top-bottom

 

container (holding all the content, width, margin:auto)

 

Header: Logo 'Flashing Text' Address (three divs, float:left; using margins to space them accordingly)

 

main content: linkbar using an unordered list <ul> display: inline so they go across rather then down

 

then again two divs floated and spaced using margins,

 

then the last div with the bulk text with another unordered list <ul> at the bottom.

 

Like I said I am still trying to learn myself and some of the pros on here would be able to tell you more semantic ways of going around this, without using so many divs.

 

Best regards!

My personal opinion is, knowing what you know now (about the do's and don'ts of positioning), go about starting again from scratch using the right methods. That way you'll be able to start with a clean slate and will learn more constructively.

 

I only ever use relative or absolute positioning when absolutely necessary, never to lay out numerous page elements. You should be in the same mindset when starting off coding up a website. That way, you'll start to do things properly.

 

You should start by learning how floats work, that'll be the biggest and most beneficial hurdle to overcome, but I assure you, it will be worth it.

 

Here's a basic example of how you could (or should) go about coding a simple 2 column layout:

 

HTML:

<div id="container">
 <div id="header"><h1>This is the header!</h1></div>

 <ul id="nav">
   <li><a href="#">Link 1</a></li>
   <li><a href="#">Link 2</a></li>
   <li><a href="#">Link 3</a></li>
   <li><a href="#">Link 4</a></li>
 <ul>

 <div id="content">
   <h1>Content!</h1>
   <p>This is some content</p>
 </div>

 <div id="sidebar"><p>Sidebar Content</p></div>

 <div id="footer"><p>Copyright blah blah</p></div>
</div>

 

CSS:

#container {
width: 960px;
margin: 0 auto;
}

#header {
width: 960px;
height: 150px;
margin-bottom: 10px;
background: #333;
}

#nav {
height:50px;
background: #333;
}

#nav li {
list-style: none;
float: left;
margin-right: 5px;
}

#content {
width: 600px;
padding: 15px;
float: left; // floats content area left
background:#333;
}

#sidebar {
width: 315px;
padding: 15px;
float: right; // floats sidebar right
background:#333;
}

#footer {
height:100px;
clear:both; // clears previously created floats
background:#333;
}

 

That's all there is to it. Hope it helps.

Advice from the pros would be great!

Well you won't be getting any because you can't listen. I just posted your entire site layout in HTML using the same grid system that some of the best designers on the web use. I'm not sure what else you're looking for in this thread.

 

I've told you not to use absolute positioning etc, but you'll still continue to use it. I also told you to download Firebug, but you won't. You're beyond hope.

  • Author

Lol Calm down calm down. I have listened, I just haven't started altering the site yet as I have been busy over xmas and new year. I take on board all the valuable advice that is given to me in these forums and I will start putting it to use in the next few days.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.