Google Translate with fixed top navbar - html

I use Twitter Bootsrap's navbar to put a navigation bar on top of my website. (class="navbar navbar-fixed-top")
I also need to use Google Translate widget.
I use tools written here.
But when user selects a language to translate, Google puts a horizontal navbar on top of my page.
That bar masks my own navbar.
I need my navbar appear just below the Google's horizontal bar.
Should I use z-index ? But in that case one of them will mask other navbar?
Is there a better solution? To show one of them below another?
Thank you
edit: when I add following code to the top of my page, Google puts a navbar before my navbar, and everything seems well. But the bad thing is, Google's navbar is visible for every user. I need to show only to the users that doesn't speak my page's language.
<div id="google_translate_element"></div><script>
function googleTranslateElementInit() {
new google.translate.TranslateElement({
pageLanguage: 'fr',
layout: google.translate.TranslateElement.InlineLayout.HORIZONTAL
}, 'google_translate_element');
}
</script><script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
edit: I suppose there is no option like "show google translate if language is different" and "show horizontal bar. If i load horizontal bar without considering the user's language everything is working fine. But the native speakers see the Google Translate bar. Which takes space from my page.

This would be a ugly solution but a quick one.
After clicked the tag will automatically add class="translated-ltr" or "translated-rtl". Use these class to hack your fixed header.
html.translated-ltr .navbar-inner, html.translated-ltr .navbar-inner { padding-top: 39px; }

i use jQuery to check it, im using this code :
setInterval(function(){
if ( $('html').hasClass('translated-ltr')) {
$('.navbar').css('margin-top','30px');
}else{
$('.navbar').css('margin-top','0px');
}
}, 3000);

the easy option would be
<div class="navbar-inner" style="padding-top:39px;">

Just want to share my experience, I have used Arthron's answer and it works.
But have a little bug if click the translate / show the original on the translate bar, the logic return false when the actual is true (translated bar visible). So I add this and perfect :
document.getElementsByClassName("skiptranslate")[1].style.visibility=='visible'
&& document.getElementsByClassName("skiptranslate")[0].style.display!='none'
full code :
setInterval(function(){
if ( $('html').hasClass('translated-ltr') ||
(document.getElementsByClassName("skiptranslate")[1].style.visibility=='visible' &&
document.getElementsByClassName("skiptranslate")[0].style.display!='none')) {
$('.navbar').css('margin-top','30px');
}else{
$('.navbar').css('margin-top','0px');
}
}, 500);

In your css:
body {
padding-top: 60px;
}
.navbar-fixed-top {
position: relative;
top: -60px;
}

Related

NavBar Dropdown injected into SquareSpace Header Disappearing on Hover

I have a webpage with a simple navbar. The actual webpage can be seen here, and a CodePen demo can be seen here. In the CodePen demo, everything works fine. If I hover over a dropdown, the menu appears below. I can then seamlessly move my mouse down over that dropdown menu and select an option. In comparison, on the actual production website, things are not so smooth. The dropdown appears as expected, but as soon as I move my mouse down over the dropdown it disappears - it doesn't seem to register the hover event.
I've tried the following:
Setting z-index to be 1000 or 10000000 in the css for .dropdown
Doing step 1 with the added qualifier of !important;
In Chrome dev tools I tried giving other parts of the webpage lower z-index values, and it changed nothing
Notably, the drop-down is definitely hidden behind stuff. For example if I hover over Alumni, the options in the drop-down are occluded by the label of the website (in white font).
Is there some way other than messing with the z-index with which I can force my dropdown to register the hover event and work as expected? I am comfortable using Javascript, HTML, CSS, and any normal libraries such as Bootstrap or JQuery. Thanks!
EDIT: #lalitbhakuni's answer solved the problem for me. That said, it is possible that people who are dealing with the specifically identical circumstance to my own will run into this and wonder how to implement the CSS solution without access to the CSS for the entire web-page. Here is how I did it, in my banner code injection:
<script>
window.onload = function() {
var header = document.getElementById('header');
header.style.zIndex = 10;
};
</script>
Your header is overlapping your navbar. The y nav dropdown is not working as a result. To fix this, can, you can please define header z_index as follows:
.transparent-header #header {
z-index: 10;
}

open a small screen with text and images in HTML

I am working on a website.
Now what I want is to open a small screen with text and images,which pops up when a link is clicked.
I don't want to open small sized webpage..
What I want is similar to this in chrome.. "chrome://settings/startup"
please if someone can tell me what this feature is called and how it is implemented It will be helpful.
It's called a modal window. Not a real pop up.
Create a div with id
<div id="modal">
// your content with images
</div>
CSS
#modal {
position: absolute;
z-index: 99;
top: 25%;
width: 400px;
height: 300px;
margin: auto;
display: none;
}
Now in javascript:
On click of the link, show the modal window
$("#buttonId").click(function() {
$("#modal").show();
})
There already many plugins which does this:
Jquery UI
Bootstrap
But, if you have Chrome or a modern browser, use the <dialog open> tag (like a div) and use id's to edit the dialog via JS, such as:
window.<id>.close(); // closes dialog/hides it
window.<id>.show();
window.<id>.showModal(); // instead of showing it regularly, it puts it to the middle of the screen and greys the background like an alert. (you can edit the background effect with CSS)
If you want to use pure html, probably you can use window object. It has several types of popup window method, like window.alert(), window.comfirm(), etc.
If you want to use with javascript and css, then there are many ways to implement it. Here is a simple example I found:
[1]http://www.webdesignerdepot.com/2012/10/creating-a-modal-window-with-html5-and-css3/

Trying to hide an object / create a fold effect

I'm trying to create a rather unique effect. It's actually not that complicated, what I'm trying to do is build an experimental site, which I have already done. I just can't seem to figure out how to go about doing the final step.
So this is my site I'm tinkering with http://www.dig.ital.me/sandbox/about-me/
And what I'm trying to do is collapse the left-side bar that has the text in it : "Made in blah blah blah, etc." By clicking on the : " Click this to hide this " .
And I've tried going about doing an anchor link associated with a name link and calling the display:none when that link is clicked. However, it isn't working. So I thought I would try stackoverflow, on how I could about achieving this kind of effect where it collapses, and re-opens again.
#hide-option { color:#FFF; width:500px; height:500px; padding-left:170px;}
#hide-option:hover .fixedfooter {
display:none;
cursor:pointer; }
Here's a snippet of the hide-option div id. I've exhausted a lot of routes to try and achieve this effect but I cannot seem how to figure it out. I've tried the :onClick class, and nth-child classes, but nothing seems to work.
// Store the footer as a variable, so we don't have to keep calling jQuery's selector engine
// It's slower than a tortoise stuck in a traffic jam.
var target = $('.fixedfooter');
// Every time the hide-option link is clicked
$('#hide-option a').click(function() {
// If the left position of the target is 0
if(parseInt(target.css('left')) == 0) {
// Check the target is not animated and, if it is, animate off screen
!target.is(':animated') && target.animate({left: -751}, 250);
} else {
// Assume it's hidden, and put it back to the start
!target.is(':animated') && target.animate({left: 0}, 250);
}
// Stop the link being followed
return false;
});
JQuery, the JavaScript library, will solve it all for you.
$("el").bind("onclick",function(){$("el").toggle('slow');});
If you only want CSS3 (if you don't care about IE6-8), here's something you could try: http://jsbin.com/isunoz/6/edit
I've commented it as much as possible, I hope it helps :)
What I've done is to use a checkbox input to decide if the sidebar should be shown or not.
By putting the checkbox input element right before the sidebar element (div.fixedfooter) and changing your anchor (the arrow) into a label for that checkbox, I'm able to use the :checked pseudo class and the + selector to target the sibling element (in this case, the sidebar div.fixedfooter). If the checkbox is checked, the sidebar is moved out of the screen and if it's not checked, the sidebar is shown (left: 0).
For the animation I've used some css3 transition (transition: left .4s ease) :)

Always visible div while scrolling

On my aspx page, I have two left and right portions. I want to show always left side (which is actually a 'div' containig treeview) while scrolling the right side (which are actual contents of page). Thanks
You need to put position: fixed; on the div element. That will anchor it to the viewport.
Hi I found the best solution! As always JQUERY saving my life !!
Just put a Div called as you wan, I've chosen the same in the example below: #scrollingDiv.
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script>
$().ready(function() {
var $scrollingDiv = $("#scrollingDiv");
$(window).scroll(function(){
$scrollingDiv
.stop()
.animate({"marginTop": ($(window).scrollTop() )}, "slow" );
});
});
</script>
I took that code from a website, it works and it's pretty easy to understand.
Fast forward to 2020, and it is now possible to do this with CSS.
<div style="position: sticky; top: 0;"> Tree view </div>
The user npas explains this quite nicely:
top is the distance to the viewport top the div should stay at when you scroll. Specifying top is mandatory. (…)
The sticky div will act like a normal div in all ways except when you scroll past it, then it will stick to the top of the browser.
Here's a jsfiddle to give you an idea.
MDN documentation
Supported by all modern browsers
You need to set the position of the div to Fixed in CSS. See this link for more information. You will need to set position using the top and left in css as well so it knows where to fix it!
The problem is that when the block moves, it gets attention and ability to concentrate on reading.
To remedy this using this function.
This code is perfect :
(change "220" and "46px" if necessary)
var $scrollingDiv = $("#scrollingDiv");
$(window).scroll(function(){
if ($(window).scrollTop()>220) {
$scrollingDiv
.css("position",'fixed' )
.css("top",'46px' )
} else {
$scrollingDiv
.css("position",'' )
.css("top",'' )
}
});

link to anchor near bottom of page

I'm doing some documentation where I make heavy use of anchors for linking between pages on a wiki.
see here:
http://code.google.com/p/xcmetadataservicestoolkit/wiki/ServicesExplained#Platform_Data_Structures
The feature that really makes this work well is when the browser shows the anchor at the absolute top of the pane. When it gets confusing is when linking to an anchor shows the anchor half-way down the page since the page is scrolled down all the way
see here:
http://code.google.com/p/xcmetadataservicestoolkit/source/browse/trunk/mst-common/src/java/xc/mst/utils/Util.java#227
My solution in the wiki (first link) was to put a blank image at the bottom of the page simply to make the browser show the anchor right at the top. Is there a better way to do this? Is there a way to do it in the second link (in which I can't add a blank image)?
Putting a blank image at the bottom of your page is a bad idea, since it will expand your document to a unnecessary height.
You could throw in some javascript to apply an effect to the anchor you just travelled to, to highlight it wherever it is.
Without altering the height of your document (i.e. adding extra padding at bottom), you'll always have this issue.
However, using bit of JS/jQuery, the user experience can be improved considerably:
On clicking a named anchor:
Instead of jumping in a flash (broswer's default behavior), add a smooth scroll
add an highlight to indicate current selection (this helps tremendously in 2nd case as the user can clearly see what is current)
Created a demo to illustrate the concepts: http://jsfiddle.net/mrchief/PYsyN/9/
CSS
<style>
.current { font-weight: bold; }
</style>
JS
function smoothScroll(elemId) {
// remove existing highlights
$('.current').css({backgroundColor: "transparent"}).removeClass('current');
var top = $(elemId).offset().top;
// do a smooth scroll
$('html, body').animate({scrollTop:top}, 500, function(){
// add an highlight
$(elemId).animate({backgroundColor: "#68BFEF" }, 500, function () {
// keep tab of current so that style can be reset later
$(elemId).addClass('current');
});
});
}
// when landing directly
if (document.location.hash) {
smoothScroll(document.location.hash);
}
$('a[href*="#"]').click(function() {
// utilizing the fact that named anchor has a corresponding id element
var elemId = $(this).attr('href');
smoothScroll(elemId);
});
You can create a absolutre positioned pseudo-element with a great height to targeted block using just the following CSS (for the second link in your post:
#nums td:target a::before {
content: '';
position: absolute;
height: 700px;
}
The height must be around the height of the viewport, so the best solution is to create these styles on the fly using js. But if you don't wan't to use js, just use height: 1000px or more — if you don't mind a gap at the bottom of course.
The best part: it's only CSS and there would be no gap when no anchors are targeted.
Edit: just a sneak peek into the future: if the vw/vh units would come to other browsers (now it's only in IE9), this could be awesomely done with just CSS using height: 100vh :)
You could use Javascript / jQuery to create a white div that has the necessary height needed to put your element at the top of the browser window, and you could even remove this upon scrolling away.
However I would highly recommend against doing so as this will expand your page where it isn't needed. It's a lot smarter to simply style the tag upon going there (through Javascript / jQuery) so it pops out to the viewer, for instance by setting the font-weight to bold or changing the background-color.
I would probably use a combination of jQuery and PHP for this:
PHP(somewhere right after your <body> element):
<?php
$anchor = explode('#', $_SERVER['REQUEST_URI']);
$anchor = $anchor[1];
echo '<div id="selected-anchor" anchor="'.$anchor.'"></div>';
?>
And then the jQuery:
<script type="text/javascript">
$(function(){
$('#selected-anchor').css('background-color', '[Whatever highlight color you want]');
});
</script>
Hope this helps.