我有一个问题,无法找到答案或不知道如何搜索答案。
我不知道如何将文本定位在图像上方,以使它们对齐。以下图片将澄清我的问题。 下面是我的HTML和CSS代码,我只提供了关于页面的HTML,但CSS适用于整个网站。这不是什么专业的东西,我只是想通过实践学习。我的想法是将这些图像用作链接(我知道如何做)。如果已经有类似的问题,请原谅,我尝试在这里和YouTube上搜索,但找不到解决此问题的方法。如果没有其他办法,我将在GIMP中编辑带有文本的图片。
我不知道如何将文本定位在图像上方,以使它们对齐。以下图片将澄清我的问题。 下面是我的HTML和CSS代码,我只提供了关于页面的HTML,但CSS适用于整个网站。这不是什么专业的东西,我只是想通过实践学习。我的想法是将这些图像用作链接(我知道如何做)。如果已经有类似的问题,请原谅,我尝试在这里和YouTube上搜索,但找不到解决此问题的方法。如果没有其他办法,我将在GIMP中编辑带有文本的图片。
body {
background: #e5fcf4;
font-family: Arial;
}
header {
text-align: center;
}
header nav {
display: inline-block;
}
header nav ul {
list-style: none;
margin: 0;
padding: 0;
}
header ul li {
float: left;
color: white;
width: 200px;
height: 40px;
background-color: #0d3801;
opacity: .9;
line-height: 40px;
text-align: center;
font-size: 20px;
}
header ul li a {
text-decoration: none;
color: white;
display: block;
}
header ul li a:hover {
background-color: green;
color: black;
}
header ul li ul li {
display: none;
}
header ul li:hover ul li {
display: block;
}
div.maincontent {
width: 70%;
padding: 2px;
margin: 2px;
float: left;
}
div.sidecontent {
width: 23%;
float: right;
padding: 2px;
margin: 2px;
margin-top: 10px;
}
div.maincontent img {
width: 900px;
height: 400px;
}
.clear {
clear: both;
}
footer {
background-color: #0d3801;
text-align: center;
}
footer img {
width: 200px;
height: 200px;
margin: 5px;
}
footer h2 {
font-size: 2rem;
color: white;
}
img.aboutimage {
width: 450px;
height: 400px;
float: left;
padding: 5px;
margin-left: 125px;
margin-top: 100px;
}
<header>
<nav>
<ul>
<li> <a href="index.html">Home </a> </li>
<li> <a href="about.html">About </a>
<ul>
<li><a> Our team </a></li>
<li><a> Camp sites </a></li>
<li><a> Mission & Vision </a></li>
</ul>
</li>
<li> <a href="things.html">Things to do </a>
<ul>
<li><a> Activities </a></li>
<li><a> Parks </a></li>
<li><a> Coffee bars </a></li>
</ul>
</li>
<li> <a href="contact.html"> Contact </a>
<ul>
<li><a> Map </a></li>
<li><a> Directions </a></li>
</ul>
</li>
<li> <a href="news.html"> News </a> </li>
</ul>
</nav>
</header>
<div>
<a href="">
<img class="aboutimage" src="https://images.pexels.com/photos/7097/people-coffee-tea-meeting.jpg?w=1260&h=750&auto=compress&cs=tinysrgb">
</a>
<a href="">
<img class="aboutimage" src="https://images.pexels.com/photos/803226/pexels-photo-803226.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb">
</a>
<a href="">
<img class="aboutimage" src="https://images.pexels.com/photos/462353/pexels-photo-462353.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb">
</a>
</div>
a
标签上方添加<h1>Hello There</h1>
即可。 - Athul Nath