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.

Trouble with resizing background image in header

Featured Replies

Im trying to have an image as a background in my header but im having trouble getting it the right size, as the image is smaller then the header. So far i've written this in my style sheet...

 

#header {

width: 655;

height: 100px;

padding: 10px 20px 10px 20px;

background-image: url("headercrop.jpg");

background-repeat: no-repeat;}

 

Can anyone help?

You can't scale background images. You'll have to make it the correct size in Photoshop or whatever software package you use to author your graphics.

 

Any image is best sized to fit in a graphics program, as resizing it in a browser will make it look pixelated.

  • Author

hmm I think it'll be ok if i make the header and sidebar stationary. Is it easy to do or will i have to rewrite my tags?

I'm unsure what you mean by making them stationary. Can you explain some more? And do you have a link to what you got at the moment?

Hi aj47, if you could give us a link to the page with the problem then we'd be able to help you out faster.

  • Author

I haven't uploaded it onto the Internet so i cant really send you a link at the moment. . The problem im having is i managed to get my page layout working in firefox then i opened up the page in internet explorer and its all moved around. The attached files are screen shots of what they look like in both browsers and the css code i've been using is ...

 

 

body{font-family: arial, verdana,san serif ; margin: 20px 0px 40px 0px;
}



#content {

float: right;
width: 600px;
padding: 0px 20px 10px 10px;


}

#sidebar {

float: left;
width: 100px;
height: 630px;
padding: 30px 50px 10px 20px;
background-image: url("sidebarcrop.jpg");
background-repeat: repeat-y;}


#header {
width: 796px;
height: 89px;
padding: 20px 20px 10px 30px;
background-image: url("headercrop.jpg");
background-repeat: no-repeat;}





#antidepressant {margin: 20px 20px 20px 20px}

#moodbrightner {margin: 20px 60px 20px 0px}


#header {letter-spacing: 4px}


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

a:link { 
color: white;
font-family: sans-serif;
text-decoration: none;}

a:visited {text-decoration: none ; color: white;
font-family: sans-serif;}

a:hover { text-decoration: none ;color: red; 
font-family: sans-serif;}

a:active {text-decoration: none ; color: white;
font-family: sans-serif; }








post-4405-1209305056_thumb.jpg

post-4405-1209305134_thumb.jpg

Without seeing the live page its a bit difficult.

Your problem might be to do with the widths of #content and #sidebar.

Try altering the width(decreasing) of either by 1 or 2px and it might sort IE out.

  • Author

hmm yea i managed to sort out some of it by changing the widths c but theres still the problem with the writing in the header not being centered even though i added padding above and below?

  • Author

sure i know there are quite a few errors in it as it doesn't pass any validation but im not sure why....

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>The Chemistry of Antidepressants</title>
<link rel="stylesheet" type="text/css" href="style.css" />





</head>






<body>

<div id="container">


<div id="header"><span style="color: white">

  <h1>The Chemistry of Antidepressants</h1>  </span>  </div>



<div id="sidebar"> <b> <p><a href="page1.html">What are antidepressants?</a></p>
  <a href="page 2 history.html">A brief history of antidepressants drugs</a> 
<p><a href="page3how.html">Neurotransmitters and depression</a></p>
<p><a href="page4howantidepressantswork.html">How do antidepressants work? </a></p>
<p><a href="page5.html">The Blood Brain Barrier </a></p>
<p><a href="page6.html">Stereoisomerism and drug design </a></p>
<p><a href="page7.html">Prozac synthesis an overview</a></p>

</b></div>


<div id="content">

<br><span style="color:rgb(3,97,152)">
<h2>
What Are Antidepressants?</h2>
</span>



<p>
Antidepressants are a class of mood-stabilising drugs prescribed to treat
clinical depression, anxiety, and a wide range of other psychiatric disorders. 
With current figures suggesting depression affecting an estimate of 7-12% of men 
and 20-25% of women at some point in their lives, antidepressants have become 
one of the most commonly prescribed medicines worldwide.
</p>

<div id="antidepressant">

<img src="antidepressants.jpg" width="200" height="150" alt="Fluoxetine pills" style="float: right"/>

</div>






<p>
Although millions of pounds have been spent on researching antidepressants, they 
are far from benign and their adverse effects are well documented and the subject 
of many studies. As a result, the chemical and biological mechanisms behind how 
these drugs work are becoming increasingly important as pharmaceutical companies 
spend millions on finding 'rationally designed' safer alternatives to the current 
drugs on the market.</p>

<p>
This website is a short introduction to the chemistry and pharmacology behind this class 
of drugs and a brief overview of the constraints that chemists face today when designing 
an effective antidepressants.</p> 









</div>
</div>


<address>
Author: <a href="mailto:......@shef.ac.uk">Alexander Johnson</a> (document modification date: 26 apr 2008)

</address>



</body>
</html>

First of all, here is your html (validated).

You had a few nesting errors.

Try this first and see if your problems still exist.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>The Chemistry of Antidepressants</title>
<link rel="stylesheet" type="text/css" href="style.css">





</head>






<body>

<div id="container">


<div id="header">

<h1><span style="color: white">The Chemistry of Antidepressants</span></h1></div>



<div id="sidebar"><p><a href="page1.html">What are antidepressants?</a></p>
<a href="page 2 history.html">A brief history of antidepressants drugs</a>
<p><a href="page3how.html">Neurotransmitters and depression</a></p>
<p><a href="page4howantidepressantswork.html">How do antidepressants work? </a></p>
<p><a href="page5.html">The Blood Brain Barrier </a></p>
<p><a href="page6.html">Stereoisomerism and drug design </a></p>
<p><a href="page7.html">Prozac synthesis an overview</a></p>
</div>


<div id="content">

<br>
<h2><span style="color:rgb(3,97,152)">
What Are Antidepressants?</span></h2>


<p>
Antidepressants are a class of mood-stabilising drugs prescribed to treat
clinical depression, anxiety, and a wide range of other psychiatric disorders.
With current figures suggesting depression affecting an estimate of 7-12% of men
and 20-25% of women at some point in their lives, antidepressants have become
one of the most commonly prescribed medicines worldwide.
</p>

<div id="antidepressant">

<img src="antidepressants.jpg" width="200" height="150" alt="Fluoxetine pills" style="float: right">

</div>






<p>
Although millions of pounds have been spent on researching antidepressants, they
are far from benign and their adverse effects are well documented and the subject
of many studies. As a result, the chemical and biological mechanisms behind how
these drugs work are becoming increasingly important as pharmaceutical companies
spend millions on finding 'rationally designed' safer alternatives to the current
drugs on the market.</p>

<p>
This website is a short introduction to the chemistry and pharmacology behind this class
of drugs and a brief overview of the constraints that chemists face today when designing
an effective antidepressants.</p>









</div>
</div>


<address>
Author: <a href="mailto:......@shef.ac.uk">Alexander Johnson</a> (document modification date: 26 apr 2008)

</address>



</body>
</html>

Because you want to have the h1 vertically aligned, you could position it absolutely.

h1 {
position:absolute;
top:50%;
left:10%; /*change this value to whatever you like*/
}

You would also need to give the #header a relative position for this to work.

#header {
position:relative;
}

  • Author

Thanks for the speedy reply. I tried changing the position how you suggested but however i position it to look in firefox when i open in I.E the writing in the header always appears a little higher.

You could try putting the following at the top of your stylesheet.

It might mess up your layout to begin with but it removes any browser defaults that might be affecting your layout in IE.

* {
padding:0;
margin:0;
}

  • Author

hmm yea that works but its wierdly made all my paragraphs bunch together?

You'll now need to set the padding/margins for your paragraphs to get the desired look.

The beauty of this approach is that it should look pretty much the same in all browsers.

  • 2 weeks later...
  • Author

I have yet another bunch of problem that i can' seem to sort out.

 

firstly i'm trying to make a group of links a different color but im not sure where to put the tags. In my style sheet I have

.class2 A:link { 
color: white;
font-family: sans-serif;
text-decoration: none;}

.class2 A:visited {text-decoration: none ; color: white;
font-family: sans-serif;}

.class2 A:active { text-decoration: none ;color: red; 
font-family: sans-serif;}

.class2 A:hover {text-decoration: none ; color: white;
font-family: sans-serif; }

 

and then around the links i've put the following span tags ...

<div id="sidebar"><span class="class2"><hr><p><a href="index.html"><b>What are Antidepressants?</b></a></p>
<p><a href="page 2 history.html"><b>A Brief History of Antidepressants Drugs</b></a></p>
<p><a href="page3how.html"><b>How Antidepressants Work</b></a></p>
<p><a href="page5.html"><b>The Blood Brain Barrier </b></a></p>
<p><a href="page6.html"><b>Stereoisomerism and Drug Design</b> </a></p>
<p><a href="page7.html"><b>Prozac Synthesis : An Overview</b></a></p><hr><span>
</div>

 

however when I use that, although it works it doesn't pass validation. Where's the best place to place the tags.

 

Also on the pages that do pass validation it always picks up errors with my image tags with the following warning

Line 70, Column 85: NET-enabling start-tag requires SHORTTAG YES.

…" alt="dopamine" style="float: right"/>

✉

The sequence <FOO /> can be interpreted in at least two different ways, depending on the DOCTYPE of the document. For HMTL 4.01 Strict, the '/' terminates the tag <FOO (with an implied '>'). However, since many browsers don't interpret it this way, even in the presence of an HMTL 4.01 Strict DOCTYPE, it is best to avoid it completely in pure HTML documents and reserve its use solely for those written in XHTML.

 

It seems to go if i remove the close tags at the end of my image tags but I'm fairly sure they should be there. I've also been told that there should be a space before the close tags i.e. <img src="Monoamines.gif" width="514" height="84" alt="Deamination of Monoamines" /> but that doesn't seem to make a difference.

 

One final thing that is the most annoying is when i open up my webpage in Internet explorer. For some unknown reason some of the images do not load and the font seems to go back to default style.

 

Anyone know what I can do

  • Author

Ah yes also one more thing. Im trying to get margins on my images but it isn't working.

My image tags are for example ..

 

<div id="moodbrightner">

<img src="moodbrightner.jpg" width="150" height="180" alt="Prozac Advert" style="float: left"/>

</div>

 

and in my header i have

 

 

<style type="text/css">

#moodbrightner {margin: 10px 20px 10px 0px;
}

</style>

 

I have also tried in my style sheet but it still doesn't work

For the first problem, you are nesting <p>(block elements) inside <span>(inline elements) which isn't allowed.

Instead of using a <span>, put the class="class2" in the <p> tags so you have :

<p class="class2">

For your second problem, it depends what doctype you're using. From the error you are getting, I'm assuming your using html 4.01 so just leave the end / off.

For your last problem, put this in your css:

<style type="text/css">

#moodbrightner img {margin: 10px 20px 10px 0px;
}

</style>

This way, you're referencing the image and not the div that surrounds it.

  • Author

hmm tried adding the span tags i.e.

<div id="sidebar"><hr><p class="class2"><a href="index.html"><b>What are Antidepressants?</b></a><span>
<p><a href="page 2 history.html"><b>A Brief History of Antidepressants Drugs</b></a></p>
<p><a href="page3how.html"><b>How Antidepressants Work</b></a></p>
<p><a href="page5.html"><b>The Blood Brain Barrier </b></a></p>
<p><a href="page6.html"><b>Stereoisomerism and Drug Design</b> </a></p>
<p><a href="page7.html"><b>Prozac Synthesis : An Overview</b></a></p><hr>
</div>

but it still doesn't seem to validate?

hmm tried adding the span tags i.e.
<div id="sidebar"><hr><p class="class2"><a href="index.html"><b>What are Antidepressants?</b></a><span>
<p><a href="page 2 history.html"><b>A Brief History of Antidepressants Drugs</b></a></p>
<p><a href="page3how.html"><b>How Antidepressants Work</b></a></p>
<p><a href="page5.html"><b>The Blood Brain Barrier </b></a></p>
<p><a href="page6.html"><b>Stereoisomerism and Drug Design</b> </a></p>
<p><a href="page7.html"><b>Prozac Synthesis : An Overview</b></a></p><hr>
</div>

but it still doesn't seem to validate?

Not quite sure what you're trying to do there. You have an opening <span> but not a closing</span>

Based on your previous example, I would have done this:

<div id="sidebar"><hr>
<p class="class2"><a href="index.html"><b>What are Antidepressants?</b></a></p>
<p class="class2"><a href="page 2 history.html"><b>A Brief History of Antidepressants Drugs</b></a></p>
<p class="class2"><a href="page3how.html"><b>How Antidepressants Work</b></a></p>
<p class="class2"><a href="page5.html"><b>The Blood Brain Barrier </b></a></p>
<p class="class2"><a href="page6.html"><b>Stereoisomerism and Drug Design</b> </a></p>
<p class="class2"><a href="page7.html"><b>Prozac Synthesis : An Overview</b></a></p><hr>
</div>

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.