I have the following code:
<div style="" class="skiptranslate">
<iframe frameborder="0" style="visibility:visible"
src="javascript:''"
class="goog-te-banner-frame skiptranslate"
id=":2.container"></iframe>
</div>
I need to hide it but if I only hide the goog-te-banner-frame using:
.goog-te-banner-frame {
display:none !important
}
It still throws my header down. If I use this:
.skiptranslate {
display:none !important
}
It also hides the language selection dropdown because it shares the same class.
I'd like to hide the skiptranslate div that CONTAINS the goog-te-banner-frame.
How do I do that?
Edit:
This is actual code to "create" the translate div above:
<div id="google_translate_element"></div>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'en',
layout: google.translate.TranslateElement.InlineLayout.SIMPLE,
autoDisplay: false,
includedLanguages: ''}, 'google_translate_element');}
</script>
<script type="text/javascript" src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
Ok, this works for some reason:
.goog-te-banner-frame.skiptranslate {
display: none !important;
}
body {
top: 0px !important;
}
The selected answer is wrong!
I know this is an old question, but for anyone coming across this problem in the future, the easiest way:
body > .skiptranslate {
display: none;
}
Since the iframes are dynamically added directly to the body, you can simply select only direct descendants and nothing deeper.
This works for me:
.goog-te-banner-frame.skiptranslate {
display: none !important;
}
body {
top: 0px !important;
}
Why don't you just add an id to the skiptranslate div that holds the goog-te-banner-frame? <div id="something" class="skiptranslate" style=""> will then allow you to style div#something { display: none !important; }
Try to add another class, say .myClass {display: none;}, append to skiptranslate, like class="skiptranslate myClass"
EDIT:
Another solution:
You can also wrap the google translate code with another div, say <div id="google-wrapper">... google translate code...</div> and then style the wrapper with display: none;
OR
See this fiddle: http://jsfiddle.net/SryPD/
I found this to work the best for me. I send the Google Translate "origninal text" tooltip to z-index: -1000. So it is still in the page, but out of sight.
// Force hiding of "original text" popup for menus, etc. (very annoying)
jQuery(selector).bind(
"mouseenter mouseleave",
function (event) {
if (event.type === 'mouseenter') { google_trans_tt.css('z-index', -1000); }
else { google_trans_tt.css('z-index', 1000); }
}
);
October 2022: None of the above answers worked in my case.
I made it work by simply changing the z-index: of my website's menus, after I found the z-index: of the google translate's iframe (using of course the Developers Tools).
It works for me.
.goog-te-gadget img{
display:none !important;
}
body > .skiptranslate {
display: none;
}
body {
top: 0px !important;
}
Related
So I am a bit stumped on this ... I'm using a WebView in a portion of our app, the reason for the WebView is because we are pulling from an API endpoint that returns to us an HTML string. The font size and other things in this HTML string aren't styled for the purpose of using in a mobile app so we are trying to add some stylistic changes to it for better viewability. I've seen people add Style Tags at the top of the html file to add specific html styles to the element, and everything is generally working except the font size in the HTML of WebView renders differently every time I click into the screen that has the WebView contained in it.
Here is the current code (style + html + script):
let rawHTML = htmlStyle + this.props.itemDetails.body_html.replace("\n", "").replace(/("\/\/[c])\w/g, "\"https://cd").replace(/(width: 10.094%;)/g, "").replace(/(width: 84.906%;)/g, "") + heightScript
I have also console logged this string out in the debugger to make sure it's stitched well, and have even created and index.html and pasted in there the exact string, to make sure it's just showing up properly there.
Here is the style string:
let htmlStyle = `<style>
#height-calculator {
margin: 0;
padding: 0;
}
#height-calculator {
position: absolute;
top: 0;
left: 0;
right: 0;
margin: 0;
padding: 0;
}
body {
width:100%;
}
h2 {
font-size: 48px;
}
p {
font-size: 18px;
}
h3 {
font-size: 32px
}
img {
width:98%;
}
td {
display: block !important;
width: 95% !important;
}
img {
width:98%;
}
hr {
width: 98%;
}
ol li ol li ol li {
position: relative; right: 85px;
}
ul {
width: 98%,
margin-left: -25px;
}
li {
width: 98%;
}
.tabs {
display: none;
}
.tabs > li {
display: none;
}
.tabs-content {
padding: 0;
list-style-type: none;
}
tr {
display: flex;
flex-direction: column;
}
</style>`
And finally here is the WebView:
<WebView
javaScriptEnabled={true}
onNavigationStateChange={this.onNavigationStateChange.bind(this)}
scrollEnabled={false}
source={{html: rawHTML}}
style={{height: Number(this.state.height)}}
domStorageEnabled={true}
scalesPageToFit={true}
decelerationRate="normal"
javaScriptEnabledAndroid={true} />
Also, as I mentioned all the other styles applied are working, it's mainly just the font size that is super unpredictable.
Here is the view when I click it one time:
And then I don't change or exit the app, I just go back, and then click the same button to enter that same display and I get this sometimes (it sometimes takes multiple clicks ... it's very unpredictable):
I have a video of this as well, if you feel that would help this explanation. I'm trying to retell it the best I can haha.
Edit:
I think this might be a simulator only related issue? If anyone could speak some wisdom into that, that would be awesome still. I can't seem to reproduce this error on production build.
I recently experienced the same issue. It was only occurring for me on iOS, not Android.
The weirdest part is the inconsistency in replication. I couldn't find any pattern to when the WebView content would be sized differently. Identical HTML would result in font size that was sometimes normal, but other times very tiny.
My solution came from a (RN 0.47) WebView prop:
scalesPageToFit?: bool
Boolean that controls whether the web content is scaled to fit the view and enables the user to change the scale. The default value is true.
I tried setting scalesPageToFit to false, and voilĂ , the page stopped scaling down:
<WebView
source={{ html: myHtml }}
scalesPageToFit={false}
/>
The only problem is that this caused my content to be scaled larger than the WebView's container on Android. To fix this, I simply set the scalesPageToFit prop conditionally, based on platform:
<WebView
source={{ html: myHtml }}
scalesPageToFit={(Platform.OS === 'ios') ? false : true}
/>
Worked like a charm for me!
I used react-native-render-html. The reason I choose this solution over the accepted answer is because I can style html tags using react native styles instead of injecting style declaration string before the actual content.
const htmlStyles = { p: {fontFamily: 'Lato'} }
const htmlContent = <H1>My Html</H1>;
<HTML containerStyle={ {margin: 16} }
html={ htmlContent }
tagsStyles={ htmlStyles } />
I've been trying to hide everything apart from the main content on the following Facebook post
I've been injecting the following css without luck - can someone please help?
html body * {
display:none;
}
#contentArea {
display:block;
}
Below is a screenshot of what I'm after.
With body * you are hiding every child.
With #contentArea you are showing this block, but still - body * persist for child elements AND parent elements.
You have to specify much more rules to hide everything else.
As mentioned before, you cannot display an element which has a parent that was hidden. Anyway, Facebook's layout is simpler than I thought, all you have to do is hide two elements: the header and sidebar. This of course assumes that a user is not logged in.
Inject this CSS
#pagelet_bluebar, #rightCol {
visibility: hidden;
}
Result:
Result (user logged in):
To hide the chat sidebar, you can add #pagelet_sidebar to the CSS.
#pagelet_bluebar, #rightCol, #pagelet_sidebar {
visibility: hidden;
}
To conclude: Hide the main parts instead of everything, or use jQuery to target all except your element as suggested by #MaVRoSCy.
Thanks everyone - the following seems to be the combination of everyone's answers:
#leftCol, #pagelet_bluebar, #rightCol, #pagelet_bluebar {
visibility: hidden !important;
display: none !important;
}
html ._5vb_.hasLeftCol #contentCol {
border-left: initial !important;
margin-left: initial !important;
padding-left: initial !important;
padding-top: initial !important;
}
._5vb_, ._5vb_ #contentCol {
background: none !important;
}
Seems to be CSS related because initializing the map in a simple HTML page works just fine. I have added suggested CSS to fix known issues (below), but can't seem to get rid of this.
#map {
*, *:before, *:after {
-moz-box-sizing: content-box!important;
-webkit-box-sizing: content-box!important;
box-sizing: content-box!important;
}
img {
max-width: none;
height: auto;
}
label {
width: auto;
display: inline;
}
}
For anyone else looking for a temp solution for this bug:
CSS
.map *, .map *:before, .map *:after {
-webkit-transform: none !important;
}
SASS
.map {
*, *:before, *:after {
-webkit-transform: none!important;
}
}
It seems to be a rendering bug with Chrome (I can replicate it in v 34.0.1847.131), rather than with your CSS. It's been fixed in Canary (v 36.0.1973.2 canary).
According to this bug thread on gmaps-api-issues:
The fix is in Chrome 35, which is currently scheduled for release in mid-May (you can switch to the beta channel to get the fix now or verify it in a Canary build - http://www.chromium.org/getting-involved/dev-channel).
Until then, like #user699242 suggested, removing any heading tags (h1, h2, etc.) in your page seems to fix it. Of course, that's semantically unappealing though, might be better just to wait.
.gm-style div div *{
-webkit-transform: none !important;
}
Note: Does the same as Nathans solutions, but also guarantees that the maps is still dragable. However it's just a temporary solution.
Seems like it has something to do with the following which is added inline to images by Google:
-webkit-transform: translateZ(0px)
Finally narrowed it down to h tags. If I removed all the h tags (h1, h2, etc.), the gray line disappears. So, seems like a Chrome bug (v 34.0.1847.116).
It is happening for me on my site http://www.shortwave.am/ as well, but only in the newest version of Chrome (I had Version 33.x before which was for some reason not updating and the problem was not there, but since I changed to the newest I have the issue).
It is fine on Firefox though.
Can you post a link to your site as an example please?
I encountered this problem but with a vertical gray line, and it was a rounding issue.
This was due to the fact that the div containing the map canvas was set to fluid-width (50% in my case) and more often than not did lead to a subpixel width.
To fix my problem, I had to listen to the map canvas resize event, retrieve and round the inner width of the container of the canvas (the one with width set to 50%) and set the rounded width back to map canvas - all of this in JavaScript of course.
Here is my HTML markup :
<div id="mapContainer">
<div id="mapCanvas"></div>
</div>
Here are my CSS rules :
#mapContainer {
width: 50%;
}
#mapCanvas {
height: 100%;
width: 100%;
float: right;
}
Here is the JavaScript fix :
var isResizing = false;
var fixMapCanvasRoundingIssue = function () {
if (isResizing == false) {
isResizing = true;
var width = Math.floor(document.getElementById("mapContainer").getBoundingClientRect().width);
$("#mapCanvas").width(width);
// is this needed ?
google.maps.event.trigger(map, "resize");
isResizing = false;
}
}
And here is the Google Map initialization :
var mapCanvas = document.getElementById("mapCanvas");
google.maps.event.addDomListener(mapCanvas, "resize", function () {
fixMapCanvasRoundingIssue();
});
map = new google.maps.Map(mapCanvas , {
...
});
fixMapCanvasRoundingIssue();
Note that I set the map canvas to float to the right to prevent any tearing issue on resize. This may not be needed in your case.
.gmap-container,
.gmap-container > div.gm-style,
.gmap-container > div.gm-style > div:first-child,
.gmap-container > div.gm-style > div:first-child > div > div:last-child,
.gmap-container > div.gm-style > div:first-child > div > div:last-child * {
-webkit-transform: none!important;
}
If -webkit-transform: none !important; doesn't work make sure your browser isn't zoomed in. Having it zoomed into 110% causes the same grey line.
Simply switch onto newer version of API:
<script src="http://maps.googleapis.com/maps/api/js?v=3.14&sensor=false"></script>
it worked for me!
The solution suggested by Optimiertes seems to be unfairly marked down as it worked for me.
I'd suggest caution as there may be cases when something on that level needs to be transformed, but I did the following and it worked great.
#map .gm-style div div *:not(.something-that-needs-transforming){
-webkit-transform: none !important;
}
I'm sure in time it'll be fixed in Chrome, but annoyed me enough for now to want to fix it.
Other solutions I tried didn't allow the map to pan.
In my case, I needed a simple way showing the location for a restaurant. All solutions didn't work for me and so I went for the following solution, using a iFrame, with the dimensions specified in my css class:
<div class="fluid google_maps">
<iframe
width="100%"
height="100%"
frameborder="0" style="border:0"
src="https://www.google.com/maps/embed/v1/place?key=PLACE_APIKEY_HERE
&q=eiffel tower">
</iframe>
</div>
Thats all to it, no javascript or anything, just a few lines of html.
Since I don't expect over 2kk visitors a day (google's free limit), it's perfect for me.
You do need to create a google API key, but that 1 minute work.
The eiffel tower, can be any address or known location, you normally fill in the google maps website.
#map *, #map *:before, #map *:after {
-webkit-transform: none !important;
}
it's right way if you don't use parallax effect, but if you want to hide horizontal line with parallax effect, here is fix:
.gm-style > div:first-child {
background-color: #000000;
}
color #000000 if your google map background color is black, if is other - change this color.
work fine with google maps parallax effect
I have a page with lots of data, tables and content.
I want to make a print version that will only display very few selected things.
Instead of writing another page just for printing, I was reading about CSS's feature for "#media print".
First, what browsers support it? Since this is an internal feature, it's OK if only the latest browsers support it.
I was thinking of tagging a few DOM elements with a "printable" class, and basically apply "display:none" to everything except those elements with the "printable" class.
Is that doable?
How do I achieve this?
EDIT:
This is what I have so far:
<style type="text/css">
#media print {
* {display:none;}
.printable, .printable > * {display:block;}
}
</style>
But it hides everything. How do I make those "printable" elements visible?
EDIT:
Trying now the negative approach
<style type="text/css">
#media print {
body *:not(.printable *) {display:none;}
}
</style>
This looks good in theory, however it doesn't work. Maybe "not" doesn't support advanced css ...
Start here. But basically what you are thinking is the correct approach.
Thanks, Now my question is actually
becoming: How do I apply CSS to a
class AND ALL OF ITS DESCENDANT
ELEMENTS? So that I can apply
"display:block" to whatever is in the
"printable" zones.
If an element is set to display:none; all its children will be hidden as well. But in any case. If you want a style to apply to all children of something else, you do the following:
.printable * {
display: block;
}
That would apply the style to all children of the "printable" zone.
If you want to display some links etc. when in the browser, that you don't want to be printed. Furthermore you have some logos and letterhead info that only should go on the printed page.
This seems to work fine:
Example:
CSS:
#media print {
.noPrint {
display:none;
}
}
#media screen {
.onlyPrint {
display: none;
}
}
HTML:
<div class="noPrint" id="this_is_not_printed" >
<a href=links.html>
</div>
<div class="onlyPrint" id="this_is_only_seen_on_printer" >
<img scr=logo.png >
<img scr=letterhead.png >
</div>
A simple way:
<style>
.print-only{
display: none;
}
#media print {
.no-print {
display: none;
}
.print-only{
display: block;
}
}
</style>
I got here because I was curious about printing a chart generated by chart.js. I wanted to just print the chart directly from the page (with a button that does a 'window.print') without all of the other content of the page.
So, I got closer by using the technique from the answer here: Why can't I override display property applied via an asterisk? .
You have to apply the 'asterisk' to the 'body' element, not just by itself. So, using the example CSS that the OP (Nathan) added to the question, I changed it to this:
<style type="text/css">
#media print {
body * {display:none;}
.printable, .printable > * {
display: block !important;
}
}
</style>
Then adding that 'printable' class to the chart itself, as in
<canvas id="myChart" class="printable" width="400" height="400"></canvas>
Which removed all page elements on the printed output except the chart when the 'print' button is clicked (via this):
<script>
myChart.render();
document.getElementById("printChart").addEventListener("click",function(){
window.print();
});
</script>
So, perhaps this will help anyone that gets to this question via the googles.
Came across the same question recently and for me, this solution works just perfect:
#media print {
* {
visibility: hidden;
}
.printable {
visibility: visible;
position: absolute;
top: 0;
left: 0;
padding: 10mm;
}
.printable * {
visibility: visible;
}
}
Since visibility: hidden doesn't remove elements, as display: none does, it is possible to change it for desired elements separately.
Nearly all browsers support it. It might be advantageous to use the media attribute on the link tag.
Using display: none; in some of your rules would be an appropriate way to handle your situation.
I suggest to hide the element that you won't print:
HTML
<h1 class="no-print" >Welcome Just Screen</h1>
<div> I want print this section :)</div>
<div class="no-print">It's display only on screen</div>
CSS
#media print {
.no-print {
display: none;
}
}
I have the following CSS for my print style:
* {
display:none;
}
#printableArea {
display:block;
}
I expected this to hide all elements, and only show the printableArea, however everything gets hidden. In print view, all I get is a blank page.
I have it included properly in the HEAD, with media="print" on this particular stylesheet.
If an element is not displayed, then none of its children will be displayed (no matter what their display property is set to).
* matches the <html> element, so the entire document is hidden.
You need to be more selective about what you hide.
You're taking the right general approach, but you want to use visibility: hidden instead of display: none so that you can set child elements to be visible.
See Print <div id=printarea></div> only?
html body * {
display:none;
}
#printableArea {
display:block;
}
Also, you may need an !important on #printableArea, but probably not.
Answering because I found this question while searching for this
Instead of 'display: none' you can use :
* {
visibility: hidden;
margin:0; padding:0;
}
#printableArea * {
visibility: visible;
}
source : https://www.concrete5.org/community/forums/5-7-discussion/need-to-print-a-certain-div-and-ignore-everythign-else-on-the-pa
You might try popping it up on top of everything. This solved 90% of my problems, then I just had to make a .noprint class and add it to a few straggling elements.
.print_area{
position: fixed;
top: 0px;
left: 0px;
width: 100%;
z-index: 9999;
background-color: #ffffff;
}
If you want to use JavaScript, you can try this simple snippet that doesn't even require jQuery:
document.body.innerHTML=document.getElementById('printableArea').innerHTML;
make a div wrap everything after the body tag. Before the wrap div, put the visible item's div.
I had to do this to make a simple username-password page, and needed to hide everything, except the half-opaque sign-in form's background. So, after the correct credentials were typed in, the form would animate out, and the half-opaque page cover would animate out, and finally, EVERYTHING aside would show up and you could use the page normally.
There is a one-line solution:
With JQuery
var selector = '';
$(document.head).append($('style').text('*{visibility:hidden}' + selector + '{visibility:visible}'));
Without JQuery
var selector = '';
document.head.appendChild(Object.assign(document.createElement('style'), { innerText: '*{visibility:hidden}' + selector + '{visibility:visible}' });
In both examples, set the selector variable to the selector you want. For example, div#page:hover or p.class1,p.class2
#media print {
* {
visibility: hidden;
}
/* Show element to print, and any children he has. */
.svgContainer, .svgContainer * {
visibility: initial;
}
}
Make sure any children elements are also visible. Remember that invisible elements still influence positionning of other elements in the page. In my (simple) case, I just added position: fixed; on .svgContainer (somewhere else).
Simply you can use the following code and assign "hide" class to that specific element you dont want to display on print page
<style type="text/css" media="print">
img
{
display:none;
}
.hide
{
display:none;
}
</style>
There is another clean way to achieve this:
* {
visibility: hidden;
}
#printableArea {
visibility: visible;
position: absolute;
top: 0;
left: 0;
width: 100%;
}
That way you're going to get only the #printableArea element in the print view and all of the other elements will be hidden.