HTML编码没有正确居中小工具 - 请保存我的理智

时间:2017-01-17 00:25:38

标签: javascript html

我正在努力从网页中心获取100个Widgets中检索到的对象。这是一个时钟。我在TeamSite工作。对象将无法正确居中。当我键入HTML编码以使对象居中时,预览模式将其更改为居中,但是当我发布项目时,网站将不会反映调整" live"。它保持左对齐;除了预览模式,它将保持正确居中 这就是我所拥有的(它非常简单,所以它让我疯了!):

<div style="width: 50%; margin: 0 auto;">    
  <script type="text/javascript" src="http://100widgets.com/js_data.php?id=38"> 
  </script>    
</div>

添加了空格以允许文本查看。我也尝试过非常基本,包括<center></center>。我得到了相同的结果。此时钟位于:http://100widgets.com/clocks/page/2/,称为时钟蓝色和白色 在我完全疯了之前,有人可以告诉我这件事有什么问题吗?!大声笑......但是真的。

谢谢!

1 个答案:

答案 0 :(得分:0)

这应该将div元素置于页面中心,尽管它可能不会将内容置于其中心。以下是一些如何水平居中的示例。

<style>body {margin:0;} </style>
<div style="width: 50%; margin: 0 auto;">1</div> <!-- centers the element based on the width -->
<div style="text-align:center">2</div> <!-- centers the inline content in the element -->
<div style="position: absolute; left: 50%; transform: translateX(-50%)">3</div> <!-- centers the element and the element is only as wide as the content inside -->

这是集中物品的好参考。 https://www.w3.org/Style/Examples/007/center.en.html