CSS drop down menu - html

I want to make a drop down list with nice buttons that are long as the screen (compatible with more screens)....
I will use 3 images (left , middle and right) ... something like this (of course, smaller):
The middle part will repeat itself to "fill" the button. I want to get something like this:
There is no example with 3 images, all I could found is only 2 images.

my solution:
html:
<div class="button">
<div class="left"></div>
<div class="inner">text</div>
<div class="clear"></div>
</div>
css:
* {margin: 0px; padding: 0px;}
.clear {clear: both; height: 0px; font-size: 0px; line-height: 0px;}
.button {
padding-right: 15px; /* right image width */
background: url('right_image.jpg') no-repeat right top;
height: 20px; /* images height */
}
.button .left {
background: url('left_image.jpg') no-repeat right top;
width: 15px; /* left image width */
height: 20px; /* images height */
float: left;
}
.button .inner {
height: 20px; /* images height */
background: url('middle_image.jpg') repeat-x right top;
text-align: center;
}
jsFiddle Demo

It's very easy.
That's html:
<button>
<span><span> MENU </span></span>
</button>
You should place all parts of your image in a very wide none-transparent(for transparent png method is harder a little bit) PNG(like it looks on design), trimmed to the image content. (one image wouldn't increase size much, but will make less http request to server). It called sprite.
button { }
button span {
padding:0 0 0 25px;
background:url('image.png') left 0;
display:inline-block;
height:25px;
line-height:25px;
}
button span span {
padding:0 25px 0 0;
background:url('image.png') right 0;
}
That's it. Of course you should place your image name, and your values of padding, height and line-height.

There are no examples with 3 images because you don't need 3 images. Create a small right images (like you have posted above) and create a left + center image with your maximum width (let's say 800px). Set the left sided / background image on a <li> and hook the right side up to the <a>.
<li>
Link
</li>

Try this - this uses 3 background images which isn't compatible with IE8 and below, but you could use two inner divs to give you three containers and put one image in each - note the bottom image is listed last.
nav {
height:75px; /* height of graphic elements */
background:
url(images/left_end.png) no-repeat 0px 0px,
url(images/right_end.png) no-repeat right top,
url(images/center.png); /* this images repeats */
}

Related

How to attach an icon next to a link using an ending selectors?

The issue I'm having is that my link is being placed over the icon, so that the icon is in the background, not next to it as I would like. How would you write this so that the icon would be to the left of the link?
HTML:
<p>Hunger Games, Chapter 1</p>
CSS:
a[href $=".pdf"] {
background: url('image.png') no-repeat center left;
padding-left 25px;
}
I have updated your code and it seems to work just fine..
SEE HERE
a[href$=".pdf"] {
background: url('http://cdn.cutestpaw.com/wp-content/uploads/2011/11/cute-cat-l.jpg') no-repeat center left;
padding-left: 25px; /* you forgot the colon here */
background-size: auto 100%; /* make the background size 100% of the height of the anchor link */
}

CSS Sprits, Add Padding to Background Image

i'm new to css sprits. i have added a small red color arrow like image to all links in a DIV ID. it looks like this.(image attached)
how to get some padding after the background image ? i mean some space between image and text using CSS.
CSS
#maincontent a:link {
background: url(images/css-images.png) no-repeat top left;
background-position: 0 0;
width: 4px;
height: 12px;
display:inline;
}
HTML
<div id="maincontent">
Btech III
</div>
i tried adding to css padding right, but it is giving some space after text not after image.
You want to use padding on your link, this will leave the background where it is but move the text, try padding-left: 25px;. But adding padding will add to the width so you will want to adjust the width of your link and reduce it by the amount of padding you have added (maybe not in this example)
Also your example image isn't loading
Try this:
#maincontent a:link {
background: url(images/css-images.png) no-repeat top left;
background-position: 0 0;
width: 4px;
padding-left: 25px;
height: 12px;
display:inline;
}
just apply a padding-left or a text-indent to your link

Fix left and right floating images in HTML

Here's what I'd like to do: have a banner across the top of a website which stretches all across. On the left is a menu, and on the right a logo image; the menu floats left, the image floats right.
The problem is the resizing of the browser window. Because the image floats right, it correctly moves as the window gets smaller. However, at some point it begins to float into the menu. Here is a Fiddle that illustrates this effect with two floating images. Resize the browser window to see how the two images overlap.
Setting
body {
min-width: 800px;
}
I can now make sure that the scrollbar appears as the browser window reaches a certain minimum width. However, that doesn't hinder the right-floating image to keep moving as the browser window keeps getting smaller. I tried to change position: relative but that didn't work. I tried to use Javascript to fixate the images once the browser window reaches its min-width but that didn't seem to have an impact either. Using min-width on the DIV and making the images children of the DIV didn't work either.
My question is: how can I make sure that, starting at a certain window size, the right-floating image stays put instead of floating into the left-floating menu?
EDIT: Oh dear, I forgot to mention a rather important detail: the menu bar at the top needs to be sticky. That is why I used the position: fixed property for the DIV. The other page content is supposed to scroll under that menu and out of the window, see the modified fiddle here which is based on ntgCleaner's answer. This kind-of changes the whole thing, doesn't it! Sorry about that...
Thanks!
A couple things I changed:
I made your banner DIV a container instead of just a free floating div. Probably not necessary.
I gave that banner div a min-width:280px and made it overflow:hidden;
I made the images just float left and right, not positioned relatively or absolute (since it's in the div container now).
#banner {
left: 0px;
top: 0px;
width: 100%;
height: 60px;
background-color: lightblue;
z-index: 1;
opacity: 0.8;
overflow:hidden;
min-width:280px;
}
#left {
float:left;
margin:5px;
height:40px;
}
#right {
float:right;
margin:5px;
height:40px;
}
​
​
Here's the fiddle
EDITED FOR THE EDITED QUESTION:
You will just need to place all of your content under your header into a div, then give that div a top margin of the height of your fixed div. In this caes, it's 60px.
Add this to your HTML
<div id="content">
this <br>
is <br>
some <br>
test <br>
text <br>
</div>
then add this to your CSS
#content {
margin:60px 0px 0px 0px;
}​
Here's the new fiddle
Is this what you are after? http://jsfiddle.net/9wNEx/10/
You are not using the position: fixed correctly. Fixed means 'positioned relative to the viewport or browser window', and that is exactly what you are experiencing.
I removed the position: fixed from the images, and placed them inside the div. This should keep them always on top of the page, as they are inside the div that is still positioned fixed.
Also I tweaked some of the other styling to replicate your example. Note that i removed the fixed height of the head and replaced it by a padding bottom. This way the height will follow the content whenever the screen size becomes to small and the images are forced underneath each other.
The css looks like this now:
#banner {
left: 0px;
top: 0px;
width: 100%;
padding-bottom: 15px;
background-color: lightblue;
z-index: 1;
position: fixed;
opacity: 0.8;
}
#left {
float: left;
margin-left: 10px;
margin-top: 5px;
height: 40px;
}
#right {
float: right;
margin-right: 10px;
margin-top: 5px;
height: 40px;
}
I changed your HTML to put the <img> tags inside the banner, and added the min-width to the #banner since it has position: fixed. You'll still need to add min-width to the body or a container that wraps all other elements if you want there to be a min-width of the entire page.
http://jsfiddle.net/Wexcode/s8bQL/
<div id="banner">
<img id="left" src="http://www.google.com/images/srpr/logo3w.png" />
<img id="right" src="http://www.google.com/images/srpr/logo3w.png" />
</div>
#banner {
width: 100%;
min-width: 800px;
height: 60px;
background-color: lightblue;
z-index: 1;
position: fixed;
opacity: 0.8; }
#left {
float: left;
margin: 5px 0 0 10px;
height: 40px; }
#right {
float: right;
margin: 5px 10px 0 0;
height: 40px; }
​
When I look at your Fiddle I think your problem isn't the floats at all. position:fixed supersedes float. Those two elements aren't floating at all, they're in a fixed position (similar to an absolute position), which is why they overlap when they don't have enough room.
Take out float:left and float:right, the result will be the same. Also, top, left, bottom, and right don't work on non-positioned elements. So they are superfluous on your banner.
If you use floats, however, when there is not enough room the right image will wrap underneath the left. See http://codepen.io/morewry/pen/rjCGd. Assuming the heights on the images were set for jsfiddle testing only, all you need is:
.banner {
padding: 5px; /* don't repeat padding unnecessarily */
min-width: ??; /* to keep floats from wrapping, set one */
overflow: hidden; /* clearfix */
}
.right { float: right; } /* only need one float, don't over-complicate it with two */

Cutting out the middle portion of an image (example shown)?

This is something I've seen done by Grooveshark, which removes the need to use multiple images for expandable buttons and such.
Basically, an image like this
is used to produce buttons of any width smaller than the image itself. I assume this is done by somehow trimming out the middle, but I'm not sure how. I've looked over the CSS properties for it's usage here but can't seem to find out what's done aside from a 15px padding on either side.
Does anyone know how to replicate the same effect?
Edit: Just for clarity, I'm talking about cutting out the middle of a single button (I do realize I've given a picture of a sprite for 4 button styles, so it might be confusing when I say "cutting out the middle portion of an image").
What you're talking about is known as the sliding doors technique. By applying the background image to a container element to show the left edge, you can then apply the same image to another element that only shows the right edge.
For example:
.menu li {
background: url(button-sprite.png) 0 0 no-repeat;
padding-left: 10px;
}
.menu li a {
background: url(button-sprite.png) 100% 0 no-repeat;
display: block;
}
The list item shows the left edge of the image. The padding allows the left edge to show when another element is laid on top.
The anchor element shows the right edge of the image, and it is cropped to the required width of the text content.
CSS allows to move background image to any position.
In order to display part of the background you need to define CSS like the following:
.button {
background: transparent url(sprite.png) left top no-repeat;
display: block;
height: 40px;
width: 160px;
}
.button:hover {
background-position: left bottom;
}
.button:focus {
background-position: left center;
/* or
background-position: left -50%;
background-position: left -40px;
*/
}
#Pixelatron; i know you accept the answer but check this example may be that's help you & easy solution as well http://jsfiddle.net/sandeep/CQmJz/
css:
a{
text-decoration:none;
display:inline-block;
background:url(http://i.stack.imgur.com/gYknG.png) no-repeat 0 0;
position:relative;
padding:8px 0 8px 10px;
height:17px;
}
a:after{
content:"";
display:block;
background:url(http://i.stack.imgur.com/gYknG.png) no-repeat -490px 0;
position:absolute;
height:33px;
width:10px;
top:0;
right:-10px;
}
a:hover{
background-position:0 -34px;
}
a:hover:after{
background-position:-490px -34px;
}
I know of no way to manipulate images like that in CSS,
I think you'll find what they do is have the top image and bottom image always top and bottom, and just fill the rest with a middle image.
This can also be applied to each side, i'll add the CSS3 code, the CSS2 code should be easy to determine.
This would look like (CSS3):
.button_horizontal {
background: url(topimage) top left no-repeat,
url(bottomimage) bottom left no-repeat,
url(middleimage) top left repeat-y;
}
.button_vertical {
background: url(left.png) top left no-repeat,
url(right.png) top right no-repeat,
url(middle.png) top left repeat-x;
}
This would look like (CSS2):
.top {
background: url(top.png) top left no-repeat;
width:100%;
height:10px;
}
.middle {
background: url(bottom.png) bottom left no-repeat;
width:100%;
height:180px;
}
.button{
background: url(middle.png) top left repeat-y;
width:500px;
height:200px;
}
<div class="button">
<div class="top"> </div>
<div class="middle"><p>stuff goes in here :D</p></div>
</div>
That is called border-image.

Create CSS background image that overlays border?

I am having trouble getting a background-image to overlay the border of another div. We have a sidebar panel with various sidebars, including a navigation menu. To the right is the content panel. We'd like anything selected on the sidebar to appear connected to the content panel:
In the example above, there is a background image on the Personal Info <li> tag. I'd like to extend this image one pixel to the right so that the line next to the selected value isn't visible.
Here is my CSS for the submenu (selected) and the Content area to the right:
.submenu-item li span{
padding: 4px 0 4px 16px;
min-height: 16px;
border-bottom:0px;
}
.submenu-item li{
font-size:12px;
border: none;
padding: 0px 0 0px 16px;
}
.submenu-item span.Active{
background-image: url(../images/submenu-select.png);
background-repeat: no-repeat;
}
#Content {
margin-left:190px;
border-left: 1px solid #b0b0b0;
padding: 20px;
background: #FFFFFF;
min-height:600px;
}
Is there a way to do this other than putting a right border on my sidebar (and excluding it on the list item tag)?
If you have a border on that right, you just can't eliminate that part of the border.
However, you're in luck. Try using margin-right: -1px; in your CSS. This will drag the
element to the right 1 pixel, and hopefully over the border. You may need to also set
position: relative;
z-index: 100;
Also, because it's over to the right 1 pixel, to make it align on the left with the others, you may need to make the active element 1 pixel wider.
Alex's solution should work, but another way to do it would be to remove the border-left CSS atrtribute from #Content and instead use a 1 pixel wide gray GIF or PNG image on the DIV containing the submenu items.
Like this:
#SubMenu { background: url(grayline.gif) #CCCCCC top right; }
That would remove the need to worry about the selected submenu element not being aligned.