This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I have these css code:
.tabs_inactive {
border: 1px solid #cccccc;
border-top-left-radius: 8px;
border-top-right-radius: 8px;
background-color: #eeeeee;
border-bottom: #cccccc;
}
.tabs_inactive:hover {
background-color: #ff8000;
border-color: #ff8000;
cursor: pointer;
}
/*this does not work*/
.tabs_inactive:hover a {
color: #ffffff;
}
.tabs_active {
background-color: #ffffff;
border-bottom: 2px solid #ffffff;
}
.tabs_active:hover{
background-color: #ffffff;
border: 1px solid #cccccc;
border-bottom: 2px solid #ffffff;
cursor: default;
}
.tabs_active:hover a {
cursor: default;
}
The last one (.tab_active:hover a) is working perfectly in my webpage, but the third block is not. I can not figure out why this happened.
Could somebody explain me why the third block doesn't work?
Thanks!
UPDATE 1:
Here is the relative JavaScript code:
//add class "tabs_inactive" to the original tabs option.
$( "#tabs ul li" ).addClass("tabs_inactive");
//default: set the first tab as the active one.
$( "#tabs ul li" ).first().toggleClass("tabs_active");
//to make sure the style sheet will be changed when click on the inside <a> tag
$( "#tabs ul li a" ).live( "click", function () {
//close other tabs
$( this ).parents("ul").children("li").each( function (){
if( $(this).hasClass("tabs_active")){
$(this).removeClass("tabs_active");
}
});
$( this ).parent().toggleClass("tabs_active");
return false;
});
//change the class to "tabs_active" when the tab is clicked
$( "#tabs ul li" ).live( "click", function () {
//close other tab
$( this ).parent().children("li").each( function (){
if( $(this).hasClass("tabs_active")){
$(this).removeClass("tabs_active");
}
});
$( this ).toggleClass("tabs_active");
});
And also HTML code:
<div id="tabs">
<ul>
<li>HOME </li>
<li>option1 </li>
</ul>
<div id="homepage">
<p>
HOME:
Here is the home page
</p>
</div>
<div id="option1">
<p>
Option1:
Here is the tag page 1
</p>
</div>
</div>
So, yes, I am trying to implement a tab menu, and this is a practice so I don't want to use the original JqueryUI function. Dose somebody know that what is the problem?
Thank you.
Sorry guys, it's not a typo or something else, I just make a mistake that I give a font color style to the #tab ul li a before, which is using the id selector, and that make the the function toggleClass doesn't work at all. I convert that tag from id to class then every thing works fine. thanks all, That's my bad.
Related
I am trying to create a basic CSS template for a project. It needs to support both a light and dark mode.
In the html, the body tag has data-layout-color attribute. I have some toggles that allow switching between light and dark, and it is updating this attribute. In my CSS sheet, I use the attribute selector for background color, and it works! Now I need to be able to set other elements color based on the light/dark mode, but that's not working as the individual element doesn't have the attribute. I don't want to add data-layout-color to everything, and then have to update it all with my js. Any suggestions?
HTML:
<body ng-controller="myApp" data-layout-color="dark" data-layout="topnav">
<button type="button" class="btn btn-primary">PRESS ME!</button>
</body>
CSS:
body[data-layout-color="dark"]{
background-color: var(--my-body-dark-bg);
}
body[data-layout-color="light"]{
background-color: var(--my-body-light-bg);
}
.btn-primary[data-layout-color="light" {
color: var(--my-white-light);
background-color: var(--my-primary-light);
border-color: var(--my-primary-light);
}
.btn-primary[data-layout-color="dark" {
color: var(--my-white-dark);
background-color: var(--my-primary-dark);
border-color: var(--my-primary-dark);
}
You could write your selectors such that the attribute selector remains on body:
/* primary button under a "light" layout parent */
[data-layout-color="light"] .btn-primary {
color: var(--my-white-light);
background-color: var(--my-primary-light);
border-color: var(--my-primary-light);
}
But I think a better idea would be to change the custom property values so you don't need the theme-specific selectors on child elements in the first place:
[data-layout-color="dark"] {
--button-color-bg: white;
--button-color-fg: black;
}
[data-layout-color="light"] {
--button-color-bg: black;
--button-color-fg: white;
}
.btn-primary {
background-color: var(--button-color-bg);
color: var(--button-color-fg);
display: inline-block;
padding: 0.25em 1em;
border: 1px solid grey;
margin: 0.5em;
}
<div data-layout-color="dark">
<div class="btn-primary">Dark Body</div>
</div>
<div data-layout-color="light">
<div class="btn-primary">Light Body</div>
</div>
With plain css you can write it like this
body[data-layout-color="dark"]{
background-color: var(--my-body-dark-bg);
}
body[data-layout-color="dark"] .btn-primary{
color: var(--my-white-dark);
background-color: var(--my-primary-dark);
border-color: var(--my-primary-dark);
}
body[data-layout-color="dark"] .btn-primary a{
text-decoration: underline overline #FF3028;
}
I suggest you use scss though. It will make your life easier. If you'r using visualstudio code just download Live sass complier and click watch sass in the bottom right corner.
Using scss you would write it like this:
body[data-layout-color="dark"]{
background-color: var(--my-body-dark-bg);
.btn-primary{
color: var(--my-white-dark);
background-color: var(--my-primary-dark);
border-color: var(--my-primary-dark);
a{
text-decoration: underline overline #FF3028;
}
}
.btn-secondary{
color: var(--my-white-dark-secondary);
background-color: var(--my-primary-dark-secondary);
border-color: var(--my-primary-dark-secondary);
}
p{
color: var(--my-white-dark);
}
}
body[data-layout-color="light"]{
background-color: var(--my-body-light-bg);
/*etc etc*/
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Could anyone help me by describing how etc. I do to makes for a function as illustrated.
What I want is that when I mouse over a product box (have not fixed height),
I want to get a box with the buy button, etc. that looks like the picture.
Know that I do not put up the code or, but I do not know where to begin.
So if anyone has any tips or so, I'd be grateful!
Try
button {
display: none;
}
li:hover > button {
display: block;
}
<ul>
<li>Description 1<button>Buy</button></li>
<li>Description 2<button>Buy</button></li>
</ul>
The idea here is to use the > operator to tell CSS to change something in our target. The target being the Buy button inside the li tag.
http://jsfiddle.net/beautifulcoder/kj2XA/
1) First of all: make your items fixed size. This prevents later issues (in layout) and allows you to create effect you described. Like:
HTML (not complete):
<div class="item-wrapper">
<div class="item-content">
<!-- item images etc here -->
</div>
<div class="item-actions">
<button class="buy">Buy</button>
</div>
</div>
CSS:
.item-wrapper {
width: 200px;
overflow: visible;
float: left;
background: #999999;
margin: 5px;
position: relative;
border: 2px solid #fff; /* without this you have unwanted size effects on hover*/
}
.item-content {
width: 200px;
height: 300px;
}
.item-actions {
display: none;
position: absolute;
background: #888;
top:300px;
z-index: 10;
left: 0px;
width: 200px;
height: 100px;
}
2) create javascript with jquery for your items like:
$('.item-wrapper').hover(function () {
// Change css on hover .. this could be done also by changing class
$(this).css({'border':'2px solid #880088'});
$(this).find(".item-actions").slideDown("fast");
}, function(){
$(this).css({'border':'2px solid #fff'});
$(this).find(".item-actions").slideUp("fast");
});
Here is fiddle: http://jsfiddle.net/h23mY/
This is also nice effect: http://jsfiddle.net/ww53e/
lets say the item is enclosed by div tag, now use css hover on
<script>
//on document load item1-buy.hide(); dont forget to use jquery
</script>
<div id="item1">
//item goes here.
<input type="submit" id="item1-buy" value="Buy">
</div>
css:
#item1:hover {
//here you can style how ever you want. Add orange border and so on...
}
now on hover unhide the buy button using jquery #item1-buy.show();
Check the DEMO
I've made a simple markup to show you the idea:
<div class="item">
<img src="http://lorempixel.com/200/200/" alt="" />
<span>15$</span>
<div class="buy">BUY</div>
</div>
And the CSS:
.item {
float: left;
padding: 10px;
border: 1px solid #ccc;
margin: 10px 10px 0 0;
}
span{
display: block;
}
.buy {
padding: 5px;
background: green;
display: none;
}
.item:hover {
border: 1px solid yellow;
}
.item:hover .buy {
display: inline-block;
}
Update: still an issue with the last image in a row, but hope it helps: DEMO 2
<div class="item">
<img src="http://lorempixel.com/200/200/" alt="" />
<span>15$</span>
<div class="buy">
<span class="button">BUY</span>
</div>
</div>
Im using reference from here : http://www.cssnewbie.com/example/showhide-content/ and confused with the javascript
I want if I click see more, the see more wont become invisible, only activate the link
PS: I tried this at jsfiddle but dunno why didnt working, here it is: http://jsfiddle.net/cfp35/
The code:
<a href="#" id="example-show" class="showLink" onclick="showHide('example');return false;">
home
</a>
<div id="example" class="more">
<p>Congratulations! You've found the magic hidden text! Clicking the link below will hide this content again.</p>
<p>Hide this content.</p>
</div>
CSS:
.more {
display: none;
border-top: 1px solid #666;
border-bottom: 1px solid #666;
}
It's simple. If #shID element is not displayed, let it display.
No change in the buttom at all.
function showHide(shID) {
if (document.getElementById(shID)) {
if ((document.getElementById(shID).style.display == 'none')||(document.getElementById(shID).style.display == '')) {
document.getElementById(shID).style.display = 'block';
}
else {
document.getElementById(shID).style.display = 'none';
}
}
}
I'm working on creating tooltips for some content with jQuery and CSS. It works as it should in that the tooltip appears on mouseenter and disappears on mouseleave. My problem lies within my CSS layout. When the tooltip is rendered to the page, it is constricted to the height of its parent:
html:
<div id="allInvTable">
<div class="invItmCont" style="border-bottom:1px solid white;">
<div class="invItmItm">An Item</div>
<div class="invItmStats" style="display:none;">
<div style="clear:both;">
...Some content here...
</div>
<span style="display: none; top: -90px;">
<div style="clear:both;">
...The same content placed here via jquery to display as the tooltip...
</div>
</span>
</div>
</div>
</div>
css:
#allInvTable {
overflow:auto;
}
.invItmCont {
text-decoration:none;
display:block;
float:left;
padding:0 15px;
text-align:center;
position:relative;
clear: both;
}
.invItmCont span {
background-color: #000;
border: 5px solid #826217;
border-radius:15px;
-moz-border-radius:15px;
-o-border-radius:15px;
-webkit-border-radius:15px;
-moz-box-shadow: 2px 2px 2px #000;
-webkit-box-shadow: 2px 2px 2px #000;
box-shadow: 2px 2px 2px #000;
width:200px;
height:auto;
position:absolute;
display:none;
top:-90px;
color:#fff;
left:-37px;
}
Just for reference, the jquery:
<script>
$("#allInvTable div.invItmCont").append("<span></span>");
$("#allInvTable div.invItmCont").hover(function() {
$(this).find("span").animate({opacity:"show", top: "-70"}, "slow");
var itmStat = $(".invItmStats", this).html();
$(this).find("span").html(itmStat);
},
function() {
$(this).find("span").animate({opacity:"hide", top: "-90"}, "fast");
});
</script>
I know that it has to do with the overflow:auto; on #allInvTable because when i remove that attribute, it renders correctly, but the items flow out of their container. How do I fix this?
Um, I know this doesn't answer your question directly, but have you looked at existing tooltip libraries like Twitter's Bootstrap for example: http://twitter.github.com/bootstrap/javascript.html#tooltips
The reason I say this is because, I would rather spend time working on the core of my app rather than try and re-invent the wheel. Unless, you are indeed trying to learn the process of creating the wheel to begin with. Which is also good by the way. You learn a lot that way too.
One of the things you can do is just swap the "tooltip" content into the place you want to display it (that already has the visibility and formatting you want).
This approach treats a display:none element like a content stash.
$("#allInvTable div.invItmCont")
.hover(function() {
var outgoing = $(".invItmItm", this).html();
var incoming = $(".invItmStats", this).html();
$(".invItmItm", this).html(incoming);
$(".invItmStats", this).html(outgoing);
}, function() {
var outgoing = $(".invItmItm", this).html();
var incoming = $(".invItmStats", this).html();
$(".invItmItm", this).html(incoming);
$(".invItmStats", this).html(outgoing);
}
);
See: http://jsfiddle.net/zatz/mgtKD/6/
Alternatively, you can start futzing with z-layers which should be enough of a bad experience that you are ultimately driven to use/adapt one of the existing libraries.
I use anchor as my site navigation.
<div id='nav'>
<a href='#abouts'>
<div class='navitem about'>
about
</div>
</a>
<a href='#workss'>
<div class='navitem works'>
works
</div>
</a>
</div>
The CSS
#nav {
margin-left: 50px;
margin-top: 50px;
text-transform: uppercase;
}
.navitem {
background: #333;
color: white;
width: 230px;
height: 50px;
font-size: 25px;
line-height: 50px;
padding-left: 20px;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
margin-top: 10px;
}
.about:hover {
background: #cc00ff;
}
.about:active {
background: #ff00ff;
color: #000;
width: 250px;
}
.works:hover {
background: #0066FF;
}
.works:active {
background: #0099cc;
color: #000;
width: 250px;
}
I'm wondering how to keep the div element style keep in the :active state once after the click until I hit another nav bar item, so how to do it?
Combine JS & CSS :
button{
/* 1st state */
}
button:hover{
/* hover state */
}
button:active{
/* click state */
}
button.active{
/* after click state */
}
jQuery('button').click(function(){
jQuery(this).toggleClass('active');
});
The :target-pseudo selector is made for these type of situations: http://reference.sitepoint.com/css/pseudoclass-target
It is supported by all modern browsers. To get some IE versions to understand it you can use something like Selectivizr
Here is a tab example with :target-pseudo selector.
I FIGURED IT OUT. SIMPLE, EFFECTIVE NO jQUERY
We're going to to be using a hidden checkbox.
This example includes one "on click - off click 'hover / active' state"
--
To make content itself clickable:
#activate-div{display:none}
.my-div{background-color:#FFF}
#activate-div:checked ~ label
.my-div{background-color:#000}
<input type="checkbox" id="activate-div">
<label for="activate-div">
<div class="my-div">
//MY DIV CONTENT
</div>
</label>
To make button change content:
#activate-div{display:none}
.my-div{background-color:#FFF}
#activate-div:checked +
.my-div{background-color:#000}
<input type="checkbox" id="activate-div">
<div class="my-div">
//MY DIV CONTENT
</div>
<label for="activate-div">
//MY BUTTON STUFF
</label>
Hope it helps!!
You can use a little bit of Javascript to add and remove CSS classes of your navitems. For starters, create a CSS class that you're going to apply to the active element, name it ie: ".activeItem". Then, put a javascript function to each of your navigation buttons' onclick event which is going to add "activeItem" class to the one activated, and remove from the others...
It should look something like this: (untested!)
/*In your stylesheet*/
.activeItem{
background-color:#999; /*make some difference for the active item here */
}
/*In your javascript*/
var prevItem = null;
function activateItem(t){
if(prevItem != null){
prevItem.className = prevItem.className.replace(/{\b}?activeItem/, "");
}
t.className += " activeItem";
prevItem = t;
}
<!-- And then your markup -->
<div id='nav'>
<a href='#abouts' onClick="activateItem(this)">
<div class='navitem about'>
about
</div>
</a>
<a href='#workss' onClick="activateItem(this)">
<div class='navitem works'>
works
</div>
</a>
</div>
If you want to keep your links to look like they are :active class, you should define :visited class same as :active so if you have a links in .example then you do something like this:
a.example:active, a.example:visited {
/* Put your active state style code here */ }
The Link visited Pseudo Class is used to select visited links as says the name.