English 中文(简体)
显示图像标题, 以图像为中心, 以 Cs 或 jquery 为中心?
原标题:Show image caption centered over image and center with css or jquery possible?
  • 时间:2012-05-28 05:27:04
  •  标签:
  • jquery
  • css

Trying to add a centered caption over an image, almost there. see:http://cssdesk.com/2wreQ But I want and can t get the text paragraph (p.wp-caption-text to) be centered. Can t get it done and hopefully someone can point me in the right direction to do it with css or jquery.

非常感谢任何帮助。

最佳回答

你让它变得比需要的复杂多了 JQuery根本不必要

< a href=> "http://csdesk.com/jegSJ" rel="nofollow" > 我的行动建议。 我删除了 .wp-caption 元素的内线宽度,因为这不是一个伟大的实践,它使事情复杂化。你不需要任何 z-index 值,而 position: 绝对 位置实际上造成了你的问题,因为它没有定义宽度。 要将标题文本置于图像中, 标题文本元素需要拥有图像的全部宽度。 您可以简单地添加 width: 140px; .wpp-caption- text 来完成这个任务, 但随后你就会遇到其他问题。

删除 < code> 位置: 绝对; , 段落可以追溯到使用其可用的全部宽度( 在应用边距后), 以及 text- align: central; 属性适用于 .wp- caption 的工作。 对边距和垫线的修改主要是为了简化 CSS 安保部, 使其更容易工作, 但是它们还应该修正一些浏览器问题, 您可能稍后会遇到的 。 我还应用了一些非争议格式化。 I. e. I., 我重新排序了属性, 删除了重复内容, 添加了间距 。

HTML HTML

<div id="content">
<div id="attachment_24" class="wp-caption alignnone"><a href="http://zoekmachineoptimalisatielab.nl/wp-content/uploads/2012/05/Koala.jpg"><img class="size-thumbnail wp-image-24" title="Koala" src="http://zoekmachineoptimalisatielab.nl/wp-content/uploads/2012/05/Koala-150x150.jpg" alt="" width="150" height="150" /></a><p class="wp-caption-text">Koala caption</p></div>
</div><!-- .entry-content -->

CSS 安保部

#content .wp-caption {
  background: #F1F1F1;
  line-height: 18px;
  margin-bottom: 20px;
  overflow: hidden;
  padding: 9px 0;
  text-align: center;
  width: 168px;
}
#content .wp-caption a {
  display: block;
  margin: 0 9px;
}
#content .wp-caption-text {
  background-color: #FFFFFF;
  border: 1px solid #CACACA;
  color: #888888;
  font-size: 12px;
  font-weight: bold;
  margin: -12px 9px 0;
  padding: 1px 4px;
  position: relative;
}
问题回答

嘿,我想你应该 这个

在 cs 中添加一个属性

#content .wp-caption {
position:relative;
}

并替换此 cs 中的此 css

#content .wp-caption p.wp-caption-text {
    background-color: #FFFFFF;
    border: 1px solid #CACACA;
    bottom: 24px;
    color: #888888;
    font-size: 12px;
    font-weight: bold;
    left: 0;
    margin: 0 9px;
    padding: 1px 4px;
    position: absolute;
    right: 0;
    z-index: 9999;
}

这里的现场演示 http://jsfiddle.net/seK84/

I assume u have fixed width of 160px of attachment_24. Add this to your css.

p.wp-caption-text{
    width:140px
}

Thanks everybody for helping me in right direction.. This is what I had in mind: http://cssdesk.com/tVpxK and thanks to your help I got it working..





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

Drop down background url in Safari Issue

selectBox.selectCSS { background: url(/Images/replacementSelectBackground.png) top left no-repeat height:auto; } I have an issue in Safari only where the image is not rendering on top ...

CSS specific for Safari

How do you target specifically safari in css with styles?

Aligning textarea in a form

Ive used the following css code to align my form elements: form { position:relative; } form input { position:absolute; left:11em; } However, the textarea element is not aligned correctly with the ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

CSS problem with page footer

I have defined my page footer in the css file as: #footer { position: absolute; height: 50px; text-align: center; background: #66CCCC; bottom: 0px; left: 0px; width: 100%; height: ...