html - 为 div 中的各个元素着色

标签 html css

我正在编写自己的网站,并且 html/css 经验有限,所以请放轻松:)
我使用以下 html 在网页左侧提供一个“菜单”

并使用以下 css 将其向左对齐,以允许另一段标题文本 float 在其右侧

			.links	{
				width: 45%;
				float: left;
				font-size: 2em;
				margin: 0 5%;
				clear: left;
			}
			.links a	{
				text-decoration: none;
				color: black;
				border: 1px solid black;
				padding: 1%;
				display: inline-block;
			}
			.links a:hover	{
				background:lightblue;
			}
<div class="links">
		<a href="index.html"><b><i>Home</i></b></a>
		<a href="services.html"><b><i>Services</i></b></a>
		<a href="contact.html"><b><i>Contact Us</i></b></a>
	</div>

现在,我真的很希望能够为单个链接框着色以显示用户所在的页面,但无法弄清楚如何
我尝试为每个链接添加额外的“div”,但这会导致对齐失败并将链接放在彼此下面
任何帮助将不胜感激,因为我渴望学习:)
非常感谢

最佳答案

您可以将单个类添加到链接,如下所示:

<div class="links">
        <a class="clicked" href="index.html"><b><i>Home</i></b></a>
        <a href="services.html"><b><i>Services</i></b></a>
        <a href="contact.html"><b><i>Contact Us</i></b></a>
    </div>

然后设置此类的样式:

 .clicked{
        background: gray;
}

我鼓励您使用列表进行导航,如下所示:https://jsfiddle.net/o4tcsdmp/2/

关于html - 为 div 中的各个元素着色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45401691/

相关文章:

html - 将 Ace 编辑器与 Twitter Bootstrap 结合使用

html - 检查 ="checked"在 chrome 中不工作

javascript - 单击按钮时如何使输入值变为空白?

javascript - Unicode 字符转义序列未在 handlebar.js 中正确打印

CSS - 按钮分离

HTML 编码问题 - 显示 "Â"字符而不是 "&nbsp;"

css - SASS 元素设置 : mixins that depend on other mixins

html - 图像在浏览器预览中质量下降

css - 在 RMarkdown 中更改 block 背景颜色

javascript - AngularJs 应用程序不能在 chrome 中工作但在其他浏览器中工作