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.

How can I change my CSS/HTML code to create the layout of these div tags?

Featured Replies

The current layout of my website is:

Header:

Width=1000 pixels

Height=70 pixels

Menu:

Width=1000 pixels

Height=34 pixels

Images:

Width=1000 pixels

Height=82 pixels

Text:

Width=1000 pixels

Height=automatically expands when content is added

Footer:

Width=1000 pixels

Height=20 pixels

 

The layout I want to change it too:

Header:

Width=full width of internet browser window

Height=70 pixels

Menu:

Width=full width of internet browser window

Height=34 pixels

Images:

Width=1000 pixels

Height=82 pixels

Text:

Width=1000 pixels

Height=automatically expands when content is added

Footer:

Width=full width of internet browser window

Height=20 pixels

 

This is my CSS code:

#container	{
	height: auto;
	width: 1000px;
	margin: auto;
}

#header	{
	width: 1000px;
	height: 70px;
	background-image: url(images/headerbackground.fw.png);
}

#menu	{
	width: 1000px;
	height: 34px;
	background-color: #00F;
}

#images	{
	width: 1000px;
	height: 82px;
	background-image: url(images/imagesbackground.fw.png);
}

#text	{
	width: 1000px;
	height: auto;
	min-height: 20px;
	background-color: #FFF;
}

#footer	{
	width: 1000px;
	height: 20px;
	background-image: url(images/footerbackground.fw.png);
	text-align: right;
}

This is my HTML code:

<div id="container">
  <div id="header"></div>
  <div id="menu"></div>
  <div id="images"></div>
  <div id="text"></div>
  <div id="footer"></div>
</div>

Could someone tell me how I can change my CSS and/or HTML code to create the layout I mentioned above please?

Thank you for any help.

Hi :)

 

You can give your #container a width of 100%, so it takes full width of the browser window.

Then adjust the widths of the other elements and use 100% width where you need the element to take full width of the browser window.

You can also add margin:0 auto; to center some elements (if you need to).

 

Hope that helps.

  • Author

Hi :)

 

You can give your #container a width of 100%, so it takes full width of the browser window.

Then adjust the widths of the other elements and use 100% width where you need the element to take full width of the browser window.

You can also add margin:0 auto; to center some elements (if you need to).

 

Hope that helps.

Thank you for your help, that worked. The only problem is, there seems to be a bit of white space around the outside of the container div, is there something I've done wrong?

 

Here's the CSS as I've rewritten it:

1.#container	{
2.	height: auto;
3.	width: 100%;
4.	margin: auto;
5.}
6. 
7.#header	{
8.	width: 100%;
9.	height: 70px;
10.	background-image: url(images/headerbackground.fw.png);
11.}
12. 
13.#menu	{
14.	width: 100%;
15.	height: 34px;
16.	background-color: #00F;
17.}
18. 
19.#images	{
20.	width: 1000px;
21.	height: 82px;
22.	background-image: url(images/imagesbackground.fw.png);
23.}
24. 
25.#text	{
26.	width: 1000px;
27.	height: auto;
28.	min-height: 20px;
29.	background-color: #FFF;
30.}
31. 
32.#footer	{
33.	width: 100%;
34.	height: 20px;
35.	background-image: url(images/footerbackground.fw.png);
36.	text-align: right;
37.}

Have I done something wrong, or is there something I need to change?

 

Thank you for any help.

Edited by dandydan1152

Try adding:

 

* {margin: 0; padding: 0;}

Inside your CSS sheet.

  • Author

Try adding:

 

* {margin: 0; padding: 0;}

Inside your CSS sheet.

Thank you, I've added that code:

#container	{
	height: auto;
	width: 100%;
	margin: 0;
	padding: 0;
}

But I'm still having the same problem with the white space, is there anything else I can try?

 

Thank you for any help.

  • Author

Did you use the reset that I suggested?

Also, do you have a link or screenshot so we could see a visual example?

I haven't tried the reset, because I wasn't sure what it did exactly, and whether I would have re-write the whole code again.

 

I've uploaded a screenshot of what the problem is, you can see the white space at the top of the page (above the logo that says "Enjoy Leeds".

 

Thank you for any help.

post-54765-0-54428000-1372281665_thumb.jpg

  • Author

I've tried changing my code to the following:

#container	{
	height: auto;
	width: 100%;
	margin-top: -8px;
	margin-left: -8px;
	margin-right: -8px;
}

This has fixed the white space at the top and to the left, but there is now a big white space to the right hand side (as you can see in the picture). Even though I have the width set to 100%.

post-54765-0-78745500-1372282822_thumb.jpg

Edited by dandydan1152

Have you got a link?

 

And you should do what Alluzion has suggested. It's not a big deal, it's just called a page reset, don't let the name scare you. You can create more problems with what you're trying now and the structure of your html matters too.

Lets see your code and ideally a link would be better.

  • Author

Have you got a link?

 

And you should do what Alluzion has suggested. It's not a big deal, it's just called a page reset, don't let the name scare you. You can create more problems with what you're trying now and the structure of your html matters too.

Lets see your code and ideally a link would be better.

Thank you, I've used the CSS reset and it worked straight away. The only problem is that with the margins being set to negative values, it was cutting parts of the web page off. So I just had to set the negative values for the margins to 0, and then it worked fine.

 

Thank you again.

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.