I have a picture I have to use for a fullsize cover picture for a landingpage. The picture is 3680 * 2456px. When I set the picture in my code, the picture is zooming, which means I can see the half of the picture. Therefore I tried to resize it to 1024 * 683 px, which resultet in that my picture filled the half of the banner.
How can I make my picture fit my banner, so it is not zooming?
.fullscreen {
width:100%;
min-height:100%;
background-repeat:no-repeat;
background-position:50% 50%;
background-position:50% 50%\9 !important;
background-image:url(/img/seminar/bg.jpg);
background-size
}
.overlay {
background-color: rgba(0, 0, 0, 0.5);
position: relative;
width: 100%;
height: 100%;
display: block;
}
<div class="fullscreen landing parallax">
<div class="overlay">
<div class="container">
<div class="row">
<div class="col-md-7">
<!-- /.logo -->
<div class="logo"><img src="http://site.dk/img/site-logo-white.png" alt="logo"></div>
</div>
</div>
</div>
</div>
</div>
Try:
.fullscreen {
background: url(/img/seminar/bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
instead of your original .fullscreen CSS.
This snippet of code can be found via CSS Tricks website.
This should work. Set the image height and width to 100%
<img src="http://site.dk/img/site-logo-white.png" alt="logo" style="width: 100%; height: 100%;" />
Edit: To do that in CSS try this
.fullscreen img {
width: 100%;
height: 100%;
}
Related
1.How do I change the image size for the background url depending on screen size?
<main id="main">
<section class="uvsbg text-center">
<div class="container" data-aos="fade-up" style="height:950px;">
<div class="row" style="background: url('assets/img/contact-bg5.jpg'); background-size: 100% 100%; position: relative; height: 850px;">
<div class="col-md-12"> <h1 style="color:#fff;text-align:center;margin-top:50px;font-size: 52px;">Contact Us
There are several ways you could do that.
If you are interested in the background being the full size of the element, replace the style attribute of the row div with this: (Source)
background: url(assets/img/contact-bg5.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
Otherwise, you would have to use Javascript to do this if you do not want the background to be the full width of the element. (You can learn a bit about this here)
Use CSS media queries. Replace the inline-CSS with a class and add the CSS to an external file or using internal CSS.
<main id="main">
<section class="uvsbg text-center">
<div class="container" data-aos="fade-up" style="height:950px;">
<div class="row" class="change-bg-image">
<div class="col-md-12"> <h1 style="color:#fff;text-align:center;margin-top:50px;font-size: 52px;">Contact Us
.change-bg-image {
background: url('assets/img/contact-bg5.jpg');
background-size: 100% 100%;
position: relative;
height: 850px;
}
#media only screen and (max-width: 768px) {
.change-bg-image {
background-size: 50% 50%;
position: relative;
height: 400px;
}
}
you can use these values as well
background-size: auto|length|cover|contain|initial|inherit;
#media screen and (max-width: 992px){
.row{
background-size: 50% 50%;
}
}
I'm attempting to set this image as the background of the page, and for whatever reason it just won't work. The intention is to make the background image cover the page, without cropping vertically or horizontally.
Note: The CSS file is connected to the document.
HTML:
<body>
<main>
<h2 id="cityName">
</h2>
<div id="weatherIcon">
<img id="weatherIconImg"/>
</div>
</main>
</body>
CSS:
body {
background-image: url("https://firebasestorage.googleapis.com/v0/b/production2hats.appspot.com/o/studentPortal%2Fassessment-web-app-essentials%2Fbackground.jpg?alt=media&token=d0e6837f-d037-4fee-97b6-313c8ea6aa80");
background-repeat: no-repeat;
-webkit-background-size: cover fixed;
-moz-background-size: cover fixed;
-o-background-size: cover fixed;
background-size: cover fixed;
}
Hope this will work for you:
body {
min-height: 100vh;
min-width: 100vw;
background-image: url("https://firebasestorage.googleapis.com/v0/b/production2hats.appspot.com/o/studentPortal%2Fassessment-web-app-essentials%2Fbackground.jpg?alt=media&token=d0e6837f-d037-4fee-97b6-313c8ea6aa80");
background-size: 100% 100%;
background-attachment: fixed;
}
<main>
<h2 id="cityName">
</h2>
<div id="weatherIcon">
<img id="weatherIconImg"/>
</div>
</main>
You should try background-size: Cover; may be an image will be cut from right or bottom but with background-size: 100% 100%; image can stretch. It totally depends on image size.
please do not use this css attribute "background-repeat: no-repeat;" if you want full screen image.
Actually you can solve this issue in two ways.
1.use the fullimage and repeat the image if size of the screen is large
2. stretching the image to the full width.
please look at the below code:
body {
background-image: url("https://firebasestorage.googleapis.com/v0/b/production2hats.appspot.com/o/studentPortal%2Fassessment-web-app-essentials%2Fbackground.jpg?alt=media&token=d0e6837f-d037-4fee-97b6-313c8ea6aa80");
min-height: 100%;
min-width: 1024px;
width: 100%;
height: auto;
position: fixed;
top: 0;
left: 0;
}
<h2 id="cityName"></h2>
<div id="weatherIcon">
<img id="weatherIconImg"/>
</div>
another meathod is below here.
body {
min-height: 100vh;
min-width: 100vw;
background-image: url("https://firebasestorage.googleapis.com/v0/b/production2hats.appspot.com/o/studentPortal%2Fassessment-web-app-essentials%2Fbackground.jpg?alt=media&token=d0e6837f-d037-4fee-97b6-313c8ea6aa80");
background-size: 100% 100%;
}
<h2 id="cityName"></h2>
<div id="weatherIcon">
<img id="weatherIconImg"/>
</div>
The Problem
I have a user image, which I want to scale up and down with the window so that the height is always 100% and the image stays centered.
Example 1
This example scales as the window is resized, but the height doesn't stay at 100% and therefore gets cut off at the bottom.
.user {
width: 100%;
height: 100%;
object-fit: cover;
object-position: 50% 0%;
}
CodePen Example 1
Example 2
This example works perfectly, apart from when the width of the browser window is smaller than the width of the image, the right-hand side is cut off.
I do want the image to be cropped, but I want the right and left sides to be cropped equally.
.user {
object-position: center;
display: block;
height: 100%;
margin-left: auto;
margin-right: auto;
}
CodePen Example 2
Visual Example
Here is an example of how I want the images to appear when the browser is scaled horizontally/vertically.
An idea is to use multiple background like this:
I used multiple div to illustrate with different sizes
body,
html {
height: 100vh;
margin: 0;
}
.bg-shine {
background-position: center;
background-repeat: no-repeat;
background-size: auto 100%, cover;
background-image: url("https://icons.iconarchive.com/icons/paomedia/small-n-flat/512/user-male-icon.png"), url("https://t.motionelements.com/stock-video/design-elements/me1656952-blue-sunrise-background-hd-a0120-poster.jpg");
}
<div style="display: inline-block;">
<div class="bg-shine" style="height:100px;width:400px;">
</div>
<div class="bg-shine" style="height:100px;width:200px;">
</div>
</div>
<div style="display: inline-block;">
<div class="bg-shine" style="height:200px;width:100px;">
</div>
</div>
Update
To avoid using the image within CSS you can consider the inline style and a separate div for the user image so that you have almost the same markup as using an image tag:
body,
html {
height: 100vh;
margin: 0;
}
.bg-shine {
background-position: center;
background-repeat: no-repeat;
background-size: cover;
background-image: url("https://t.motionelements.com/stock-video/design-elements/me1656952-blue-sunrise-background-hd-a0120-poster.jpg");
}
.bg-shine>div {
background-size: auto 100%;
background-position: center;
background-repeat: no-repeat;
height:100%;
}
<div style="display: inline-block;">
<div class="bg-shine" style="height:100px;width:400px;">
<div style="background-image:url('https://icons.iconarchive.com/icons/paomedia/small-n-flat/512/user-male-icon.png')"></div>
</div>
<div class="bg-shine" style="height:100px;width:200px;">
<div style="background-image:url('https://icons.iconarchive.com/icons/paomedia/small-n-flat/512/user-male-icon.png')"></div>
</div>
</div>
<div style="display: inline-block;">
<div class="bg-shine" style="height:200px;width:100px;">
<div style="background-image:url('https://icons.iconarchive.com/icons/paomedia/small-n-flat/512/user-male-icon.png')"></div>
</div>
</div>
I like your question! I approached it from a different angle, and tried to use background rather than img element. Please see the results here:
https://codepen.io/Varin/pen/xYqXQe
body, html {
height: 100vh;
margin: 0;
}
.bg-shine {
height: 100vh;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
background-image: url("http://t.motionelements.com/stock-video/design-elements/me1656952-blue-sunrise-background-hd-a0120-poster.jpg");
position: relative;
}
.image {
padding:0;
margin:0;
width: 100%;
height:100%;
position:absolute;
top:50%;
left:50%;
transform: translate(-50%, -50%);
background-image:url('http://icons.iconarchive.com/icons/paomedia/small-n-flat/512/user-male-icon.png');
background-repeat: no-repeat;
background-position: center center;
background-size: auto 100%;
}
<div class="bg-shine">
<div class="image">
</div>
</div>
I try to make background with image, this image
I have this code (page on bootstrap).
.cover-losos{
background: url('http://patwoj.hekko24.pl/zdrowie/images/losos.jpg') no-repeat center center;
-webkit-background-size: 100%;
-moz-background-size: 100%;
-o-background-size: 100%;
background-size: 100%;
}
<div class="container-fluid">
<div class="row">
<div class="col-md-12 cover-losos">
</div>
</div>
</div>
Why isn't the photo showing? What am I doing wrong?
Your issue is not the background. Your div where you set the background has neither a width nor a height set meaning that the size of the background image is 100% of 0px.
try adding a width and height to your cover-losos div.
.cover-losos {
background: url('https://placeimg.com/640/480/any') no-repeat center center;
-webkit-background-size: 100%;
-moz-background-size: 100%;
-o-background-size: 100%;
background-size: 100%;
width: 100%;
height: 300px;
}
<div class="container-fluid">
<div class="row">
<div class="col-md-12 cover-losos">
</div>
</div>
</div>
I am having trouble getting my image to display when there are no fixed height and width assigned. I want my image to be flexy and responsive with my grid, so what I thought would work is to set height and width to 100% but no avail.
How can I get the image to show and be able to change size accordingly?
HTML
<div class="row">
<div class="large-12 columns">
<div class="hero">
<img id="image" src="steve1.png" alt=""/>
</div>
</div>
</div>
CSS
.hero {
max-width: 100%;
height: auto;
background-repeat: no-repeat;
margin: 0;
}
Give this a shot:
html {
min-height: 100%;
background-size: cover;
background-image: url(steve1.png);
background-repeat: no-repeat;
background-position: right bottom;
}
body{
min-height:100%;
}
Try adding to the css:
.hero img {width:100%;}
You have to add the style to the img it self, not the container div.