Html 在 WordPress 中居中对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4940231/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Centering an object in WordPress
提问by Adrian D'Urso
I have a blog on wordpress and I need to center an object. What is the easiest way?
我有一个关于 wordpress 的博客,我需要将一个对象居中。什么是最简单的方法?
采纳答案by jdhartley
You would actually use HTML and CSS to do that. :)
您实际上会使用 HTML 和 CSS 来做到这一点。:)
<div style="text-align: center;"> YOUR OBJECT HERE </div>
回答by Steve Massing
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:
你不能用 PHP 做布局,它是为了编程逻辑。要进行布局,您可以使用 CSS 和 HTML。要使文本居中,您可以使用 jdhartley 上面显示的 text-align 标签。要像表格或 div 这样的块居中,请使用以下 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.
宽度可以是任何东西,但你必须设置它。它可以是 90% 之类的百分比或像素宽度。
回答by Antonio Dimitrovski
Definitely easiest and the best way to centre whatever you want in WordPress is to use:
在 WordPress 中居中任何你想要的东西绝对是最简单和最好的方法是使用:
<center>whatever you need, a, img etc..</center>
回答by Demian Brecht
You don't center objects using PHP. You position them using CSS. Read this for further info.
您不使用 PHP 将对象居中。您可以使用 CSS 定位它们。阅读本文了解更多信息。
回答by Aaron Hathaway
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 只是一种执行数据操作等的脚本语言。您处理该信息并输出 HTML(通常)。您可以做的就是关闭 PHP 并将一些 HTML 放入其中,如下所示:
<?php //PHP stuff ?>
<p style="text-align:center;">HTML Stuff</p>
alternatively you can do it all in PHP like:
或者,您可以在 PHP 中完成所有操作,例如:
<?php
$output = '<p style="text-align:center;">HTML Stuff</p>
echo $output;
?>