html - 在html页面中将文本覆盖在图像上

标签 html css

如何在页面中间的图像 (homepagepic.jpg) 上叠加一段文字。 我想在图像上写一堆文字,我做了很多研究,但老实说我还没有遇到太多。非常感谢提前

HTML:

<center>
   <h1>Welcome To The Kingston University Survey Page</h1>
</center>
<img src="kingstonunilogo.jpg" id="uni" alt="uni logo"/>
<br/>
<div id="buttons">
    <button onclick="window.location='http://www.google.com'" type="button home-button">Home</button>
    <button onclick="window.location='http://www.google.com'" type="button contact-button">Contact Us</button>
    <a href="http://www.w3schools.com/html/">LogIn</a>
</div>
<br/><br/><br/><br/><br/><br/>
<img src="homepagepic.jpg" alt="homepagepic" id="middlepic" />
<br/>
<div id="footer">
  &copy; 
  <img class="social-badge" src="facebookpic.png" alt="facebook logo" onclick="window.location.href='http://www.facebook.com'">
  <img class="social-badge" src="twitterpic.jpg" alt="twitter logo" onclick="window.location.href='http://www.twitter.com'">
</div>

CSS:

h1 {
    margin:0px;
    padding:0px;
}
body {
    background-color: #A9D0F5;
}
#middlepic {
    display: block; margin: 0 auto; 
} 
#uni { 
    display: block; width: 200px; height: 175px; float:left; 
} 
#footer { 
    width: 100%; height:100px; display: inline-block; text-align: center; 
}
#buttons {
    display: block;       
    margin: 0 auto;
    width: 50%;
}
button { 
    height: 30px; 
    width: 200px; 
    background-color: #ccc; 
    border-radius: 10px; 
} 
a { 
    text-decoration: none; color: #000; 
}
.social-badge {
    width: 40px;
}

最佳答案

要不你新建一个div,把homepagepic.jpg作为背景,然后在那个div里面写。

<div id="written">
This text is over the image
</div>

在 CSS 中

#written
{
    background-image : url(***** here comes the url of image homepagepic.jpg*****);
}

关于html - 在html页面中将文本覆盖在图像上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27704941/

相关文章:

html - 为什么 Chrome 会忽略文本输入的 "size"属性?

Javascript:解析 html 表

javascript - 样式为 :before and :after CSS 的互斥复选框

jquery - overflow hidden 不适用于 jQuery .css 单击事件

jquery - 如何在禁用 javascript 时使这些 jquery 弹出窗口回退到 css

悬停时动画元素的 JavaScript 问题

javascript - 如何使用 .js 从每个 div 获取值?

javascript - 如果在 jQuery 中找不到 ID,则显示不同的结果

html - Flexbox 最后一项右对齐

javascript - 为每个 img 分配一个不同的随机类