I am building a website where I want the background image to be attached fixed.
I have achieved this in desktop browsers with the CSS below, but it doesn't work on Smartphone.
This is a known bug with background-attachment: fixed.
I don't know how to fix it.
#page-header{
height: 300px;
background: url("../img/wood.jpg");
background-attachment: fixed;
color: #fff;
border-bottom: 1px #eee solid;
padding-top: 50px;
}
My HTML
<header id="page-header">
<div class="container">
<div class="row">
<div class="col-md-6 offset-md-3 text-center">
<h1 id="h1header">Products</h1>
<p>Local, Organic, Tasty</p>
</div>
</div>
</div>
</header>
You can find my website at http://maisonbergeret.com/product.html
My question is how can I keep the exact same effect.
This is what I changed for page-header.
#page-header:before{
content: "";
width: 100%;
height: 300px;
position: fixed;
background: url("../img/wood.jpg")no-repeat center center;
color: #fff;
border-bottom: 1px #eee solid;
padding-top: 50px;
z-index: -10;
display: block;
left: 0;
top: 0;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
Below the header, I have a section product with id="products"
section#products{
background-color: #FAEBD7;
}
Same color as my body background-color: #FAEBD7;
Adjusted margins and now it works.
Related
I am trying to darken images using transparency (opacity) so that the foreground text can be better read.
Here is my header HTML:
.header-image {
display: block;
width: 100%;
text-align: center;
/* image must be 1900 x 500 */
background: url('back.1.jpg') no-repeat center center scroll;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
-o-background-size: cover;
opacity: 1.0;
}
.headline {
padding: 120px 0;
}
.headline h1 {
font-size: 50px;
font-weight: 500;
background: #24292E;
background: rgba(36, 41, 46, 0.7);
color: #FCFCFC;
}
<header class="header-image" style="background: url(' URL TO IMAGE') center no-repeat; background-size: cover;">
<div class="headline">
<div class="container">
<h1>Headline</h1>
</div>
</div>
</header>
You will see that I added 'opacity: 1.0;' on the last line of 'header-image' but it didn't work.
Any idea where I am going wrong here?
Thanks
Well you don't want to change transition of whole div, just an image I guess. You should place it using ::before pseudo-element. Now all css attributes will apply only to ::before:
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<header class="header-image">
<div class="headline">
<div class="container">
<h1>Headlines</h1>
</div>
</div>
</header>
</body>
</html>
CSS:
.header-image {
position: relative;
overflow: hidden;
height: 180px;
}
.header-image:before {
content: ' ';
display: block;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 1;
opacity: 0.5;
background-image: url('http://placekitten.com/1500/1000');
background-repeat: no-repeat;
background-position: 50% 0;
-ms-background-size: cover;
-o-background-size: cover;
-moz-background-size: cover;
-webkit-background-size: cover;
background-size: cover;
}
.headline {
}
.headline h1 {
position: relative;
z-index: 1;
font-size: 50px;
font-weight: 500;
background: #24292E;
background: rgba(36, 41, 46, 0.3);
color: #FCFCFC;
margin: 0;
}
https://jsbin.com/lisakez/edit?html,css,output
You can't apply opacity to a background image.
One way to get around this is to place the image you want as the background directly over the top of the container, which gives the impression it is set as the background. Then place any text directly over the top of the image by applying a higher z-index to the text.
.header-image {
position: relative;
overflow: hidden;
text-align: center;
}
.header-image img {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: auto;
opacity: 0.6;
}
.headline h1 {
position: relative;
z-index: 2;
font-size: 50px;
font-weight: 500;
background: #24292E;
background: rgba(36, 41, 46, 0.7);
color: #FCFCFC;
}
<header class="header-image">
<div class="headline">
<div class="container">
<h1>Headline</h1>
<img src="your-image.jpg">
</div>
</div>
</header>
See fiddle
I am using Bootstrap and have an image 1920x1280. It is currently responsive only till about a width of 1000 px and stops shrinking from there. Width below 1000 px, it starts to cut off the side of the image. I need the full image to be visible on any device. I am adding the image via CSS background url. Is there a way around this. Added the relevant code below. The image is placed within the ID 'intro'.
Image
HTML
<div id="intro">
<div class="intro-body">
<div class="container">
<div class="row">
<div class="col-md-10 col-md-offset-1">
<h1 style="color: #000000">Title<span class="brand-heading">Quote</span></h1>
<p style="color: #000000" class="intro-text">Short description</p>
Learn More </div>
</div>
</div>
</div>
</div>
CSS
#intro {
display: table;
width: 100%;
height: auto;
padding: 100px 0;
text-align: center;
color: #fff;
background: url(../img/intro-bg.jpg) no-repeat center center fixed;
background-color: #000;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#intro .intro-body {
display: table-cell;
vertical-align: middle;
}
#intro .intro-body H1 {
font-size: 76px;
font-weight: 700;
color: rgba(255,255,255,0.8);
text-transform: uppercase;
}
#media(min-width:768px) {
#intro {
height: 100%;
padding: 0;
}
#intro .intro-body .intro-text {
font-size: 18px;
letter-spacing: 1px;
margin-bottom: 100px;
color: rgba(255,255,255,0.9);
}
}
background-size: cover; try to fill all background space so maybe cutoff edge of image. If you will show image completely without cut off set background-size to contain.
background: url(../img/intro-bg.jpg) no-repeat right bottom scroll;
background-color: #31f1fd;
-webkit-background-size: contain;
-moz-background-size: contain;
-o-background-size: contain;
background-size: contain;
Please try this Style instead of your id intro. There are two methods. One is with fixed height and width the other one is without width and height.
#intro{
width: 100%;
height: 400px;
background-image: url('../img/intro-bg.jpg');
background-size: 100% 100%;
border: 1px solid red;
}
or
#intro{
background-image:url('../img/intro-bg.jpg');
background-repeat:no-repeat;
background-size:contain;
background-position:center;
}
I've got this code (with no header-image visible) so far:
.wrap {
margin: 50px auto;
}
html,
body {
height: 100%;
}
body {
background-image: url('https://placebear.com/1000/800');
background-repeat: no-repeat;
background-position: center center;
background-size: cover;
background-attachment: fixed;
}
.header {
background-image: url('https://placebear.com/940/248');
background-repeat: no-repeat;
background-position: center center;
background-size: cover;
}
<div class="wrap">
<div class="row">
<div class="medium-12 columns header"></div>
</div>
</div>
If you give the header-image a fixed size of 248px you can see it appear. Example with visible header-image:
.wrap {
margin: 50px auto;
}
html,
body {
height: 100%;
}
body {
background-image: url('https://placebear.com/1000/800');
background-repeat: no-repeat;
background-position: center center;
background-size: cover;
background-attachment: fixed;
}
.header {
background-image: url('https://placebear.com/940/248');
background-repeat: no-repeat;
background-position: center center;
background-size: cover;
height: 248px;
border: 3px solid white;
}
<div class="wrap">
<div class="row">
<div class="medium-12 columns header"></div>
</div>
</div>
Is there a way to make it appear without using a fixed height?
Like when using a classic img-tag with just src- and alt-attribute. Then height is read out of the image-file self.
I would like to avoid fixed heights in there because if the image changes then it becomes all wrong.
I think you have to define a height if using background-image. Might be better to use img tag and just put a width of 100%, like so:
.wrap {
margin: 50px auto;
}
html,
body {
height: 100%;
}
body {
background-image: url('https://placebear.com/1000/800');
background-repeat: no-repeat;
background-position: center center;
background-size: cover;
background-attachment: fixed;
}
.header {
border: 3px solid white;
}
img {
width: 100%;
}
<div class="wrap">
<div class="row">
<div class="medium-12 columns header">
<img src="https://placebear.com/940/248" alt="Bear Image">
</div>
</div>
</div>
I have a fixed header with a full screen background image under that my sections. what i am trying to do is if i have a alert it will echo above the whole page pushing down the header and hero. but it either wont show up or when i do get it to show it wont stay fixed and scrolls with the page.
.sitrep {
top 0;
height: 50px;
width: 100%;
position: fixed;
z-index: 10000;
}
.siteHeader {
min-height: 76px;
height: 76px;
overflow: visible;
background-color: #000;
color: #f4f4f4;
position: fixed;
top: 0;
z-index: 10000;
}
#hero {
height: 100vh;
}
.hero {
background: url(images/hero-bg.jpg) no-repeat top center;
background-color: #000;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
}
#hero-content {
position: absolute;
width: 100%;
bottom: 0%;
}
#hero-content a {
background-color: #131313;
padding-top: 10px;
height: 40px;
display: block;
font-size: 12px;
text-align: center;
text-transform: uppercase;
text-decoration: none;
}
#hero-content img {
display: block;
margin-top: 2px;
max-height: 145px;
margin-right: auto;
margin-left: auto;
margin-bottom: 53px;
padding: 5px;
}
<div class="sitrep">
<div class="alert-status">
<div class="info">
<span class="closebtn" onclick="this.parentElement.style.display='none';">×</span>
<strong>Announcement!</strong> anouncment goes here.
</div>
</div>
</div>
<div id="siteHeader">my header</div>
<!-- Hero Unit -->
<div id="hero" class="hero">
<div id="hero-content">
<img src="content/images/logo-dt.png" class="img-responsive">
<a class="button" role="button" href="#base">Learn more</a>
</div>
</div>
You are mixing up classes and ID's.
In your HTML, you give the element the ID of sitrep, whereas you are giving the styles to the elements with the class of siterep.
Try either of the following options and you'll be set :
Changing the element attribute: <div id="sitrep"> to <div class="sitrep">
Changing the CSS to fit the proper elements: .sitrep { to #sitrep {
Happy coding !
I have got a simple part of a website where i am using some CSS to get a square tile. The problem is the whole tile is never actually showing up, when i use it in HTML and put a lot of text in it, the width and height attribute dont seem to have any effect on the div. Here
`
.tileYellowDouble {
display: inline-block;
background-color: Black;
height: 200px;
width: 400px;
border: solid 1px black;
}
#imageTile {
float: right;
display: inline-block;
background: url(Thimo.png);
background-size: 100% 100%;
width: 400px;
height: 600px;
border-radius: 0px 10px 10px 0px;
}
body {
background: url(York.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
.main {
position: fixed;
border: solid 1px black;
top: 50%;
left: 50%;
margin-top: -300px;
margin-left: -500px;
width: 1000px;
height: 600px;
background: #35bc7a;
border-radius: 10px;
}
<div class="main">
<div id="imageTile"></div>
<div class="tileYellowDouble">Doesnt show the background color or border</div>
</div>
I just found out that when i comment out .main it does show the box, but when it is back in it just shows a clear background. Also using Z-index doesnt work