如何将其与右对齐<ul>?



我目前正试图在我的博客上对齐<ul> -标签,但我有很多问题。我试过在css中浮动它,但它不起作用。我显然不是一个高级编码员,正如你所看到的,它在wordpress中,所以我几乎可以肯定我做错了什么。我试图向右对齐的<ul>标签是"GPS状态:"以及GPS状态的gif。这是我正在做的页面:blog.dronebutikken.dk

老实说,我更喜欢没有li标签,以避免间距。提前非常感谢!

HTML:

<div class="trending-articles">
    <ul>
       <li class="firstlink"><?php _e('Mest populære','mythemeshop'); ?>:</li>
        <?php $i = 1; $my_query = new wp_query( 'cat='.$mts_options['mts_trending_articles_cat'].'&posts_per_page=4&ignore_sticky_posts=1' ); ?>
        <?php if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <li class="trendingPost <?php if($i % 4 == 0){echo 'last';} ?>">
                <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" rel="bookmark"><?php mts_short_title('...', 24); ?></a>
            </li>                   
        <?php $i++; endwhile; endif;?>
    </ul>
    <ul class="gps">
        <li>GPS Status</li>
        <li>
            <a href="http://blog.dronebutikken.dk/k-indeks/"><img src="http://altigator.com/wp-content/uploads/gps/gps_kpstatus.gif" align="right" width="100px"></a>
        </li>
    </ul>
</div>
CSS

趋势文章和我无效的gps类试图对齐它

.trending-articles {
  background: #2A2A2A;
  border-bottom: 1px solid #000;
  float: left;
  width: 100%;
  position: relative;
  z-index: 100;
}
.trending-articles ul {
  list-style: none
}
.trending-articles li {
  border-right: 1px solid #7D7D7D;
  color: #fff;
  float: left;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2em;
  margin: 10px 0 9px;
  padding: 0 13px;
  text-transform: uppercase;
}
.trending-articles li.firstlink {
  border: none;
  padding-left: 20px;
}
.trending-articles li.last {
  border: none
}
.trending-articles li a {
  color: #7D7D7D;
  display: block;
}
.trending-articles li a:hover {
   color: #fff
}
.gps ul {
  float="right"
}

您正在尝试将样式应用于gps类中的<ul>,但是您的类应用于<ul>。:)

哦,还有一个CSS语法错误。

去:

ul.gps { float: right; }

你应该使用flexbox,如下所示:http://codepen.io/anon/pen/XmKxOr?editors=110

删除列表元素

<div class="trending-articles">
  <div>
    <a href="" title="" rel="bookmark">lala</a>
  </div>
  <div>
    <a href="" title="" rel="bookmark">lala</a>
  </div>
  <div>
    <a href="" title="" rel="bookmark">lala</a>
  </div>
  <div>
    <a href="" title="" rel="bookmark">lala</a>
  </div>
  <div>
    <a href="" title="" rel="bookmark">lala</a>
  </div>
  <div>
    GPS Status
  </div>
  <div>
    <a href="http://blog.dronebutikken.dk/k-indeks/"><img src="http://altigator.com/wp-content/uploads/gps/gps_kpstatus.gif"></a>
  </div>
</div>
flex

.trending-articles {
  background: #2A2A2A;
  border-bottom: 1px solid #000;
  padding-top:5px;
  margin:0;
  display: flex;
  justify-content: space-around
}
.trending-articles > div{
  list-style: none;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2em;
  text-transform: uppercase;
  margin: 8px 0;
  flex: 1 0 auto;
  text-align:center;
  padding-top:2px
}
.trending-articles > div:not(last-child) {
  border-right: #555 solid 1px;
}

.trending-articles > div > a {
  color: #7D7D7D;
}
.trending-articles > div > a:hover {
  color: #fff
}

你的css代码有语法错误。将.gps ul { float: "right" }替换为ul.gps { float: right; }

最新更新