开发者

Centering an object in WordPress

I have a blog on wordpress and I ne开发者_C百科ed to center an object. What is the easiest way?


You cannot do layout with PHP, it is for programming logic. To do layout you use CSS and HTML. To center text you can use the text-align tag that jdhartley showed above. To center a block like a table or div you use the following CSS:

<style>
.centered {width:950px; margin-left:auto; margin-right:auto;}
</style>

<div class="centered">Bunch of stuff to be centered</div>

The width can be anything, but you do have to set it. It can be a percent like 90% or a pixel width.


You would actually use HTML and CSS to do that. :)

<div style="text-align: center;"> YOUR OBJECT HERE </div>


Definitely easiest and the best way to centre whatever you want in WordPress is to use:

<center>whatever you need, a, img etc..</center>


You don't center objects using PHP. You position them using CSS. Read this for further info.


PHP is just a scripting language that performs data manipulation and such. You process that information and output HTML (usually.) Something you can do is just close the PHP and drop some HTML into it like this:

<?php //PHP stuff ?>
<p style="text-align:center;">HTML Stuff</p>

alternatively you can do it all in PHP like:

<?php
$output = '<p style="text-align:center;">HTML Stuff</p>
echo $output;
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜