html - 我有 2 个不同的列表,我想在 css 上设置样式,我应该怎么做?

标签 html css

HTML

<pre>

<head>
    <title>
        title of the page
    </title>
    <link rel="styleheet" type="text/css" href="css/style.css"> 
</head>
<body>
<ul>
    <li>Italy</li>
    <li>France</li>
    <li>Greece</li>
</ul>
   <h1> This is the main heading</h1>
  <p>This text might be an introduction to the rest of
the page. And if the page is a long one it might
be split up into several sub-headings</p>
<h2>this is the second heading</h2>
<p> long live the King :Many long articles have sub-headings so to help
you follow the structure of what is being written.
There may even be sub-sub-headings (or lower-level
headings).</p>
<h2>Another sub heading</h2>
<p>Here you can see another sub-heading.</p>
<p>This is how we make a word appear <b>bold.</b></p>
<p>This is how we make a word appear <i>italic</i>.
</p>
<ul>
    <li>Potatoes</li>
    <li>Oranges</li>
    <li>Berries</li>
</ul>
</body>
</html>
</pre>

CSS:

<pre>
body{background: url("../img/poza.jpg");

}
ul{text-align: left;

}
ol{
    list-style-position: right;
    text-align: 
}
</pre>

最佳答案

使用类或 id 的

HTML

<ul class="list1">
    <li>Italy</li>
    <li>France</li>
    <li>Greece</li>
</ul>

<ul class="list2">
    <li>Potatoes</li>
    <li>Oranges</li>
    <li>Berries</li>
</ul>

CSS

.list1 {
   text-align: left;
   color: red;
}
.list2 {
   text-align: right;
   color: blue;
}

此外,如果你想将 CSS 应用于所有内部的“li”,例如“ul class="list1"'(以避免为每个“li”元素赋予类),你可以在 css 中使用子/父元素来实现:

.list1 > li {
   color: orange;
}

关于html - 我有 2 个不同的列表,我想在 css 上设置样式,我应该怎么做?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41861887/

相关文章:

Android:如何从 TextView 链接本地 HTML 文件

html - 使用 JSON 传递 HTML

jquery - 无法使用 Textualizer 显示动画文本

CSS div 溢出。 (调整浏览器大小时)

css - 注释导致代码显示不正确 (CSS/Bootstrap)

html - 将文本置于图像之上时遇到问题

javascript - 在复选框上显示 map_canvas div

javascript - 如何在 javascript 中向多边形添加图案?

javascript - Canvas - 将第一个 Canvas 中生成的图像添加到第二个 Canvas 中

css - 在带有固定宽度标题的滚动列底部填充