css - 如何在内容后面显示背景图像?
问题描述
我正在使用 Visual Studio 创建一个聊天应用程序,并希望在主页和关于我们页面上添加背景图像,这两个页面都已经有一个导航栏,并且主页有一个框,用户可以在其中输入详细信息并加入聊天室我想在所有这些后面添加一张图片,我尝试使用不同的代码,但最接近的是这个:
HTML
<img src="image/friends.jpg" alt="image">
CSS
div {
background: url('image/friends.jpg');
background-size: cover;
background-position: center;
}
但是图像未完整显示,它仅显示图像图标并删除了内容,请帮助
解决方案
你不需要
<img src="image/friends.jpg" alt="image">
只需使用 CSS:
body {
background-image: url("https://images.unsplash.com/photo-1542281286-9e0a16bb7366");
background-size: cover;
background-position: center; // if you want the image to be centered
}
或(见片段)
.bg {
background-image: url("https://images.unsplash.com/photo-1542281286-9e0a16bb7366");
background-size: cover;
background-position: center; // if you want the image to be centered
}
.bg {
background-image: url("https://images.unsplash.com/photo-1542281286-9e0a16bb7366");
background-size: cover;
background-position: center;
}
div {
height: 700px;
}
<div class="bg">
I am creating a chat app with visual studio and want to add a background image on the home page and about us page, both pages already have a nav-bar and the home page has a box where the user can enter details and join the chatroom and I want to add an image behind all of that, I tried using different codes but the one that came close is this one...
</div>
推荐阅读
- cypress - cypress - 为具有 css 属性“display: none”的元素识别具有鼠标事件的元素
- wpf - 问题图标 WPF XAML - 不显示图标
- multithreading - ASP.net Web API 中的异步线程
- c++ - opencv 程序已编译,但不执行(c++)
- sql - 如何在过去几年和几个月之间的参数中设置日期
- html - 为什么我在 html 文档中看不到 Flask 中的任何文本?
- regex - 正则表达式在 URL 中查找字符串的唯一第一次出现
- javascript - 使用 vue 3 以编程方式创建和挂载组件
- javascript - 如何使用 javascript 迭代 JSON 对象并显示
- javascript - 如何在不同的文件中处理相同的导入/需求?