【问题标题】:Caption uncentering its image标题使图像不居中
【发布时间】:2012-02-20 15:51:37
【问题描述】:

我有一个问题可能很简单,但找不到解决方案。

我正在管理我的自托管 wordpress,并且经常在我发布的文章中添加图片,并希望它们居中。但是,我注意到在为居中的图片添加标题时,它们最终左对齐。你可以看一个例子here(第一张和第二张图片)。

“无标题&对齐”图片代码为:

<p style="text-align: center;">
    <a rel="attachment wp-att-1949" href="http://themikal.com/?attachment_id=1949">
        <img class=" size-large wp-image-1949 aligncenter" title="hildolfr1" src="http://themikal.com/wp-content/uploads/2011/05/hildolfr1-566x400.jpg"alt="" width="391" height="276" />
    </a>
</p>

而“标题和未对齐”图片代码将是:

[caption id="attachment_1949" align="aligncenter" width="391" caption="Hildolfr"]
    <a rel="attachment wp-att-1949" href="http://themikal.com/?attachment_id=1949">
        <img class=" size-large wp-image-1949 aligncenter  " title="hildolfr1" src="http://themikal.com/wp-content/uploads/2011/05/hildolfr1-566x400.jpg" alt="" width="391" height="276" />
    </a>
[/caption]

我尝试将&lt;p style="text-align: center;"&gt;&lt;/p&gt; 添加到带字幕的图片代码中,无论是在字幕括号外还是在字幕括号内,但没有结果。

有人知道它为什么会有这样的反应吗? wordpress.stackexchange 认为这是一个与 css 相关的问题,因此在这里更相关。

我在 CSS 方面完全是初学者,并且正在使用预先设计的代码,然后我对其进行了大量修改。但是,如果有人指出它所在的位置,我可以提供有关 CSS 中某些信息的更多信息。

非常感谢!

【问题讨论】:

  • 您链接到的页面上第二张图片下的标题以我的浏览器为中心(Chrome v17)。你用什么浏览器?
  • 相同。使用 Firefox 最新版本。我建议您尝试使用不同的浏览器和/或便携式(自包含)版本,以确保它不是让您感到困惑的插件。
  • 奇怪。我也在使用 Chrome v17,并且是最新的。图像是否也居中?我希望图像居中,但一旦我添加标题,它总是左对齐。
  • 它也在 Windows 7 的 IE9 中居中。您的 CSS 代码 .wp-caption {text-align: center;} 可以解决问题。
  • 图像和文本在 IE、FF、GG、Safari 和 Opera 中居中。也许张贴问题的图片!

标签: css wordpress caption


【解决方案1】:

虽然很尴尬,但我在不知不觉问问题前几分钟解决了这个问题。

CSS 缺少以下几行:

img.alignright {float:right; margin:0 0 1em 1em}
img.alignleft {float:left; margin:0 1em 1em 0}
img.aligncenter {display: block; margin-left: auto; margin-right: auto}
.alignright {float:right; }
.alignleft {float:left; }
.aligncenter {display: block; margin-left: auto; margin-right: auto}

所以它无法理解img class = aligncenter 的含义。重新添加这些行可以解决问题。

【讨论】:

猜你喜欢
  • 2013-12-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-24
  • 1970-01-01
  • 2018-11-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多