This question already has an answer here:
How to have both position fixed and background-attachment fixed?
(1 answer)
Closed 2 years ago.
I have a parent div which is holding links called #linkHolder. I have its position:fixed. The links have a background which have a background-attachment: fixed to give it that nice background effect. Those two things seem to cancel each other out. Is there a way around this issue?
#linkHolder {
display: block;
position: fixed;
top: 0;
width: 100%;
}
ul {
list-style-type: none;
overflow: hidden;
background-color: #1b242f;
text-align: right;
font-size: 22px;
width: 100%;
font-family: "Sansita Swashed";
}
ul li {
display: inline-block;
padding-right: 6%;
}
#homeLink {
background-image: url("/static/portfolioBackground/linkBackA.png");
background-repeat: no-repeat;
background-size: cover;
background-position: center;
background-attachment: fixed;
}
<div id="linkHolder">
<ul>
<li><a id="homeLink" href="/">Home</a></li>
<li><a id="aboutLink" href="/about">About</a></li>
<li><a id="serviceLink" href="service">Services</a></li>
</ul>
</div>
Here's the issue on codepen I am having.
https://codepen.io/webdev154676/pen/VwjNoRN
Here's what I would like to have with the background image, but with the #linkHolder as position fixed, it will not work. Please help, and thank you for your time.
https://codepen.io/webdev154676/pen/rNLgBVv
From your question I'm understanding that the issue is that the background image is a little more blurred than what you would like to have.
For that i sudjest you to try using the background-size attribute and play around with it giving some sizes in % like
#homeLink{
background-size:90% 100%;
}
Related
This question already has answers here:
How to apply a CSS filter to a background image
(22 answers)
Closed 3 years ago.
Hi I have <div class="jumbotron text-center"><nav>something</nav></div> this line of code and the jumbotron has some CSS effects something like
.jumbotron{
background: url("image-url") no-repeat center center;
-webkit-background-size: 100% 100%;
-moz-background-size: 100% 100%;
-o-background-size: 100% 100%;
background-size: 100% 100%;
background-size: cover;
height: 78vh;
filter: brightness(50%);
}
but all I want is only the jumbotron's background image gets the CSS effects, not the nav tag. currently, the nav tag inherits thefilter: brigtness (50%), is there anyway only the background-image gets the effect?
No, it's not possible. A filter will affect current element with all its contents (including children).
Therefore the way to go here is to move <nav> outside of .jumbotron, wrap them in a common relative parent and render <nav> above .jumbotron.
Proof of concept:
.relative {
position: relative;
}
.relative > .absolute {
position: absolute;
width: 100%;
top: 0;
/* making it visible */
background-color: rgba(255,255,255,.25);
border-bottom: 1px solid white;
color: white;
padding: 1rem;
box-sizing: border-box;
}
.jumbotron{
background: url("https://picsum.photos/id/237/1024/540") no-repeat center center /cover;
height: 78vh;
filter: brightness(50%);
}
<div class="relative">
<div class="jumbotron"></div>
<nav class="absolute">something</nav>
</div>
Feel free to rename the classes and adjust to your particular needs.
This question already has answers here:
How do I vertically center text with CSS? [duplicate]
(37 answers)
Closed 8 years ago.
i waited for 7 days to ask this question because i can't ask more question,
i want to keep the wrapper in the middle when people re-size the page
header {
background-image: url("http://lorempixel.com/400/200");
background-size: 100% 100%;
height: 100px;
}
#home {
position:absolute;
top:10px;
left:400px;
}
<header>
<img id="home" src="https://cdn2.iconfinder.com/data/icons/snipicons/5000/home-128.png" alt="home" style="width:75px;height:67px">
</header>
thnx
You could simply add text-align: center to the parent element. The img will respect this because it is inline by default.
Updated Example
header {
background-image: url("http://lorempixel.com/400/200");
background-size: 100% 100%;
height: 100px;
text-align: center;
}
See this answer for alternative approaches.
That should do it, if all you need is keeping the icon centred all the time you don't really need to absolute position it.
header {
background-image: url("http://lorempixel.com/400/200");
background-size: 100% 100%;
height: 100px;
text-align: center;
}
#home {
margin-top: 10px;
}
try this,
#home {
position:absolute;
top:10px;
left:48%;
}
I am new to css and the image for my header is not displaying. Whenever I try to add it to my header the nav gets a slightly darker tint of red? You and your genius minds figure it out!
css:
header {
background: url("http://www.charlottecentercity.org/wp-content/uploads/2013/09/Imaginon-pic.jpg");
background-size: cover;
image-repeat: no-repeat;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
vertical-align: middle;
line-height: 70px;
display: inline;
}
li {
display: inline;
}
nav {
background: rgba(255,0,0,0.5);
}
nav img {
height: 60px;
margin: 5px;
float: left;
}
html:
<header>
<nav>
<img src="https://dl.dropboxusercontent.com/u/105222237/RGBjpeg.png" />
<ul>
<li>About Imaginon</li>
<li>General Info</li>
<li>Programs and Events</li>
<li>Plan Your Visit</li>
<li>Just for Fun</li>
</ul>
</nav>
</header>
The background image is showing on the header, but:
it is set to background-size: cover, which means that you only see the very top, blue part. Presumably, when you have more content, you'll see more of the header, but in the mean time you could add a min-height: 600px; for example.
the nav has a reddish, semi-transparent background color that sits on top of the header background color. Just remove that red color if you don't want it.
Try and give the header (min/max) width / height
Add css overflow:hidden to your header.. and do the same
in future to all your wrapper elements.
Do give the header a defined size, as it will not be able to fill something that does not have a defined size to it.
header {
margin: 0;
padding: 0;
width: 100%;
height: 100px;
background: url(../wp-content/uploads/2013/09/Imaginon-pic.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
If your style sheet is in a subfolder like I usually have, make sure to add ".." to your image location to tell css to step back one directory. Using a direct path will require another http request, not a huge deal but slows your site down in the long run.
I included the webkit background code because I believe it to be easier to use. As well as creating browser compatibility.
I have an html portion of code in my page that goes something like this:
<section class ="sidebar">
<ul>
<li class="facebook">Facebook</li>
<li class="linkedin">LinkedIn</li>
<li class="twitter">Twitter</li>
<li class="google-plus">Google+</li>
</ul>
</section>
And the css goes like this:
.sidebar ul {
float: left;
}
.sidebar ul li{
display: block;
width:35px;
text-indent: -9999px;
margin: 3px;
}
li.facebook{
height: 35px;
background: url(img/icon_face.png) center center no-repeat;
background-size: contain;
}
li.twitter{
height: 35px;
background: url(img/icon_twitter.png) center center no-repeat;
background-size: contain;
}
li.google-plus{
height: 35px;
background: url(img/icon_g+.png) center center no-repeat;
background-size: contain;
}
li.linkedin{
height: 35px;
background: url(img/icon_in.png) center center no-repeat;
background-size: contain;
}
What happens here is that I have 2 strange issues:
First the element li.google-plus does not show in any of the browsers. The browsers just ignore it. Here is what firebug shows:
The second is that the only image that shows in firefox is the twitter one. In chrome and opera all the other ones show correctly. As they are showing correctly in other browsers I assume the problem is not the path in the background property.
Any idea on what the problem may be?
EDIT:
Check what firebug says about the background image path:
It says that it couldn't load the given url.
Both in .sidebar ul li and in li.facebook,li.twitter etc. You should write width: and height: properties which You didn't set.
Ok, so it turns out that the problem was my AdBlock extension. After disabling it, it started working normally.
Figured it out through this answer: https://stackoverflow.com/a/466020/1235708
This question already has answers here:
Stretch and scale a CSS image in the background - with CSS only
(22 answers)
Closed 8 years ago.
So my problem is i need my navbar background-image to go the entire distance of the page width wise. here is a fiddle: http://jsfiddle.net/faytAlvein/FDVby/4/
the black under the nav is fine ignore that. that's not there in the original because it's a different background image. just the width is the problem. it needs to scale 100% of the page no matter the window size. real background image is 1145x144 if that helps.
<div id="navbar" >
<div id="links" >
<a href="thisindexpage.php" class="navLink" >Home</a>
<a href="aboutUs.html" class="navLink" >About Us</a>
</div>
</div>
navbar.css
#navbar
{
background-image: url('../images/nav.png');
background-repeat: no-repeat;
background-color: black;
}
#links
{
font-size: 20px;
font-family: helvetica;
padding-top: 25px;
padding-bottom: 94px;
margin-left: 150px;
}
You could "stretch" your background image to 100%, using the background-size property.
background-size: 100%;
Your CSS:
#navbar {
background-image: url('../images/nav.png');
background-repeat: no-repeat;
background-color: black;
background-size: 100%;
}
http://jsfiddle.net/FDVby/7/
Use the background-size property
Here's the documentation: https://developer.mozilla.org/en-US/docs/CSS/background-size