【问题标题】:Wordpress title positioning with CSS使用 CSS 定位 Wordpress 标题
【发布时间】:2013-04-20 04:48:30
【问题描述】:

我正在将某人的静态 HTML 设计转换为 Wordpress,但在处理标题时遇到了问题。

情况是标题向下扩展,这意味着当一个标题变成多行时,其他标题也会向上跳跃,即使它们只有一行。

这就是发生的事情

这就是我想要的

这是我用来定位标题的 CSS,因此标题的底部会碰到图像的底部:

.single_title {
    font-family:Novecent_norm, arial, helvetica, sans serif;
    font-size: 18px;
    width: 240px;
    color: white;
    background-color: purple;
    margin-top: -86px;
    position: fixed;
}

所以问题是:是否有一个 CSS 属性可以解决这个问题,所以在标题的顶部而不是在标题的底部添加额外的文本行?

根据要求,HTML:

<?php get_header(); ?>

<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="content_container">
    <div class="thumb_art">
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
            <div class="thumb_img" style="z-index: 0;">
            <?php
            if (has_post_thumbnail()) {
                the_post_thumbnail();
            }?>
            </div>
            </a></h2>

        <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
        <div class="single_title">

                <?php the_title();?>

            </div></a></h2>
    </div>
</div>
    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
<div class="navigation">  <div class="alignleft"><?php previous_posts_link('&laquo; Next Entries') ?></div>  <div class="alignright"><?php next_posts_link('Previous Entries &raquo;') ?></div></div>
<?php get_footer(); ?>

【问题讨论】:

  • 你能粘贴一个完整的 HTML 示例吗?
  • 按要求添加了 HTML。

标签: html css wordpress


【解决方案1】:

使 thumb_art 位置相对,然后在 single_title 上将底部设置为 0 以使其始终保持在底部

css

.single_title {
    font-family:Novecent_norm, arial, helvetica, sans serif;
    font-size: 18px;
    width: 240px;
    color: white;
    background-color: purple;
    bottom:0;
    position: fixed;
}

如果还没有设置为相对,也添加这个

.thumb_art{
   position:relative;//actually any positioning would do
}

仍然不完全确定我是否正确理解了您的问题,如果我遗漏了什么,请告诉。

编辑:

如果你使用我的方法,这就是它的样子

http://jsfiddle.net/nhewu/

【讨论】:

  • 这会将标题完全转储到页面底部:oi35.tinypic.com/2vc9e8g.jpg 我的问题是是否有办法让文本在换行时向上移动,而不是换行.希望我蹩脚的GIF能解释一下,哈哈! oi36.tinypic.com/5cy355.jpg 所以我希望旧线向上移动,而新线保持在同一条线上。我想这是不可能的,否则我早就找到了。可能只是最大值。字符数量并以 ... 如果更多字符结束。
  • @Rvervuur​​t 没有真正的向上换行,你要做的是强制容器向上增长以模拟你想要的结果。如果您在.single_title 上将位置更改为绝对位置,或者如果我可以获得指向该站点的链接,我可以更快地查看并为您找到解决方案
  • 我选择了 ... 解决方案,因为这看起来也比有时是一行,有时是四行等的标题更好。宽度只有 240 像素,所以标题会变得非常混乱.绝对位置没有解决它,这就是我开始的。它会让他们坚持到底,但没有解决向上换行的问题。因此,无论是在代码方面还是在设计方面,我都决定削减标题。不过感谢您的帮助!
  • 我接受了你的回答,因为显然你得到了它的工作。再次感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-03
  • 2013-04-27
  • 1970-01-01
  • 2023-03-28
  • 1970-01-01
相关资源
最近更新 更多