html - CSS :nth-child() psuedo selecting

标签 html css

<分区>


关闭 7 年前

我有一个多语言网站。

在网站的左侧有一个导航菜单。那里的元素向左浮动。但是列表中的一项(第二项)向左浮动太多。我尝试使用 li:nth-child(2) psuedo 选择来解决这个问题。这一切都很顺利。但是在其他页面(另一种语言)上,第二项向右浮动太多。

问题:

是否有另一种方法可以在不使用内联 css 的情况下仅对列表中的 1 个元素进行样式设置? (我无权访问 html)。

.welcome80 .media-list .item-readmore {
  margin-top: 12px;
  font-size: 12px;
  float: left;
}
<li class="">
  <a class="item-image" href="http://www.ace-fibreoptic.com/index.php/news.html#ericsson-toteutti-estwin-projektin-tkf-n-ace-konseptin-mukaisesti" title="">
    <img src="http://www.ace-fibreoptic.com/media/catalog/product/cache/3/small_image/125x/9df78eab33525d08d6e5fb8d27136e95/e/s/estwin_630x316.jpg" alt="">
  </a>
  <h2 class="item-name"><a href="http://www.ace-fibreoptic.com/index.php/news.html#ericsson-toteutti-estwin-projektin-tkf-n-ace-konseptin-mukaisesti" title="Ericsson toteutti EstWin-projektin TKF:n ACE-konseptin mukaisesti">Ericsson toteutti EstWin-projektin TKF:n ACE-konseptin mukaisesti</a></h2>
  <div class="item-desc">
    <p>Viron EstWin-hankkeen tavoitteena on rakentaa optinen valokuituverkko kattamaan lähes koko Viro.&nbsp; Hankkeen urakoitsija Ericsson toteutti vuoden 2015 projektin TKF:n ACE-konseptin mukaisesti.</p>
  </div>
  <div class="item-readmore">
    <a href="http://www.ace-fibreoptic.com/index.php/news.html#ericsson-toteutti-estwin-projektin-tkf-n-ace-konseptin-mukaisesti">Lue lisää...&nbsp;&gt;</a>
  </div>
</li>

截图示例:

https://i.gyazo.com/1bdbdc0831d970cbd4057170aa3d1339.png

如您所见,第二项向左浮动太多。

最佳答案

用另一个 div 包装两个 div - item-descitem-readmore 并应用 overflow-hidden

.welcome80 .media-list .item-readmore {
margin-top: 12px;
font-size: 12px;
float: left;
}
.item-text{
  overflow: hidden;
}
<li class="">
                                                        <a class="item-image" href="http://www.ace-fibreoptic.com/index.php/news.html#ericsson-toteutti-estwin-projektin-tkf-n-ace-konseptin-mukaisesti" title="">
                    <img src="http://www.ace-fibreoptic.com/media/catalog/product/cache/3/small_image/125x/9df78eab33525d08d6e5fb8d27136e95/e/s/estwin_630x316.jpg" alt="">
                </a>
                                <h2 class="item-name"><a href="http://www.ace-fibreoptic.com/index.php/news.html#ericsson-toteutti-estwin-projektin-tkf-n-ace-konseptin-mukaisesti" title="Ericsson toteutti EstWin-projektin TKF:n ACE-konseptin mukaisesti">Ericsson toteutti EstWin-projektin TKF:n ACE-konseptin mukaisesti</a></h2>
            <div class="item-text">
            <div class="item-desc">
                                        <p>Viron EstWin-hankkeen tavoitteena on rakentaa optinen valokuituverkko kattamaan lähes koko Viro.&nbsp; Hankkeen urakoitsija Ericsson toteutti vuoden 2015 projektin TKF:n ACE-konseptin mukaisesti.</p>                    </div>
            <div class="item-readmore">
                <a href="http://www.ace-fibreoptic.com/index.php/news.html#ericsson-toteutti-estwin-projektin-tkf-n-ace-konseptin-mukaisesti">Lue lisää...&nbsp;&gt;</a>
            </div>
            </div>
        </li>

关于html - CSS :nth-child() psuedo selecting,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35844463/

上一篇:javascript - 使用 JavaScript 更新转换属性中的 rotate() 属性

下一篇:javascript - Textarea和下拉集合管理

相关文章:

javascript - Jquery元素

html - 如何在圆形 div 中垂直居中对齐 Font Awesome 图标?

javascript - 第二行无法在 php 中更新

javascript - document.querySelector() 不起作用

javascript - 样式化 Polymer Web 组件

javascript - DIV 元素的 Border-Radius 在 IE8 中不起作用

css - 延迟时间后自动填充颜色 - svg

javascript - div 复选框在单击时变暗

html - 居中表内容(图像和文本)

html - 如何根据内容长度将标题居中?