I currently have it to where the current link is "underlined", but the underline is an image as I wanted it to look Android-style. The image looks like this when the web page is loaded on a normal desktop pc:
The image itself is a simple image with the top 90% transparent and the bottom 1/8th of it blue. Whenever the web page is loaded on a phone, it turns into this:
The css for it is this:
#currentlink
{
background-image:url('../images/menu-underline.png');
background-position:center;
}
With this html:
<div id="menu">
<ul id="menulinks">
<li>About me</li>
<li><a id="currentlink" href="">Apps & Projects</a></li>
<li>Work with Me</li>
</ul>
<hr>
I have also tried making the image simply just the blue line, and changing the css to have background-position:bottom but it made the whole entire box blue.
Why not just use the border-bottom property?
#currentlink {
border-bottom: 5px solid #35B5E5; /* this is your blue color */
}
The problem is on a phone your li's are adjusting, and the image isnt scaling proportionally.
This should resolve your issue:
#currentlink {
background-image:url('../images/menu-underline.png') no-repeat center center fixed;
}
The problem is your background image repeated itself, for the Android Device, in which you viewing the WebPage, either you can fire media queries for the same to adjust the background image for specific resolution only.
As #natewiley suggested I'd recommend doing such simple styling with CSS only, so your client doesn't have to download extra assets (images). But in your particular case, since on a phone the size of the list items changes and thus causing the background image to shift position.
You can try setting background-repeat: no-repeat to prevent the background image from repeating itself to fill the space, so you should at least see just one blue line instead of two. Though you'll need to adjust where the blue line should be.
Related
I'm trying to figure out how to have a full background image (background-size: cover) be fixed initially (the text over the image scrolls while the image stays put), but, at the moment when the user scrolls down to the end of the content (like a tall block of text), the background then scrolls up revealing a new section/div below.
For example:
<section id="top-section-with-fixed-bg">
<div class="tall-content-1500px">
<p>Text that's really tall</p>
</div>
</section>
<section id="next-section">
...
</section>
But, again, the background image is fixed until the user has scrolled down 1500px and the content for that section/div is done. At that point, the user continues to scroll and the background image scrolls up.
Not, as with parallax solutions, with the background image being covered by the next section. But the background image going up with the scroll.
I'm thinking this takes some javascript, jQuery fixing, but I'm still a bit novice with it. I'm a designer just wanting a site to look and act this certain way. I'm guessing I have to recognize the height of the content, where that ends, and then either tell the CSS to switch from fixed to scroll (without effecting the position of the image), or having the js move the image up with the scroll action.
Update: Here's a quickly tossed together jsfiddle
UPDATED UPDATE:
I think I've found the solution!
With the pointers provided in responses here, then some digging around, I have it kind of working.
I started with trying to figure out how to detect the window height. I plug that into the text/content DIV, using that value for the DIVs height. This is important, to set the container for the text to the height of the user's window, not to a specific height. Then, I set that DIV to overflow: auto (and hide the scrollbar, for aesthetics). That allowed me to set a trigger so when the end of the content in that DIV is reached, the background-attachment is changed from fixed to scroll.
And, voila! It's not perfect, and I'm sure some real javascript/jQuery experts will right my wrongs on it, but I like how far I've gotten with this so far.
I realize that the swtich from fixed to scroll is probably unnecessary. At the moment, when the switch happens, the image jumps a little to adjust to the window size and its own position, now being set to scroll. If I set the CSS originally to fixed, and make sure the content of the DIV (using padding wisely) to cover the window, as the user scrolls with the mouse the correct action will occur: text scrolls until there is no more text, then the image scrolls up.
Check it out and look forward to help and comments.
jsfiddle
have you set background-attachment:fixed;? This makes background images 'move' with the browser scroll. Be careful when it comes to devices though as this method can cause 'laggy looking sites' because there's too much render for the device (depending on image).
I personally target 'large' and 'modern' browsers with this:
#media query and (max-width:600px){
.top-section-with-fixed-bg{background-attachment:fixed;}
}
EDIT:
sorry I didn't fully understand the question. Here's some CSS to get you going
window.addEventListener('scroll',function(){
//document.body.scrollTop would be the windows scroll position.
if(document.body.scrollTop==1500px)
document.getElementById('top-section-with-fixed-bg').style.backgroundAttachment='static';
}else document.getElementById('top-section-with-fixed-bg').style.backgroundAttachment='fixed';
});
I'm very sorry but this is very basic. I'm about to finish work. The function could use a bit of sprucing up a bit like making it dynamic. This is also only native JS. So it's not all that fancy but you get the idea. When the document.body.scrollTop is at the bottom of your element. Which I'm guessing is 1500px tall? IF not use offsetHeight(). That'll give you the complete height of the element including padding and margins and I think borders as well?
I'd set your background images to background-position: fixed; then put the next background image at the bottom of the text so it overlays on top of the first div. Problem is you can't have the nice <section> structure you had going before.
<style type="text/css">
.section-with-fixed-bg {
min-height: 100%;
background-size: cover;
background-attachment: fixed;
background-repeat: no-repeat;
background-position: center center;
}
#bg-1 {
background-image: url("./background-1.jpg");
}
#bg-2 {
background-image: url("./background-2.jpg");
}
#bg-2 {
background-image: url("./background-3.jpg");
}
</style>
...
<body>
<div id="bg-1" class="section-with-fixed-bg">
<p>Text that's really tall</p>
<div id="bg-2" class="section-with-fixed-bg">
<p>Next section of text that's really tall.</p>
<div id="bg-3" class="section-with-fixed-bg">
<p>Next section of text that's really tall.</p>
</div>
</div>
</div>
I haven't tested this but it should cause the new image to overlap the old one, at least in theory.
EDIT: background-position does change the position of the background image. I realized the actual problem I am facing is something else, which can be seen on this thread:
Background image disappears when changing its background-position?
Okay so I have a set of links (a href's) inside an unordered list, and when the user hovers over them, I want a black background image to show up on top of the link and change the links color to black. I already have the background image which shows up photoshoped. Here is what I did so far
li:hover {
color: white;
background: url(../images/liHover.png);
}
Now, the problem is that the image doesn't show where I want it to show. I want the link to be in the center of the image. The image is like 3 pixels below where I actually want it to be. It is the same for which ever link I hover over, the image is always 3 pixels below where I want it to be. Is there a way to change the position of the image which shows up and a way to move that image a few pixels above where it is normally supposed to be? (even if we cannot do this with CSS, if someone can write a Javascript function which can get this accomplished, that would be great).
The list is just
<ul>
<li>item1</li>
<li>item2</li>
<li>item3</li>
</ul>
i think this is what you mean:
li:hover {
color: white;
background: url(../images/liHover.png) no-repeat center center;
}
if it doesn't center the way you want, play with the center center values which are x / y (horizontal / vertical). they can be also px,em or % values.
I am attempting to create a mouse-over effect on a navigation on my website.
The navigation is a horizontal bar with a few items in it. Code for it below;
<ul>
<li>Home</li>
<li>About us</li>
<li>Our work and portfolio</li>
<li>Contact</li>
</ul>
This has a plain background color and between every <li> is a border to separate the items. Now I want to give a background image on hover, though my problem is that - as you can see - every <li> has a different width because of its contents and my image for the hover is as below;
So it's actually just a black shadow on the left and right. The right shadow must be placed on the absolute right side of the <li> and the left shadow on the absolute left.
Is there any way to achieve this? Not a problem if it's with jQuery or anything like that.
Thanks in advance.
If you want the shadow, and the variable length effect. Then split the image into three parts. And update your markup to something like this
Left Shadow
Center Part
Right Shadow
Then use the following CSS snippet
li a:hover:before { content: url("image/leftshadow.jpg"); }
li a:hover { background-Image: url("image/center.jpg"); }
li a:hover:after { content: url("image/rightshadow.jpg"); }
Your image looks like a linear gradient, so you could try using
background-image: linear-gradient(to right, #111, #333, #111);
You may want to add support for older browsers.
I need to slide a background when clicking the "next" arrow, and the "previous" arrow - right now the background is in the #container element - However, that doesnt work - I've tried putting the background on the ul#slider element - But that doesnt work either...
What i need is that the background will be slider as much as the liinside the slider...
Any suggestions on how to do that ?
You can see the project here: http://www.i-creative.dk/Slider/
thx
I've built something like what you're asking for, and it's a total pain.
The problem is, you're talking about having a different background image, the size of the page, for EVERY slide.
2 options are:
1: Have one BIG background image, with all the background aligned horizontally, and animate the css background-position when you change a div, to keep things matching. This ahs the advanatage that only one image needs to be downloaded, but it will be big.
Problems are: you see all the other images if you jump multiple steps at once;
it requires that you use a fixed width;
it's a pain if you want to change the background for just one slide;
Preload the background for the next slide on a div which is a sibling of container but has a higher z-index. Use jquery to slide this over the existing background, from the appropriate side.
The good thing about this method is that you can use css to make the background image always take up the full-width of the screen, or use a bigger imager and have it centred. See here: http://cksk.com for an example.
Long story short, you won't get this working with an off-the-shelf solution, you'll need to get your hands dirty.
Also, you'll need to spend a hell of a lot of time on optimisation.
Try this css...
#slider {
width: 472px; /* divided the width of the background image by 4 (# of panels) */
height: 570px;
list-style: none;
/* start background after the initial cloned panel: 472px to match panel width */
background: transparent url(../images/background.png) 472px 0 repeat-x;
}
/* This makes sure the last cloned panel background matches the first panel */
ul#slider li.clone {
background: transparent url(../images/background.png) 0 0 repeat-x !important;
}
/* Make the background visible */
div.anythingSlider .anythingWindow {
overflow: visible !important;
}
The only problem is that the width of the UL is limited, so when you get to the last panel, the background ends, but reappears once you hit the right arrow.
I have a picture of a shirt on my html webpage, and what I want is to be able to show a hidden image that is on the shirt by clicking a button, however I want it to become part of the shirt like if it were a hidden photoshop layer so basically with a button click it would cycle through different designs changing on the shirt itself, is there anyway to do that or is the image always going to have a square background?
Thanks,
What about making your 'shirt image' the background of div and inside that div have an img of which you change the src attribute with a simple javascript.
Have a look at this idea:
HTML
<div id="shirtimagebackground">
<img id="overlay" src="overlayX.png"/>
</div>
CSS
#shirtimagebackground {
background-image: url(shirt.png);
width: Xpx;
height: Ypx;
}
#overlay {
width: 100%;
height: 100%;
}
You need to use a combination of javascript, and a absolutly positioned, hidden, image using css.
This image will have to be a .png with apha transparency.
Bear in mind that Internet Explorer 6 does not support transparency, so if this browser is in your target market include a "png fix" like DD_belated.
You can have a see through background with solid images on the top, and place the image over your t-shirt image. However, not all tools allow you to do this (for example, Microsoft's paint does not provide this functionality). One free open source tool that I've used before that has this functionality is Paint.net. Look into "Transparency - Alpha" if you go with that paint program.