make disappear bottom line in tabs html jquery css - border

i am making a web application and trying to make some nice tabs. The thing is i can't make the tabs show its content when they are active (if tab1 show content1) but without the bottom-border of the tab, classic tabs. With this i mean by switching to tab2, to make the bottom border of tab1 to appear and make disappear the bottom border of the tab2 and so on. I dont know if its clear enough its harder to explain than the thing i want to do itself. Here is my code where im having trouble with it...
HTML
<div id="principal" class="wrapper">
<h2 class="subtitulo">Mis videos!</h2>
<ul id="pestanas">
<li class="active"><a href="#" onclick="mostrarInicio()">Inicio</li>
<li><a href="#" onclick="mostrarVideos()">Todos los videos</li>
</ul>
<div id="videoDestacado" class="active">
<iframe width="420" height="345"
src="http://www.youtube.com/embed/h6k5qbt72Os">
</iframe>
</div>
<div id="todosVideos">
Aca hay un contenido
</div></div>
CSS
#principal ul {
list-style: none;
padding:0;
margin:0;
}
#principal li {
float: left;
border: 1px solid;
border-bottom: none;
/*border-bottom-width: 0;*/
margin: 0 0.5em 0 0;
}
#principal li a {
padding: 0 1em;
}
#active {
position: relative;
top: 1px;
background: black;
padding-bottom: 0px;
border-bottom: none;
}
JS/JQuery
function mostrarVideos(){
$("#todosVideos").show();
$("#videoDestacado").hide();
$("ul#pestanas li a").removeClass("active"); // desactivamos todas las pestañas
$(this).addClass("active");
}
function mostrarInicio(){
$("#todosVideos").hide();
$("#videoDestacado").show();
$("#pestanasPG li a").removeClass("active"); // desactivamos todas las pestañas
$(this).addClass("active");
}

If I'm understanding your situation correctly, the actual problem is how to add a border to previously opened tabs and removing the border on the "active" tab when you change tabs?
In that case, I would assign an unifying class without any rules on it such as "videoTabs" then use jquery on that class to deactivate all tabs then activate the tab you're on using that tab's ID.
For simplicity, let's say the tabs you are not currently using have the class "videoTabs". The tab you are currently using has the class "active" and "videoTabs". The videoTabs has a border set on it. The active class has a border-bottom override "border-bottom: 0px !important".
What you would do then is call a function whenever you switch tabs that'll take care of this process.
function switchTabs(requestedTabID){
$(".videoTabs").removeClass("active");
$("#"+requestedTabID).addClass("active");
}
This will bring all of the tabs back to a single state then you change the specific tab's CSS to reflect how you want it to look.
This may not be the most elegant solution but it's simple to implement.

Related

Darken the background on a hover

again for my website, I want to make a hover on an div class, when you put your cursor on it, his scale gets bigger, I archieved this, now I want it to add like an '!important' cause as you can try here : http://stefanspeter.fr/about-test.html , the middle div for example get his text cuts on the side. I want to fix this problem first, then I would like to darken everything around this window, and to be fair I don't have a clue about how to make that happens.
I tried to add an !important tag, not knowing if it would work, and the way I did wasn't working actually.
Here is the code I'm using now :
.job {
background: #515151;
padding: 0.5rem;
border-bottom: #eece1a 5px solid;
}
.jobzoom:hover {
transform: scale(1.2);
font-size: 22px;
}
<div class="job jobzoom col-sm">
<h3>Alternance chez <a class="link-2 about-link" href="www.hb-digit.com" target="_blank">HB-Digit</a> et <a class="link-2 about-link" href="https://www.efficom-lille.fr/" target="_blank">Efficom</a></h3>
<hr class="about-hr" />
<h4 class="text-secondary">Août 2019 - Août 2020</h4>
<hr class="about-hr" />
<p>
Je suis actuellement en alternance chez HB-Digit sous l'école supérieur Efficom.<br /> Mes principales missions :
<ul>
<li>Développement de services web (Drupal8, php, bootstrap, twig, JS, jQuery...)</li>
<li>Gestion relation client via méthode Agile (Jira)</li>
<li>Etablissement et respect des cahiers des charges</li>
</ul>
</p>
Actual output : hover get the scale correctly
Expected : darken the background while it's hovering, stopping the cut by the others div surrounding it.
Thank you
I see the text being cutted on the side you already solved.
So, here is the solution for the dark background.
First, add a div inside .about-info element as the last one. Use .dark-element class to it:
<div class="about-info">
<!-- ... -->
<div class="dark-screen"></div>
</div>
Then, let's add CSS in order to create the effect.
You are going to make it fixed, fill the whole screen, invisible if no .job element is being hovering, but will appear when any element is hovered.
So we can use some properties like transition, visibility, point-events and opacity. Also, the selector ~ to select siblings (that are after the element, that's why we put it at the end) will be very useful:
.dark-screen {
height: 100%;
width: 100%;
position: fixed;
top: 0;
left: 0;
visibility: hidden;
background: black;
pointer-events: none;
transition: 0.76s;
opacity: 0;
}
.job:hover ~ .dark-screen {
visibility: visible;
opacity: 0.6;
}

Reset CSS hover dropdown with JQLite

I'm currently in a project developing an Angular SPA that has dropdown menus in its main navbar. To get this effect, we are using CSS: hover selectors. The issue is that when an action is performed within this dropdowns we would like to close them without hindering the ability to open them again. For example, if a user opens a link within one of this dropdowns (internal link with ui-sref) he is then taken to this particular state, but the dropdown would still be visible until he moves the mouse outside it (and partially obscuring the new content shown). We would like the dropdown to be closed when an action within is performed and if the user would like to open it again, he would be able to hover the mouse again over the trigger.
We tried removing and re-adding classes (even after a timeout) but the dropdown reappears again.
Link to a Plunker with a setup similar to what we are trying to accomplish: https://plnkr.co/edit/qzQk4r2WQFhwsgUWug39?p=preview
And the relevant portions (Angular controller omitted as it has no content):
HTML:
<div class="hoverable has-dropdown">
<button class="dropdown-trigger">Hover me!</button>
<div class="dropdown">
Dropdown content
<button ng-click="buttonAction()">Action</button>
</div>
</div>
CSS:
.dropdown {
display: none;
position: absolute;
top: 20px;
width: 100px;
height: 100px;
background: lightgrey;
padding: 1em;
}
.has-dropdown {
position: relative;
height: 20px;
}
.has-dropdown .dropdown-trigger:hover + .dropdown,
.has-dropdown .dropdown-trigger + .dropdown:hover {
display: block;
}
Thanks!
Finally solved it by using ng-mousenter and ng-mouseleave and dropping CSS :hover rules. As everything is based on JS I can just trigger mouseleave when I want to close them.

How do you make a Div do the same thing as a a button?

I am trying to make a navigation bar for a project and I need a button to call the function for a dropdown menu. If I have a button, I can't format it the same as a div, and it stands out from the other options. Is there a way to make a div be a button? I have tried putting the onclick attribute on it, but then the drop-down menu doesn't appear in the same spot. Thanks in advance.
(I am very new to coding, so try to explain things in simple terms)
I decided to do a hover drop-down menu which makes things a lot easier, but thank you for your answers!
There are different ways to do this. One is to use jQuery (a Javascript extension), like Branden Keck showed it to you. Another way is to use only html and Javascript: There is a html attribute which creates an Javascript event:
<div id="myDiv" onclick="clickEvent()">Some text</div>
clickEvent has to have brackets in it because it's a Javascript Function. Your Javascript could look like something like this then:
function clickEvent() {
document.getElementById("myDiv").innerHTML = "Hello World";
}
Here a snippet for that:
function myFunction() {
document.getElementById("myDiv").innerHTML = "Hello World without jQuery!";
}
$("#myDiv2").click(function() {
$("#myDiv2").html("Hello World with jQuery!");
});
$("#myDiv3").click(function() {
$("#hiddenDiv").slideToggle(750); // 750 is the sliding time in ms
});
#myDiv,
#myDiv2, #myDiv3, #hiddenDiv {
background: #0000ff;
color: #ffffff;
transition: 0.5s all;
-webkit-transition: 0.5 all;
font-family: "Arial";
width: auto;
height: auto;
font-size: 1.3em;
margin: 0.4em;
padding: 0.2em;
border-left: 1px groove #f0f0f0;
border-top: 1px groove #f0f0f0;
}
#myDiv:hover,
#myDiv2:hover, #myDiv3:hover {
background: #ffffff;
color: #000000;
padding: 0.22em;
box-shadow: 0.22em 0.22em 0.44em #000000;
}
#myDiv2, #myDiv3 {
background: #ff0000;
}
#hiddenDiv {
background: #00aa00;
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<div id="myDiv" onclick="myFunction()">Click this div! Without jQuery</div>
<div id="myDiv2">Click this div! With jQuery</div>
<div id="myDiv3">Toggle hidden Text With jQuery<span style="font-size: 0.7em;font-family:Arial;font-style:italic;"> May lag because of snippet.</span></div>
<div id="hiddenDiv">You found me!</div>
You say you are very new to coding. Have you read about jquery at all? I would definitely suggest it. It is very possible to make things happen when a <div> tag is clicked with jquery functions. Here is an example:
$("#IdOfDivTag").click(function(){
alert("The paragraph was clicked.");
});
You will have to add an id or class attribute to the div tag you want an action to happen with (unless you want the same action for all <div>, in which case you can use "div" in the jquery statement).
To implement jquery you need at add a jquery library to your code... You can start here: http://www.w3schools.com/jquery/jquery_get_started.asp

Hover effects on class and id tied to each other?

I'm working on a custom navbar on a site I'm making but I've run into an issue. I've searched around and have found some similar threads, but nothing that has worked for me. I have a navbar with an image and some text underneath. What I'm trying to accomplish is while hovering over either the text or image, the hover effect for both occurs. The issue is that for the image, the hover effect is done thru an ID and the text hover effect is done thru a class. Here is my markup for one of the sets.
<div class="col-md-2 col-sm-1">
<a href="#Url.Action("Index","Home")" title="HOME" style="margin-left:10px;">
<div id="homenav"></div>
<div class="navtext">HOME</div>
</a>
</div>
And here is the CSS for the image:
#homenav {
margin: 0 auto;
display: block;
width: 47px;
height: 50px;
background: url('../Images/NAV_ICONS/NAV_HOME.png') no-repeat 0 0;
}
#homenav:hover {
background: url('../Images/NAV_ICONS/NAV_HOME_RED.png') no-repeat 0 0;
}
And the CSS for the text:
.navtext{
font-family: RobotoCondensed-Bold, 'Arial Narrow', Arial, sans-serif;
color: #00457c;
overflow: hidden;
white-space: nowrap;
}
.navtext:hover{
color: #ee2e24;
}
And just for clarity, I'm simply trying to make both turn the same color red. Any advice will be greatly appreciated.
Could this fit your needs ?
Put both div (#navbar and .navtext) inside a wrapper div, then put your hover styles in those selectors:
#wrapper:hover #homenav
and
#wrapper:hover .navtex
See fiddle here.
But the hover styles come for a hover over the whole wrapper div.
When using css :hover, the property changes will only affect the element being hovered. You would have to use Javascript/JQuery to do this, but it's pretty straightforward.
First, we need to change the :hover css elements into classes like so
.navtextHover{
color: #ee2e24 !important;
}
.homeNavHover {
background: url('http://lorempixel.com/g/400/200/') no-repeat 0 0 !important;
}
We also need to add a new class. This class will essentially mean that they are all tied together when hovered - ie, when one is hovered, all will be treated as hovered. So add that to the HTML (I called it syncedHover)
<div class="col-md-2 col-sm-1">
<a href="#" title="HOME" style="margin-left:10px;">
<div id="homenav" class="syncedHover"></div>
<div class="navtext syncedHover">HOME</div>
</a>
</div>
Then the javascript merely adds the classes on hover and removes them on exit
$(".syncedHover").hover(
function () {
$("#homenav").addClass("homeNavHover");
$(".navtext").addClass("navtextHover");
},
function () {
$("#homenav").removeClass("homeNavHover");
$(".navtext").removeClass("navtextHover");
}
);
This could be written better by passing data to the JQuery method on hover so you don't have a list of addClass methods, but this isn't too cumbersome for only two elements.
This JSFiddle shows a working example with how it can be done https://jsfiddle.net/bou7mqk3/1/
You just need to put a class on the link instead. As in, the parent a tag that the two elements are nested inside.
In this HTML the only change is the additional class on the link - 'your-class', and I removed the unnecessary syncedHover classes:
<div class="col-md-2 col-sm-1">
<a href="#" title="HOME" style="margin-left:10px;" class="your-class">
<div id="homenav"></div>
<div class="navtext">HOME</div>
</a>
</div>
And then update your CSS to this:
.your-class:hover #homenav{
background: url('../Images/NAV_ICONS/NAV_HOME_RED.png') no-repeat 0 0;
}
.your-class:hover .navtext{
color: #ee2e24;
}
No JavaScript needed at all!

Dynamic Div or assigning multiple functions to a Div in CSS/HTML

I'm relatively new to Web dev. The question is generic, but I'll pose specific user-cases.
Use-case 1:
I have a div element on a web page. When the page loads the first time, this div runs a small 5 sec animation. What I wish to do is, when this animation ends, I want the same div to contain some other element - it could be an image, a link, another animation etc.
That is, one container - the div - hosting multiple elements on a time-scale. First 5 secs animation , followed by an image or a link.
What Javascript methods will allow me to do so?
Use-case 2:
Again, I have a div element in a page. Now this div element is like a tabbed browser - you click on a different tab to view a different web page. Similarly, I wish to make this a "tabbed" div. As in, when the user hovers the mouse on tab 1, the div would show a video, when hovered over tab 2, it would show another video in the same div - that is, replacing the old video. The tabs can be considered as a fancy looking link.
Or, in the first place, is there an alternative to 'div' to do the things mentioned above?
Thanks,
SMK.
Solution for use case 2 -
This is a slightly lengthy solution but its extremely flexible and can be scaled up to any number of tabs very easily
We will divide the solution into 3 parts - The CSS, HTML and JQuery.
Lets take a look at the CSS part first
<style>
#tab_holder {
width: 350px; !important
}
#tab_holder .tabs {
float: left;
height: 20px;
padding: 5px;
border: 1px solid #eee;
border-bottom: none;
width: 50px;
cursor: pointer;
border-radius: 5px 5px 0 0;
}
#tab_holder .tabs:hover {
background-color: #eee;
}
#tab_holder #content_holder {
width: 400px; !important
margin: 0 0 0 0;
border: 1px solid #000;
padding: 10px;
float: left;
border-radius: 0 5px 5px 5px;
}
.content {
visibility: hidden;
}
</style>
Let us now take a look at the HTML part of this solution
<div id="tab_holder">
<div id="tab1" class="tabs">Video1</div>
<div id="tab2" class="tabs">Video2</div>
<div id="tab3" class="tabs">Video3</div>
<div id="content_holder">
<div id="main_content">Select a tab to see the video..</div>
</div>
</div>
<!-- These are divs in which you put your actual content.
They are always hidden -->
<div id="content1" class="content">
<iframe width="200" height="200" src="http://www.youtube.com/embed/4Z6YUGGlwtA?rel=0" frameborder="0" allowfullscreen></iframe>
< /div>
<div id="content2" class="content">
<iframe width="200" height="200" src="http://www.youtube.com/embed/s13dLaTIHSg?rel=0" frameborder="0" allowfullscreen></iframe>
</div>
<div id="content3" class="content">
<iframe width="200" height="200" src="http://www.youtube.com/embed/I1qHVVbYG8Y?rel=0" frameborder="0" allowfullscreen></iframe>
</div>
You can see that each tab is represented by a div which is using the "tabs" class from the CSS section. If you need to add a new tab, all you have to do is add a new div and give is a new id. For example to add a forth tab, you can say -
<div id="tab4" class="tabs">Video4</div>
It is as simple as that.
Now the thing I like about this approach is that you can place the content to be displayed also in div's, rather that nesting it under jquery. In this case we use the div's with the id content1 content2 content3
This gives you the flexibility to expand as you enter content into the div and use normal markup without getting confused and at ease.
These div's are not visible as we have set their visibility to hidden is CSS.
If you add a new tab div you must also add a new content div.
Now we move onto the JQuery part -
$(document).ready(function (){
/* Add the listeners. */
$("#tab1").mouseover(function (){
switch_content('content1')
});
$("#tab2").mouseover(function (){
switch_content('content2')
});
$("#tab3").mouseover(function (){
switch_content('content3')
});
});
function switch_content(name){
$("#main_content").fadeOut('fast',function (){
$("#main_content").html($("#"+name).html());
$("#main_content").fadeIn('fast');
});
}
The above JQuery function is extremely straight forward. Each tab is attached a action listener which is fired by a mousover event. So if you add another tab with the id=tab4 and its respective content div with the id=content4 then all you have to add in the jQuery is:
$("#tab4").mouseover(function (){
switch_content('content4')
});
So it becomes very easy to expand the code.
You can find a working demo of this on my website demo section
Tips -
Avoid using hover because it creates an annoying user experience due to accidental hovers and it is hard for mobile platforms to emulate this event. Most of them fall back to click. So I suggest use the click event instead.
If you must use, make use of the HTML video tag and pause the video using JS if the user hovers on another tab. This will render a better user experience.
Here is an example for use-case 1.
In your html you need to include the 5 second animation, i persume this is a gif? Although it can be any content. For the sake of this example i will show it as a div.
The html i have used:
<div id="example">
<div id="somecontent"> </div>
<div id="morecontent"> </div>
</div>
The CSS:
#example
{
width:500px;
height:500px;
background-color:#f00;
padding:10px;
}
#somecontent
{
width:200px;
height:200px;
background-color:#fff;
}
#morecontent
{
width:200px;
display:none;
height:200px;
background-color:#000;
}
and the javascript(using jQuery):
setTimeout(function() {
$("#somecontent").fadeOut("slow", function() {
$("#morecontent").fadeIn("slow");
});
}, 5000);​
Have a look at this jsfiddle for it in action - http://jsfiddle.net/fntWZ/
For use case 2 it will be more complicated. Try having a look for some different plugins that could help with this
answer for use-case:1
css :
<style>
#myDiv {
height:0;
width:0;
position:absolute;
border:1px solid red;
}
</style>
script :
$(document).ready(function(){
$("#myDiv").animate({width:"100px", height:"100px"},5000, function(){
var image = new Image();
image.src = "dropdownContainerBottomMiddle.png"; //your image src goes here
$("#myDiv").append(image);
//you can append more content by using setTimeout function
setTimeout(function(){
var anc = "stackoverflow";
$("#myDiv").append(anc);
}, 1000);
});
});
html:
<div id="myDiv"></div>