I am trying out responsive layout with 100% div wrapper and then placing a background image with text above and below it.
Unable to get it to display.
Looking to get the image to resize with browser window.
What am I doing wrong?
.wrapper {
width: 100%;
}
.image {
background: url("http://upload.wikimedia.org/wikipedia/commons/3/35/Rivi%C3%A8re_Coulonge_Pont_Davidson_1024x768.JPG") no-repeat center;
background-size: cover;
}
.text {
text-align: center;
font-size: 50px;
color: yellow;
}
http://jsfiddle.net/f5F6T/
Looks like you need to give height and width to your .image element. As well as a height to your wrapping div.
u need to set the content in middle div or give height. because initial div does nt have any height so how can u see the background??
check the fiddle-
--HTML--
<div class="wrapper">
<div class="text">Give the height to below div!</div>
<div class="image"></div>
<div class="text">So, here u have ur photo</div>
</div>
--CSS--
.image {
background: url("http://upload.wikimedia.org/wikipedia/commons/3/35/Rivi%C3%A8re_Coulonge_Pont_Davidson_1024x768.JPG") no-repeat center;
background-size: cover;
height:100px;
}
You're .image is actually 0px heigh, that's why the image is not displayed.
Check out this :
just moved the .image code into the .text code :
.text {
background: url("http://upload.wikimedia.org/wikipedia/commons/3/35/Rivi%C3%A8re_Coulonge_Pont_Davidson_1024x768.JPG") no-repeat center;
background-size: cover;
text-align: center;
font-size: 50px;
color: yellow;
}
http://jsfiddle.net/f5F6T/1/
Edit :
.image {
height: 30px;
background: url("http://upload.wikimedia.org/wikipedia/commons/3/35/Rivi%C3%A8re_Coulonge_Pont_Davidson_1024x768.JPG") no-repeat center;
background-size: cover;
}
http://jsfiddle.net/f5F6T/3/
Related
Hi i have written css for fixed header that is banner image should be fixed when we scroll the page the content should be scrolled on the top of the image but if i give the background attachment as fixed the height of the image is getting small and getting blank space at the top as shown in below diagram.
Css i have written this
.partnerspage {
background-image: url(http://www.server.com/bl/banner-1920x375-Partners.jpg);
background-repeat: no-repeat;
background-position: center;
background-attachment: fixed;
}
Here is the fiddle link: https://jsfiddle.net/xykchmg9/1/
Whatever you are looking for here it is: this css can fix your problem I hope
body {margin:0;}
.navbar {
overflow: hidden;
background-color: #333;
position: fixed;
top: 0;
width: 100%;
}
.navbar a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.navbar a:hover {
background: #ddd;
color: black;
}
.main {
padding: 16px;
margin-top: 30px;
height: 1500px; /* Used in this example to enable scrolling */
}
.parallax {
background-image: url("https://dmm8trq3la0u4.cloudfront.net/wp-content/uploads/2018/06/how-to-setup-website.jpg");
min-height: 500px;
/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.contain{
height:1000px;
background-color:#ccc;
font-size:36px;
padding:24px;
}
Html goes here...
<div class="navbar">
Home
News
Contact
</div>
<div class="main">
<div class="parallax"></div>
<div class="contain">
Scroll Up and Down this page to see the parallax scrolling effect.
This div is just here to enable scrolling.
Tip: Try to remove the background-attachment property to remove the scrolling effect.
</div>
</div>
Codepen example you can check it from here
background: transparent url(http://www.server.com/blue/br-banner11.jpg) 0% 0%/100% 70% no-repeat fixed;
i have fixed the background attachment by adding like this.
How can a scale this perfect circle svg to the width of the div and keep in the center - and no repeat it. It is placed as a background image:
<style>
.play_full{
background: url('../_svg/_ionicons_svg_md-play-circle.svg');
position:absolute;
background-size: 100% 100%;
background-repeat: no-repeat;
}
This is what I am getting now?
How can I center the svg V and H?
you can use flexbox position to center, I changed this:
use Flexbox to centering elements in .cotainer
added width and height on .play_full
.container {
border : 1px solid red;
display: inline-flex;
justify-content: center;
align-items: center;
}
.play-full {
display: inline-block;
width: 50px;
height: 50px;
background: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHg9IjBweCIgeT0iMHB4IgogICAgIHdpZHRoPSI1MCIgaGVpZ2h0PSI1MCIKICAgICB2aWV3Qm94PSIwIDAgMzIgMzIiCiAgICAgc3R5bGU9ImZpbGw6IzAwMDAwMDsiPjxnIGlkPSJzdXJmYWNlMSI+PHBhdGggc3R5bGU9IiAiIGQ9Ik0gMTYgN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jkxNDA2IDIzLjIyMjY1NiAyNC44NDM3NSAyMy4zNDM3NSBDIDIyLjg3MTA5NCAyMy42Mjg5MDYgMTkuNjA5Mzc1IDI0IDE2IDI0IEMgMTIuMzkwNjI1IDI0IDkuMTI1IDIzLjYyODkwNiA3LjE1NjI1IDIzLjM0Mzc1IEMgNi4zMTI1IDIzLjIyMjY1NiA1LjY1MjM0NCAyMi41ODIwMzEgNS41IDIxLjc1IEMgNS4yNTc4MTMgMjAuNDI5Njg4IDUgMTguNDc2NTYzIDUgMTYgQyA1IDEzLjUxOTUzMSA1LjI1NzgxMyAxMS41NzAzMTMgNS41IDEwLjI1IEMgNS42NTIzNDQgOS40MTc5NjkgNi4zMDg1OTQgOC43ODEyNSA3LjE1NjI1IDguNjU2MjUgQyA5LjExNzE4OCA4LjM3MTA5NCAxMi4zNjcxODggOCAxNiA4IFogTSAxMyAxMC4yODEyNSBMIDEzIDIxLjcxODc1IEwgMTQuNSAyMC44NzUgTCAyMS41IDE2Ljg3NSBMIDIzIDE2IEwgMjEuNSAxNS4xMjUgTCAxNC41IDExLjEyNSBaIE0gMTUgMTMuNzE4NzUgTCAxOC45Njg3NSAxNiBMIDE1IDE4LjI4MTI1IFogIj48L3BhdGg+PC9nPjwvc3ZnPg==') 50% 50% no-repeat;
background-size: 100%;
}
<div class="container">
<div class="play-full"></div>
</div>
CSS:
.jumbotron{
background: url("jumbotron.jpg") no-repeat center center;
-webkit-background-size: 70%;
-moz-background-size: 70%;
-o-background-size: 70%;
background-size: 70%;
margin-top: 0 auto;
}
.push-spaces {
height: 550px;
}
.supporting {
padding-top: 80px;
padding-bottom: 100px;
}
.supporting .col {
float: left;
width: 33%;
font-family: 'Raleway', sans-serif;
text-align: center;
}
.supporting .glyphicon {
font-size: 4em;
}
HTML:
<div class="jumbotron">
<div class="container-fluid push-spaces">
</div>
</div>
Viewable on voiddevelopment.com
It seems as though whenever I shrink the page to the width of the phone, the image gets a ton of padding on the top and bottom, making it look like there's a lot of white space.
Looks like background-align automatically centers if you do not specify a value.
You centered you background-image in the center center, it means that you background-image situated in the vertical and horizontal center of your block. So, the solution is just remove one center. Like this background: url("jumbotron.jpg") no-repeat center; - in this case you just center background-image in horizontal.
I basically made 960 layout with 3 divs to easily place child divs with images and text. For some reason I can't make the first background-image to display.
What am I doing wrong?
Website concept:
HTML
<div class="wrap">
<div id="left">1
<div id="logo"></div>
</div>
<div id="middle">2</div>
<div id="right">3</div>
</div>
CSS
html, body { background-image:url(../bg.png);
margin: 0;
padding: 0;
border: 0
}
.wrap {
background: #e7e7e7;
text-align: center;
width: 840px;
margin:auto;
padding-left:60px;
padding-right:60px;
}
#left, #middle, #right {
background: #ccc;
display: inline-block;
margin-right: -4px;
width:280px;
}
#logo {
display: block;
position: relative;
background-image:url(../logo.png));
width:40px;
height:40px;
}
background-image:url(../logo.png));
Should be...
background-image: url(../logo.png);
You may also want to use background-repeat: no-repeat; background-position: center center; and background-size: cover; to make proper use of the background of a div.
It looks like you have an extra parenthetic for background-image under #logo in the CSS file. Change it to background-image: url(../logo.png);
This is my website coding and I am already running into problems, please help!
This is my CSS style sheet:
.center {
position: absolute;
left: 50%;
}
body
{
background-color: #45a8e1;
background-image:url('images/background.png');
background-repeat:repeat-x;
}
And then here is the HTML:
<body>
<div id="header" class="center">
<img src="images/header.png">
</div>
</body>
The final results are coming okay but the page is extremely wide. I am trying to fit my background image in the view-port (page). Also, I want to center my div in the center which doesn't seem to be working since the page is so wide.
Use this css:
.center {
display:inline-block;
margin: 0 auto;
}
body
{
width: 100%;
text-align: center;
background-color: #45a8e1;
background:url('images/background.png');
-webkit-background-size: auto 100%;
-moz-background-size: auto 100%;
-o-background-size: auto 100%;
background-size: auto 100%;
background-repeat:repeat-x;
}
Note: background-size is not supported in IE8 and below.
Try this -jsFiddle
#header {
background: url('/*yourImageHere*/') repeat-x center;
height:200px;
width:100%;
}