can anybody help full screen background problem facing - html

the answer is i had to put one more / in the path and dont know why,example
background-image: url(/destinationfolder/imagename.jpg) not
background-image: url(destinationfolder/imagename.jpg)
i wanna make a full screen background and the code is so simple however it didnt work can any body catch the problem ?
here is the HTML code
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="bg">this is our div</div>
<p>This example creates a full page background image. Try to resize the browser window to see how it always will cover the full screen (when scrolled to top), and that it scales nicely on all screen sizes.</p>
</body>
</html>
and thats the css code
body, html {
height: 100%;
margin: 0;
}
div {
height: 100%;
}
.bg {
/* the proper height for the image */
height: 100%;
background-image: url('cover.jpg'); /* the use image location */
background-repeat: no-repeat;
background-size: cover;
}

You almost certainly need background-size.
Keep in mind that a user with a 4K monitor is going to be rare compared to someone on a mobile phone. So be sure to use CSS Media Queries once you get to the last step of adding mobile support. You're the one looking at the screen to judge how you need to use background-size so be sure to tinker with the options in the developer tools; just resize the browser window down until the mobile effect takes effect. You can also use units such as percentages (background-size: 100% 100%;). Good luck!
.bg
{
background-image: url(images/bg-desktop.png);
background-size: contain;
}
#media (max-width: 1024px)
{
.bg
{
background-image: url(images/bg-mobile.png);
background-size: cover;
}
}

Try with setting min-height of body or div element to 100vh
body{min-height:100vh;}
Possible problem: The image should be in same directory as your css file since u are using relative path.

Related

<div> not displaying background image

In my css file, I have an id named "homehero", which displays a background image.
#homehero
{
background-image: url("images/coast.jpg");
background-size: 100% 100%;
background-repeat: no-repeat;
}
In my html file, I have a div that uses this id to display the image; however, the image does not appear whatsoever.
<div id="homehero"> <!-- Home Page Image -->
<!-- <img src="images/coast.jpg" width="100%" height="100%" alt="A Sunny Coastline"> -->
<!-- Old line of html that displayed the same image, but converted to css id. -->
</div> <!-- End of Home Page Image -->
The full html file can be found here.
The full css file can be found here.
Edit:
The image is displayed when setting it as the background image for another element, it is only in this id where the issue occurs.
Please Put width and height
width:100%;
height:100vh;
#homehero
{
background-image: url("images/coast.jpg");
background-size: 100% 100%;
background-repeat: no-repeat;
width:100%;
height:100vh;
}
I would suggest below changes,
#homehero
{
background-image: url("images/coast.jpg");
width:300px;
height:300px;
background-size: cover;
background-repeat: no-repeat;
}
Where, your image will be cover and if you specifies width and height it would be good and also your image will not be repeat as no-repeat property is used.
These are a few things I recommend you try:
Try setting the background size. (Instead of %, try setting it to px.)
Most of the time, the background picture is applied, but because our div has
no dimension, we are unable to view it.
Double-check that your picture file is located in the images folder.
Check your image's extension and make sure you're using the correct one in your code.
Use the dev tools to inspect the element and see whether the background property is being overridden by another CSS rule.
If none of the above methods work, try pasting the picture's real URL by copying the image address from the internet rather than providing a folder path.
This method works 90% of the time.
i recommend to use inline scope css, i hope it works for you
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="#homehero {.css">
<style>
#homehero {
background-image: url("image/image.png");
background-size: 100% 100%;
background-repeat: no-repeat;
}
</style>
</head>
<body>
<div>
<div id="homehero">
</div>
</div>
</body>
</html>
this might be the reason why it can happen
https://www.geeksforgeeks.org/types-of-css-cascading-style-sheet/#:~:text=As%20Inline%20has%20the%20highest,sheets%20have%20the%20least%20priority.
It looks like you're entering the url in the background image, for background size using background-size: cover;
If your url address is correct, then try adding
width:100%;
height:100vh;

Background image partially disappearing when resizing browser image

I am writing a website and I have gotten everything in place with the homepage the only problem is when I resize the browser window the background image moves and parts of it disappear as the window is resized. Id like it to stay fixed in the window just have the image shrink as the window is shrunk.
I'm sure what I am doing wrong is pretty simple but I'm pretty new to coding and can't for the life of me figure out what I need to do. Thanks to you all in advance.
<meta name="viewport" content="width=device-width, initial-scale=1">
body{
background: url(Home-background.jpg);
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
background-attachment: fixed;
}
when you want cover vertical and horizontal can use this code (pay attention may be deformed this background image)
body {
background: url(Home-background.jpg);
background-position: center center;
background-repeat: no-repeat;
background-size: 100% 100%;
background-attachment: fixed;
}
You can use bootstrap to do this. In between the head tags of your html file add this:
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin="anonymous">
It should work. Hope it helps :)
should the image be full width? if yes, make sure you specify the width to be 100%
width: 100%;
should do the trick
you need to use width: 100%; height: 100%; of your body tag.
it should work.
In the HTML file:
<img id="background-image" src="Home-background.jpg">
In the CSS file:
body {
margin:0;
}
img#background-image {
position:absolute;
width:100%;
height:100%;
z-index:-1;
}
As a result, the background image will be fully stretched, vertically and horizontally.

Perfectly place an image bigger than screens

I am new to CSS and media queries and I have also followed this thread but didn't got my problem solved. I have an image which is bigger than the screen resolution. The dimension of image is 1532*933 and the resolution of my desktop is 1366*768. I am trying to make a page in which the image is in the background of the body. I am trying to perfectly fit the image on the screen. So for that I have written this CSS
html, body {
min-height: 100%;
}
body{
font-family: 'Source Sans Pro', sans-serif;
background-image: url("/public/images/image.jpg");
background-repeat: no-repeat;
background-size: cover;
background-position: 0, 0;
}
#media (min-width: 1024px), (min-height: 630px) {
body { background-size: auto; }
}
But I can clearly see that the image is not getting placed properly. It's being cut off from the bottom side and right hand side. I want to place this image properly in the full screen (means top=0, bottom = 0, right = 0, left = 0) without losing the quality of image.
Also I am trying to get the image perfectly fit in other resolutions as well using the same image, so I am using media queries.
How can I achieve this ?
Regards
I hope it could help:
body, html {
height: 100%;
}
.bg {
/* The image used */
background-image: url("https://upload.wikimedia.org/wikipedia/commons/thumb/4/43/Red_flag.svg/1280px-Red_flag.svg.png");
/* Full height */
height: 100%;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="bg"></div>
</body>
</html>
You have many options. If you need this page only on your pc you can edit yuor image with a dedicated application and then use this in your page. If you need a responsive layout you should use several versions of the image that you want to provide as background image and use media queries to choice the right one for your device. Let's say that you have an image called image.jpg (500x500) you can force resizing using height and width but the image will lost its quality. However you can use media queries like this:
/*width and height of an ipad*/
#media (min-width: 768px), (min-height: 1024px) {
body { background-image: url("/public/images/image_ipad.jpg"); }
}
/*width and height of a Galaxy S5*/
#media (min-width: 360px), (min-height: 640px) {
body { background-image: url("/public/images/image_galaxy.jpg"); }
}
Obviously you can play around with media queries a little better choosing only width range so you can say from x width to y width i will use this image and so on. Keep in mind that for this purpose you can use a vectorial image to make things easier for you.
Try
#media (min-width: 1024px) and (min-height: 630px) {
body { background-size: auto; }
}
I have figured out a way to achieve this. My image is perfectly aligning now without any distortion. Here is my code snippet:
.main-background {
background: url("https://static-fastly.hackerearth.com/static/hackerearth/images/logo/HE_logo.png") no-repeat center;
margin: 0;
background-repeat: no-repeat;
background-size: 100% 100%;
}
.main-content {
height : 100vh;
}
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<body class="main-background">
<div class="main-content">
</div>
</body>

Background image positioning, full width, browser height 100%, multiple sections, padding issues

Been writing code for the background of a website. The goals are 1) 100% height of the browser window for the first image 2) image stays centered in window and sides are cut off 3) on the home page there is also two additional images that need to have the same effect. Been trying and writing different code chunks and not getting anywhere. I can get one part which just breaks another. Thank you for any assistnaceCurrent code chunk is as follows:
<html>
<head>
<meta charset="UTF-8">
<title>Background Image</title>
<style>
* { margin: 0; padding: 0; }
.background {
background: no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
</style>
</head>
<body>
<div class="background">
<img src="images/bg.png">
</div>
<div class="background bg2">
<img src="images/bg2.png">
</div>
</body>
</html>
Not sure if I fully understand what your question is but for your image to get the height of the window you need to
.background {
background-image: url(images/bg.png);
height: 100vh;
}
That way the background image will always use the full height of the viewport. Not sure about the rest of the question tho!
If I understand what you are trying to do, there are a few things with your code that is wrong. First I will explain a couple of things and then I'll provide the code that I came up with that works when I tested it. Here goes...
First, in your style element, where you have ".background:", you don't need any of the code that you wrote. The stuff that mentions webkit, moz, etc. is really for stuff that may have cross browser compatibility problems. background-size is not one of those things you would have to worry about with that. The only thing I would put in your "background" class is width and height of 100%.
Second, speaking of width and height, I would include and "html" and "body" element and give them both a width and height of 100%.
Third, you are trying to have your images listed in your html, but you are trying to style them as if you are having your css produce them. Notice how in my html I left the "background" divs empty and then included the url of the photos in the css.
In a nutshell, I believe you may be a little confused as to what method should be used and when/where, because you are actually fusing different approaches together. That said, here is the code I wrote...
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Background Image</title>
<style>
* { margin: 0; padding: 0; }
html, body {
width: 100%;
height: 100%;
}
.background {
width: 100%;
height: 100%;
}
#bg1 {
background: url(images/bg.png) no-repeat center;
background-size: cover;
}
#bg2 {
background: url(images/bg2.pngg) no-repeat center;
background-size: cover;
}
</style>
</head>
<body>
<div class="background" id="bg1">
</div>
<div class="background" id="bg2">
</div>
</body>
</html>
Here is a link that may help you too. They have great directions, exercises and tutorials: w3schools.com
Hope all of that helps Zack! :)

Collapsing my page upon resizing

I have created this page and it is working fine, I'm having issue regarding the resizing, when I do resize the browser my page cropped and couldn't scroll to reach it. This is my HTML Code
<body id="page-top">
<style type="text/css">
#media (min-width:1500px) {
.new_bg {
background-image: url(img/bg2000.png);
background-size: cover;
background-repeat: no-repeat;
min-height: 50%;
}
}
in my CSS code:
html,body {
width: 100%;
height: 100%;}
Apologize if I didn't catch the needed portion of code, you may refer for the page to try, thanks.
UPDATE
]2
In you page CSS,
#media only screen and (orientation:portrait){
header{
display:none;
}
}
This is causing your page to go invisible when you resize your window. When you start resizing your window, at some width and height, the orientation is becoming as portrait and whole page is set to display:none.
Based on your question, I feel like, you don't need that style, as your query was like you are unable to find the content on resize.
Update
Your .header-content style is having -webkit-transform:TranslateY() and transform:translateY().
This is making your content to move up and making your page start position outside the browser view. Please remove these two.
Your header-content is having padding values, making your main content to move some pixels to the right. This is causing overflow. Please remove this as well.
#media (max-width:1500px) {
.new_bg {
background-image: url(img/bg2000.png);
background-size: cover;
background-repeat: no-repeat;
min-height: 50%;
}
}
change min width to max width try thiss...