html - 如何在 <li> 的最右边设置样式?

标签 html css

无法弄清楚为什么这段代码不起作用,它仍然在左边:

<ul style="list-style: none; width: 200px;" >
<li class="item" ><p>hello world</p></li>
<li class="item"><p>hello world</p></li>
<li class="item"><p>hello world</p></li>
</ul>

我的CSS:

.item {
 position: relative; 
 right: 0px; 
 margin-top: 2px;
}

我尝试将 li 的样式转移到 p 和两者上,但仍然没有效果。帮忙?

最佳答案

只需使用 text-align: right在你的 <ul> :

<ul style="list-style: none; width: 200px; text-align:right" >
  <li class="item" ><p>hello world</p></li>
  <li class="item"><p>hello world</p></li>
  <li class="item"><p>hello world</p></li>
</ul>

关于html - 如何在 <li> 的最右边设置样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45793580/

相关文章:

javascript - 如何通过javascript中的函数将javascript数组元素作为值放入html表单字段中?

jquery - 在 jquery 中单击更改多个类

html - Bootstrap - 减少 Dashboard 示例的宽度

Firefox 径向渐变问题

css - Flexbox 在 Chrome 或 Safari 中不工作,但在 Firefox 中工作

CSS 分页符不起作用

html - 如何让这个 Sprite 按照我想要的方式运行?

html - 需要有关外部 CSS 引用的帮助

magento 网站迁移后 CSS 不加载

javascript - TypeScript - 以 Angular 4+ 覆盖 Youtube iframe 样式