I'm trying to a language switching system in this website. The idea is to have a SPAN which upon hover displays a dropdown box (UL based) that contains a list of available languages. Here's a snapshot of the effect I'm trying to achieve.
alt text http://img337.imageshack.us/img337/3474/dropboxfinal.png
The dropdown box is actually an unordered list that is hidden by default. Upon hovering on the span, I'm making the UL visible. Here's the HTML and the CSS.
HTML
<span id="langswitch">Language↓
<ul id="langlist">
<li class="en">
<a title="Current language: English" href="http://domain/en">
<img width="16" height="13" alt="English Language" src="flag-en.gif" />
English
</a>
</li>
<li class="th">
<a title="Switch to Thai language" href="http://domain/th">
<img width="16" height="13" alt="Thai Language" src="flag-th.gif" />
Thai
</a>
</li>
<li class="zh">
<a title="Switch to Chinese language" href="http://domain/zh">
<img width="16" height="13" alt="Chinese Language" src="flag-zh.gif" />
Chinese
</a>
<li>
</ul>
</span>
CSS
ul#langlist {
border:1px solid #3399CC;
color:#006699;
background:#fff;
padding:0 !important;
width:100px;
list-style:none;
position:absolute;
top:62px;
right:0;
z-index:100;
display:none;
}
span#langswitch:hover ul#langlist { display:block; }
But instead of the dropdown appearing aligned with my span, it's appearing at the extreme right end of the browser. Here's the screenshot.
alt text http://img84.imageshack.us/img84/1687/dropbox.png
Can any of the CSS gurus here recommend a fix for this?
Thanks,
m^e
just set the position of the "span" to "relative", set a fixed width to the "span" and play a bit with the values "top" and "left" (applied to #langlist) to manage the vertical and horizontal alignment of the list!
EDIT (IN RESPONSE TO YOUR QUESTION): By default, when you place in a web page an element with an absolute position, its position (defined by the attributes "top" and "left") is calculated relatively to the html page ... so, the "left" and "top" values are the "x" and "y" coordinates of an apparent coordinate system whose origin is the top-left corner.
For elements in the head of the webpage there is no problem (in the most of cases), but the elements absolutely positioned in the content of the page are constantly locked on their position so they don't move with the content of the page if the user scrolls or resizes the web page!
If you set to "relative" the position of the element (in this case the span) that contains the absolutely positioned tag, the values "top" and "left" are calculated relatively to this container, so the problem it's fixed!
ABOUT YOUR CODE: Technically you can't apply the "hover" pseudo-class to non link elements if your Doctype is not HTML5, so my suggestion is to consider to use a jQuery function to apply "display: block" to the list when occurs an hover event on the #label. However, you can correct your code as follow ... manage the distance of the list from the #label modifying the "margin-top" value of #langlist:
<style type="text/css">
#container{
position: relative;
width:100px;
}
#langswitch{
padding: 0px;
margin: 0px;
list-style:none;
position:absolute;
}
#langlist {
border:1px solid #39C;
color:#069;
background:#fff;
padding:0 !important;
margin-top: 2px;
width:100px;
top:20px;
left:0px;
display: none;
}
#container:hover #langlist{
display:block;
}
img{
background-color: #CCC;
border: 1px solid black;
}
</style>
<div id="container">
<ul id="langswitch">
<li>
<a id="label" href="#">Language↓</a>
<ul id="langlist">
<li class="en">
<a title="Current language: English" href="http://domain/en">
<img width="16" height="13" alt="English Language" src="flag-en.gif" />
English
</a>
</li>
<li class="th">
<a title="Switch to Thai language" href="http://domain/th">
<img width="16" height="13" alt="Thai Language" src="flag-th.gif" />
Thai
</a>
</li>
<li class="zh">
<a title="Switch to Chinese language" href="http://domain/zh">
<img width="16" height="13" alt="Chinese Language" src="flag-zh.gif" />
Chinese
</a>
</li>
</ul>
</li>
</ul>
</div>
Notice that this solution doesn't work on IE6!
Related
I have the following code
<li><img src="/business/resources/images/btn_dashboard.png" height="100px" width="70%" class="img-responsive img-rounded center-block"></li>
I'd like to change the img src into btn_dashboard_active.png when the li has class="active"
How can I do this in CSS or Bootstrap ?
You can achive that by deleting the src, height, width attributes inside your IMG tag. Then set them in CSS (like in the jsFiddle example below), with the mention that the image paths (the links inside src attribute) will become the content's value.
For displaying different images when li has class active, just change the content's value (the path) inside li.active>a>img selector.
li.active>a>img{
content:url("/business/resources/images/btn_dashboard_active.png");
}
Example: http://jsfiddle.net/L3qsmeje/
Use an alternating image which shows up on demand.
html:
<li>
<a href="/business/account" id="accountLnk" class="list-group-item">
<img src="/business/resources/images/btn_dashboard.png" height="100px" width="70%" class="img-normal img-responsive img-rounded center-block">
<img src="/business/resources/images/btn_dashboard_active.png" height="100px" width="70%" class="img-active img-responsive img-rounded center-block">
</a>
</li>
css:
li .img-normal, li.active .img-active{
display:block;
}
li .img-active, li.active .img-normal{
display:none;
}
I have a banner on web page, and part of the image there is a graphic of a button box. How do I make just the part where the button is a clickable link such as a href? You can see a sample image below.
In the banner image there is a "Join Now, Its Free" Button graphic. I want to add a link on this box, so when users click on this box on the banner, then it will open the next page. I want to know how I can add a link on just this button. I don't want to add the <button> tag to it; I just want to add a link based on the area of the "Join Now, Its Free" Button graphic. Anybody have any ideas on how I can add a link on this part of the image area without using the <button> tag.
<div class="flexslider">
<ul class="slides" runat="server" id="Ul">
<li class="flex-active-slide" style="background: url("images/slider-bg-1.jpg") no-repeat scroll 50% 0px transparent; width: 100%; float: left; margin-right: -100%; position: relative; display: list-item;">
<div class="container">
<div class="sixteen columns contain"></div>
<img runat="server" id="imgSlide1" style="top: 1px; right:
-19px; opacity: 1;" class="item"
src="images/slider1.png" data-topimage="7%">
</div>
</li>
</ul>
</div>
<ul class="flex-direction-nav">
<li><a class="flex-prev" href="#"><i class="icon-angle-left"></i></a></li>
<li><a class="flex-next" href="#"><i class="icon-angle-right"></i></a></li>
</ul>
</div>
Thank You
If you don't want to make the button a separate image, you can use the <area> tag. This is done by using html similar to this:
<img src="imgsrc" width="imgwidth" height="imgheight" alt="alttext" usemap="#mapname">
<map name="mapname">
<area shape="rect" coords="see note 1" href="link" alt="alttext">
</map>
Note 1: The coords=" " attribute must be formatted in this way: coords="x1,y1,x2,y2" where:
x1=top left X coordinate
y1=top left Y coordinate
x2=bottom right X coordinate
y2=bottom right Y coordinate
Note 2: The usemap="#mapname" attribute must include the #.
EDIT:
I looked at your code and added in the <map> and <area> tags where they should be. I also commented out some parts that were either overlapping the image or seemed there for no use.
<div class="flexslider">
<ul class="slides" runat="server" id="Ul">
<li class="flex-active-slide" style="background: url("images/slider-bg-1.jpg") no-repeat scroll 50% 0px transparent; width: 100%; float: left; margin-right: -100%; position: relative; display: list-item;">
<div class="container">
<div class="sixteen columns contain"></div>
<img runat="server" id="imgSlide1" style="top: 1px; right: -19px; opacity: 1;" class="item" src="./test.png" data-topimage="7%" height="358" width="728" usemap="#imgmap" />
<map name="imgmap">
<area shape="rect" coords="48,341,294,275" href="http://www.example.com/">
</map>
<!---->
</div>
</li>
</ul>
</div>
<!-- <ul class="flex-direction-nav">
<li><a class="flex-prev" href="#"><i class="icon-angle-left"></i></a></li>
<li><a class="flex-next" href="#"><i class="icon-angle-right"></i></a></li>
</ul> -->
Notes:
The coord="48,341,294,275" is in reference to your screenshot you posted.
The src="./test.png" is the location and name of the screenshot you posted on my computer.
The href="http://www.example.com/" is an example link.
You can auto generate Image map from this website for selected area of image. https://www.image-map.net/
Easiest way to execute!
by creating an absolute-positioned link inside relative-positioned div..
You need set the link width & height as button dimensions, and left&top coordinates for the left-top corner of button within the wrapping div.
<div style="position:relative">
<img src="" width="??" height="??" />
</div>
The easiest way is to make the "button image" as a separate image.
Then place it over the main image (using "style="position: absolute;".
Assign the URL link to "button image".
and smile :)
I'm having a bit of trouble getting the various products to line up properly on my site. Some of the items have a name long enough to create a second line of text, and when it does so, the items still align with the top of the text rather than aligning the top of each image. Basically I want it to use up some of the empty space above each div to fit a second line of text, rather than pushing my picture down and just aligning at the top. This is the code I'm using to create the divs in a loop within my PHP:
<div class="new_prod_box">
<a href="details.html">
'.$title.'
</a>
<div class="new_prod_bg">
<a href="details.html">
<img src="images/'.$image.'" alt="'.$title.'" title="" class="thumb" border="0" />
</a>
</div>
<a href="cart.php?action=add&id='.$id.'">
<u>Add to cart</u>
</a>
</div>
Here's a picture explaining what I mean: my website
Here's the rules in my CSS:
.new_prod_box{
float:left;
text-align:center;
padding:10px;
width:132px;
height:180px;
}
.new_prod_box a{
padding:5px 0 5px 0;
color:#b5b5b6;
text-decoration:none;
display:block;
}
.new_prod_bg{
width:132px;
height:119px;
text-align:center;
background:url(images/new_prod_box.gif) no-repeat center;
position:relative;
}
Hmmm, if I understand your issue correctly, giving .new_prod_box > a:first-child (selects only the first, top-level <a> element inside .new_prod_box) a defined height should give you what you want. As long as the height is great enough to fit two lines of text in it, it'll keep the elements below in the same position, but still leaves space for the title to break to two lines.
If that isn't what you're looking for, let me know and I'll be happy to help further!
(Edit:) To align single-line titles to the top of the image (rather than having whitespace between them), you could try this method, which I think will work.
First, modify your HTML structure a bit, to add a <span> inside of the first <a> element:
<div class="new_prod_box">
<a href="details.html">
<span>
'.$title.'
</span>
</a>
<div class="new_prod_bg">
<a href="details.html">
<img src="images/'.$image.'" alt="'.$title.'" title="" class="thumb" border="0" />
</a>
</div>
<a href="cart.php?action=add&id='.$id.'">
<u>Add to cart</u>
</a>
</div>
Then, add/modify these styles in your CSS:
.new_prod_box > a:first-child{
height: [tall enough for two lines];
position:relative;
}
.new_prod_box > a:first-child span{
display:block;
position:absolute;
bottom:0;
left:0;
width:100%;
text-align:center;
}
Which I believe should give you what you want. Try it out though, and let me know what happens.
.games_box
{
width:575px;
margin:8px auto;
background:#f8f7f7;
padding:8px;
border-bottom:#000000 1px dotted;
}
<div class="games_box">
<a href='#'>
<img src='$host_name/staff/game-$row[0].gif' width='78' height='75' alt='games' />
<div id='staff' style='position:relative; top:-50px;z-index:1; left:29px'>
<img src='images/staff_picks.png' alt='staffpick' width='50' height='51' /></div>
</a>
</div>
I put staff div.. the games-box div is large..
i use 'clear:both'.. but no use..
1 st
2 nd
place staff pick image
3 rd
finally, z-index used staffpick image, under image more space
Hi you can give parent position relative and child give absolute as like this
Css
.games_box
{
width:575px;
margin:8px auto;
background:#f8f7f7;
padding:8px;
border-bottom:#000000 1px dotted;
position:relative;
}
HTML
<div class="games_box">
<a href='#'>
<img src='$host_name/staff/game-$row[0].gif' width='78' height='75' alt='games' />
<div id='staff' style='position:absolute; top:-5px;z-index:1; left:29px'>
<img src='images/staff_picks.png' alt='staffpick' width='50' height='51' /></div>
</a>
</div>
Live Demo http://jsfiddle.net/rohitazad/grE5A/
To 'suck up the space' you can use margin-top:-50px; or use position:absolute like in this example http://jsfiddle.net/grE5A/2/.
Notice I've given the <a> tag the relative position as it is the 'parent' that #staff needs to be positioned absolutely in.
The reason you had the space under the image is because position:relative; top:-50px moves the staff pick up relative to it's original position, but the parent still behaves like the element is in its original position. (Z-index has no effect what you are trying to do.)
I'm trying to align the share, like and tweet button horizontally but I can't get the share button right. I tried adding vertical align top, changing the height and display:inline but it always remains more or less 10px belowe the others. What should I do to get them all aligned?
<div style='vertical-align: top;'>
<a expr:share_url='data:post.url' name='fb_share'/>
<a class='twitter-share-button' data-count='horizontal' data-lang='es' data-related=':' data-via='' expr:data-text='data:post.title' expr:data-url='data:post.url' href='http://twitter.com/share' rel='nofollow'/>
<iframe allowTransparency='true' expr:src='"http://www.facebook.com/plugins/like.php?href=" + data:post.url + "&layout=button_count&show_faces=false&width=100&action=like&font=arial&colorscheme=light"' frameborder='0' scrolling='no' style='border:none; overflow:hidden; width:110px; height:20px;'/>
</div>
<script src='http://static.ak.fbcdn.net/connect.php/js/FB.Share' type='text/javascript'>
</script>
<script src='http://platform.twitter.com/widgets.js' type='text/javascript'>
</script>
Thanks
An easier method than styling these elements individually, is to sandwich them inside <li> tags--allowing you to position the parent <ul> easily, and also float the <li> tags (creating the 'inline' effect you're after.)
jsFiddle didn't like the facebook APIs, so I used 3 twitter buttons instead; the code looks like:
<ul class="social_network">
<li>
Tweet
</li>
<li>
Tweet
</li>
<li>
Tweet
</li>
</ul>
With some very simple CSS (including a subtle outline so you can see the boundaries of the <li> elements:
.social_network {
position : relative;
list-style-type : none;
}
.social_network li {
float : left;
border : 1px solid rgba(0,0,0,.1);
padding : 6px;
margin : 2px;
}
You can find an example of the above here: http://jsfiddle.net/kgFaW/
This should put you in the right direction. Let me know if you run into any issues with the Facebook APIs.
to do display:inline you can wrap each control into list like this:
<ul><li>
<a class=....../>
</li> <li> <a expr....../> </li></ul>
Also, add: list-style-type:none;
To make your controls stick to the right side of the screen,
do:
position:absolute;
right:0;