I have a div on the top of the page that is assigned a parallax image, when the view port is not that wide the image is not responsive, how can I make the background image responsive ?
#parallax{
height:100vh;
background:url("../images/keyboard.jpg");
background-size: cover;
background-attachment: fixed;
}
<div id="parallax">
<div class="col-md-1"></div>
<div id="profile" class="bottom-align col-md-4">
</div>
</div>
and here are the screenshots of what I mean by unresponsive
basically I want "web site" to show when the view port is not wide as well instead of "WE"
background-size: cover is scaling your background image to fill the whole height of the containing element which on a mobile device is tall and narrow, cropping the image.
You should either use background-size: contain instead of cover, or allow the containing element to shrink to less than 100vh. The caveat with the former is you need to figure out what to fill the rest of the container with.
Here's an example:
.target {
background: url(http://placekitten.com/300/100);
background-position: center center;
background-color: teal;
background-size: cover;
background-repeat: no-repeat;
height: 150px;
width: 100px;
}
.better {
background: url(http://placekitten.com/300/100);
background-position: top center;
background-color: teal;
background-repeat: no-repeat;
background-size: contain;
height: 150px;
width: 100px;
}
<html>
<body>
Cover:
<br>
<div class="target"></div>
Contain:
<br>
<div class="better"></div>
<div>
Original:
<br>
<img src="http://placekitten.com/300/100" ?>
</div>
</body>
</html>
Have your image width be 100%. I put the image tags inside the divs to represent screen sizes.
<div style="width:20%">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/86/Triforce.svg/691px-Triforce.svg.png" style="width:100%">
</div>
<div style="width:40%">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/86/Triforce.svg/691px-Triforce.svg.png" style="width:100%">
</div>
<div style="width:60%">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/86/Triforce.svg/691px-Triforce.svg.png" style="width:100%">
</div>
<div style="width:80%">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/86/Triforce.svg/691px-Triforce.svg.png" style="width:100%">
</div>
<div style="width:100%">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/86/Triforce.svg/691px-Triforce.svg.png" style="width:100%">
</div>
A straightforward solution would be :
Make your body size stretch to the whole view-port
body{
width:100%;
height:100%;
/* on the example due to some overflow I've used 97% to prevent scroll bars
....
make your background image fill the body element
background-image:url(...);
background-position:cover;
And that's it,
To live a white space for your header offset your image position down, by the width of your header.
background-position:50px;
The inconvenience is when you want to have actual content you can't rely on the same style sheet for the other pages, you have to change it.
Of course you won't see any responsiveness in the example here because the way the snippet is in a fixed width container. But it has work as expected when tested. (at least you can see how the image is stretched compared to the original one here )
.header{
border:solid ;
width:100%;
height:50px;
text-align:center;
}
body{
width:97%;
height:97%;
background-repeat:no-repeat;
background-image:url(https://i.stack.imgur.com/AWVa6.jpg);
background-position:0 50px;
background-attachment:fixed;
background-size:cover;
}
<div class="header">your header or navigation bar</div>
Related
I've already made the background image to full size in my page, but when I inspect and try to display it in phone mode, my background image get cropped, how can I resist this thing so it can't get cropped but always cover particular part of the page
<div class="inner-banner has-base-color-overlay text-center" style="background: url(header.jpg); background-size: cover; position: center;">
<div class="container">
<div class="box">
<h3>About Us</h3>
</div>
</div>
</div>
If you are using background image and You want see in mobile view then it will be cut off of the background image you need to call img src.
<style>
.header-img {
max-width:100%;
margin:0 auto;
display:block;
}
#media all and (max-width:600px){
.header-img {
height:300px;
object-fit:cover;
}
</style>
<div class="inner-banner has-base-color-overlay text-center">
<div class="container">
<div class="box">
<img src="images/header.jpg" class="header-img" alt="">
<h3>About Us</h3>
</div>
</div>
you can set these css for BackGround Image :
background-position: 100% 100%;
background-size: cover;
and your manual height
replace your style with below code : -
background: url(header.jpg); background-size: 100%; position: center;
I have a web page that includes a cropped section of a full size image (thumbnail).
When the thumb is clicked it opens the full size image.
I wanted to avoid uploading a full size picture and a cropped thumbnail so I used the below class which crops the full size image.
.crop {
width: 100%;
overflow: hidden;
}
.crop img {
width: 100%;
margin: -250px 0 0 0;
}
This class gives me the crop of the full size image that I wanted but unfortunately, when I switch from full screen (PC), to mobile the proportions of the image are not kept (The image should look identical on both screens). It looks like the Div width is stretching but the height remains the same.
The full size image is w:650px by h:1000px
The code for my Div is below.
<div class="col-sm-4 col-lg-4 col-md-4">
<div class="thumbnail">
<div class="crop">
<img src="/Images/5.png" alt="Nil">
</div>
<div class="caption" style="padding-bottom: 0px">
<h4 class="pull-right">#1</h4>
<h4>Title</h4>
</div>
</div>
</div>
Please can someone point me in the right direction?
Many thanks
Put your image as container background
CSS:
.Thumb-Box{
display:inline-block;
width: [your width here];
height: [your height here];
}
.Thumb-Box a{
display:inline-block;
height:100%;
width:100%;
padding:0;
margin:0;
}
HTML:
<div class="Thumb-Box" style="background: url('url');background-position: 0px 0px;"> </div>
"0px 0px" stands for what piece of the thumbnail should be seen
ex: -10px from left and -10px from top
try this css
div {
background: url(img_flwr.gif);
background-size: 80px 60px;
background-repeat: no-repeat;
background-position: center;
}
You would have to generate the thumb beforehand.
you could do something like this;
<a href="http://example.com/img.jpg" taget=_blank>
<img src="http://example.com/img.thumb.jpg" />
</a>
To generate a new thumb, you would have to use some software or lib.
My ultimate goal is to have a block of text in a fixed position relative to a background image.
But what seems to be preventing this is that when I resize the browser, the image stays the same size like I want, but the image shifts -- i.e., the top of the image rendered isn't always the top of the image source.
Here's a mockup - imagine that I want the block of text to be in the blue box:
http://jsfiddle.net/rrauenza/9hkn8p4e/embedded/result/
The yellow "ceiling" in this picture sometimes disappears for different browser sizes.
<head><style>
.intro-header {
text-align: center;
color: #f8f8f8;
background: url(http://c3softworks.com/demos/images/backgrounds_04.jpg) no-repeat center top;
background-size: cover;
background-position: center top;
height: 700px;
}
.intro-message {
position: relative;
padding-top: 100px;
height: 700px;
}
</style></head>
<div class="intro-header">
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="intro-message">
<h1>Title</h1>
<h3>...subtitle</h3>
<hr class="intro-divider">
<div class="col-lg-2 col-lg-offset-3">
<h4>Something</h4>
</div>
<div class="col-lg-2 col-lg-offset-2">
<h4>Something Else</h4>
</div>
</div>
</div>
</div>
</div>
</div>
Remove:
background-size: cover;
If you're counting on the background image not to scale it might help not to ask it to.
Also, in your fiddle .intro-header has a background-position:center bottom, while here you post center top. It needs to be center top of course.
I'm learning CSS at the moment and I am using it on a website to control the layout of the site.
I Have a number of containers, 5 of them, all on top of each other, I have a background for the page but I also want to use a background for one of the containers. So I used the 'background-image:url("");' tag to use a background, the I also used the attachment, repeat. The problem I was the image wasn't setting itself to the container, it was pushing out way past the dimensions that I had set in my CSS code which were height:312px; and width: 1000px;
Here is the CSS
html, body
{
margin-top: 25px;
padding: 0;
background-image:url("../../images/background.png");
background-repeat: none;
background-attachment: fixed;
}
.hidden
{
display: none;
}
#page-container
{
width: 1000px;
margin: auto;
background: transparent;
}
#header
{
height: 130px;
}
#content-top
{
background: #D9D9D9;
background-image:url("../images/pic.png");
background-repeat: no-repeat;
background-attachment: fixed;
background-position:right top;
height: 312px;
width: 1000px;
}
Here is the HTML:
<div id="page-container">
<div id="header">
<div id="flashContent">
</div>
</div>
<div id="content-top"><!--<img src="images/pic.png">--></div>
<div id="portfolio-container">
<div id="portfolio1"><p>1</p></div>
<div id="portfolio2">2</div>
<div id="portfolio3">3</div>
<div id="portfolio1"><p>4/p></div>
<div id="portfolio2">5</div>
<div id="portfolio3">5</div>
</div>
<div id="main-content">
main-content
</div>
<div id="footer">Footer</div>
</div>
I haven't pasted all of the CSS but its needed let me know.
Its as if the background is filling a space that is a lot bigger than the space specified.
Last time I needed to do something like this, I did the following:
#background{position:absolute; top:0; left:0; width:100%; max-width:1024; max-height:768; height:auto; z-index:-1; }
And then on my page I included the following:
<img id="background" src="whatever.jpg" alt="" title="" />
And that was it. This actually works quite nicely, with the background image magically resizing itself until one of the dimensions (width or height) reaches the maximum specified.
It doesn't need CSS3 support. Try it and see.
Obviously tweak the positioning stuff if you don't want it to fill the screen (I did).
You will have to set background-size to 100%
It only works in browsers supporting CSS3
Try float:left in #contentTop
Hope that helps!
In css you also have background-size:contain/cover
I have a DIV ...
<div id="content">
</div>
Now...In the design and if you think of it as a rectangle has the top as a header and also the footer is different so I cannot just create a 1px background image and repeat it.
I would have to do something like:
<div id="content">
<div id="header">This will have a fixed bg image</div>
<div id="body-content">This will have a repeated bg image and it's the part that can grow.</div>
<div id="footer-content">THis will content a fixed bg image for the footer</div>
</div>
Can anyone advise on the best way to handle this kind of design CSS wise please?
#header
{
background-image: url('header.png');
background-repeat: no-repeat;
}
#body
{
background-image: url('body.png');
background-repeat: repeat-y;
}
#footer
{
background-image: url('footer.png');
background-repeat: no-repeat;
}