Header / Body / Footer - Page 2

User 122279 Photo


Senior Advisor
14,624 posts

I did some housekeeping in your img1 div, and there it was, centered:

#img1
{
margin: auto;
width: 510px;
height: 388px;
border: none;
padding-bottom: 0px;
}
Ha en riktig god dag!
Inger, Norway

My work in progress:
Components for Site Designer and the HTML Editor: https://mock-up.coffeecup.com


User 2924428 Photo


Registered User
1,718 posts

Ok cool thank you Inger! Oops I tried using the code and the preview wouldn't work.. it's not bringing up an image, now that is the standard image code that you use to center an image though right? the auto code should pick up on centered.. I think?
User 2924428 Photo


Registered User
1,718 posts

#img1
{
backround: url(../images/guts1.JPG) no-repeat;
margin: auto;
width: 510px;
height: 388px;
border: none;
padding-bottom: 0px;
}
User 122279 Photo


Senior Advisor
14,624 posts

My standard way of inserting an image is much easier:

HTML:
<img src="images/guts1.JPG" alt="some image">

CSS:

img
{
margin: auto;
width: 510px;
height: 388px;
border: none;
padding-bottom: 0;
display: block;
}

The margin auto tells the browser that there is supposed to be the same space left and right, and the display block makes the image actually go into the center.

In your code I didn't have to apply the display block, because you had already created a block level container, namely the #img1.

Of course, if you have more images, and they are not supposed to be positioned the same way, you have to target them in the css:

Example:

#sidebar img { margin-right: 10px;
border: 1px solid red;
}

This will position all images in a sidebar 10px from the right edge and give them a red border.
Ha en riktig god dag!
Inger, Norway

My work in progress:
Components for Site Designer and the HTML Editor: https://mock-up.coffeecup.com


User 2924428 Photo


Registered User
1,718 posts

Ok, I got the center part of it done, the image decided to show up again, so when inserting an image, it's best to keep it in the html, and not the CSS unless it's an actual backround right? And the block code to center consists of two codes,
#img2{
margin: auto;
width: 510px;
height: 288px;
border: none;
padding-bottom:0;
display: block;
}

The margin: auto is a center code, and the display: block is a center code as well, but where does padding come in ? and why do I have to write a border: none in there if I don't use it? I'm learning good things :)
User 2924428 Photo


Registered User
1,718 posts

I know this may be a shot in the dark but i'm going to try and write some CSS3 and create my own page. I think i'm at the point to where an attempt will be in standing.
User 122279 Photo


Senior Advisor
14,624 posts

UnclePlusMax wrote:

The margin: auto is a center code, and the display: block is a center code as well, but where does padding come in ? and why do I have to write a border: none in there if I don't use it? I'm learning good things :)


The margin:auto is enough if you are centering a so called 'block level' element, like a div or p e.g., basically an element that can contain other elements. An image is not a block level element, therefore the display:block is necessary, to make the image behave like a block element.

Typically. images are inserted via css as background images if they need to have something on top of them, text or so. Other images should be added via html.

I think it would be a good idea to try to make your own css and html. But start with something simple, not with all the 'cool stuff' to begin with. And what you really need to learn, seems to be text formatting. Therefore make a page with text and a couple of images as training, and you can expand from there.
Ha en riktig god dag!
Inger, Norway

My work in progress:
Components for Site Designer and the HTML Editor: https://mock-up.coffeecup.com


User 2924428 Photo


Registered User
1,718 posts

Ok will do Inger, I got my computer back from the shop and I forgot to install the little charge holders in the bottom, that's all, it runs super fast now :) I'm going to be flyyyyying.
User 2924428 Photo


Registered User
1,718 posts

Inger, do you use CoffeeCup CSS builder for coding or just the HTML editor?
User 122279 Photo


Senior Advisor
14,624 posts

I don't use the css builder. It is too old. I use the Editor - and my brains ;)
Ha en riktig god dag!
Inger, Norway

My work in progress:
Components for Site Designer and the HTML Editor: https://mock-up.coffeecup.com



Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.