Web Master
Web Master

Reputation: 4340

div centering in html for wordpress

<div id="logo" style="center"><img src="logo1.png"></img></div><br><br><br><br><br><br><br></div>

This doesn't work. Whats the problem with the style of the div? i'm sure the syntax is wrong.

Upvotes: 0

Views: 7516

Answers (4)

Ryan Griggs
Ryan Griggs

Reputation: 2748

Try this. You have to set the width of a div as shown below in order for it to work. To specify that the text inside the div is centered, simply apply style="text-align: center"

<div id="logo" style="margin-left: auto; margin-right: auto; width: 500px; border: 1px solid #ff0000">Your content here....</div>

Note: set 500px width to your desired width. Also, remove border: directive. I just added that so you could see the DIV was centered.

fiddle

Upvotes: 1

Marco Pappalardo
Marco Pappalardo

Reputation: 955

Best way to center a element is probably to specify its width and put the side margin to auto:

If for example your logo1.png is 570px wide, you would do something like this in the css

#logo{
    margin:0px;
    margin-left:auto;
    margin-right:auto;
    width:570px;
}

Upvotes: 1

animuson
animuson

Reputation: 54719

  1. "center" is not a style. You're probably looking for text-align: center.

  2. Images are self-closing like the line-break. You don't use </img>.

  3. You have a spare closing </div> at the end of the line. One of them needs removed, I'm not sure which spot you want it in.

<div id="logo" style="text-align: center"><img src="logo1.png"></div><br><br><br><br><br><br><br>

Upvotes: 4

Sanjay Maharjan
Sanjay Maharjan

Reputation: 671

you cannot define style in div like that instead you can define the div property in css and call the class or id of the css.

Upvotes: 2

Related Questions