I have such function to calc from pixels to vw and it works perfectly for portrait orientation
#function get-vw($target) {
$vw-context: (320*.01) * 1px;
#return ($target/$vw-context) * 1vw;
}
But awful for landscape orientation. It's a pity but such function doesn't work
#function get-vw($target) {
$vw-context: (320*.01) * 1px;
#media only screen and (orientation: landscape) {
#return ($target/$vw-context) * 1vh;
}
#media only screen and (orientation: portrait) {
#return ($target/$vw-context) * 1vw;
}
}
Has anyone similar problem? How did you solve it?
In css (sass, less, no matter) you can't dynamically set the values. You should generates all properties for all conditions and all orientations in advance.
So #media blocks should be placed in element selector scope. And inside these #media's you should set sizes.
Sassmeister demo.
Sass:
// $target: number in pixels
// $orientation: string - portrait (default) | landscape
#function get-vw($target, $orientation: portrait) {
$vw-context: (320 * .01) * 1px;
$axis-unit: 1vw;
#if ($orientation == landscape) {
// Not shure about 240
$vw-context: (240 * .01) * 1px;
$axis-unit: 1vh;
}
#return ($target / $vw-context) * $axis-unit;
}
a {
#media only screen and (orientation: landscape) {
size: get-vw(12px, landscape);
}
#media only screen and (orientation: portrait) {
size: get-vw(12px);
}
}
Css:
#media only screen and (orientation: landscape) {
a {
size: 5vh;
}
}
#media only screen and (orientation: portrait) {
a {
size: 3.75vw;
}
}
Related
After hours of work, trying to add a background to my svg i finally did it, but unfortunately if you go to resolution width= 767 and bellow the background image disappear. I really have no idea why is happening.
Here is the code i am using:
const width = 555
const height = 555
const canvas = d3.select(element)
.append('div')
.classed(css.svgContainer, true)
.append('svg')
.attr('preserveAspectRatio', 'xMinYMin meet')
.attr('viewBox', `0 0 ${width} ${height}`)
.attr('xmlns', 'http://www.w3.org/2000/svg')
.classed(css['svg-content-responsive'], true)
for (let i = 1; i < svg.length; i++) {
if (svg[i].type === 'path') {
const id = setItemId(i)
defs.append('svg:pattern')
.attr('id', id)
.attr('width', '275')
.attr('height', '281')
.attr('patternUnits', 'userSpaceOnUse')
.attr('patternTransform', 'matrix(1,0,0,1,0,0) translate(251.5,142.3)')
.append('svg:image')
.attr('xlink:href', imageSrc)
.attr('width', '275')
.attr('height', '281')
.attr('x', 0)
.attr('y', 0)
}
}
// Here is the css which makes the svg responsive
.svgContainer {
display: inline-block;
position: relative;
width: 100%;
padding-bottom: 100%; /* aspect ratio */
vertical-align: top;
overflow: hidden;
}
.svg-content-responsive {
display: inline-block;
position: absolute;
left: 0;
}
I have the following mixin containing media queries:
#mixin respond($breakpoint) {
#if $breakpoint == phone {
#media only screen and (max-width: 37.5em) { #content }; //600px
}
#if $breakpoint == tab-port {
#media only screen and (max-width: 56.25em) { #content }; //900px
}
#if $breakpoint == tab-land {
#media only screen and (max-width: 75em) { #content }; //1200px
}
#if $breakpoint == big-desktop {
#media only screen and (min-width: 112.5em) { #content }; //1800px
}
}
I would like to share the same CSS properties for two of those media queries but I am not succeeding in doing so. I've written it as follows but it doesn't work.
#include respond(phone),
#include respond(tab-port) {
some CSS properties
}
I was wondering if anyone could help. Thanks in advance for doing so!
You would create another mixin with the properties you want them both to share, and then use that in each include.
In mixin files:
#mixin two-device {
#media (max-width: 37.5em) {
#content;
}
#media (max-width: 56.25em) {
#content;
}
}
And then you should use it:
#include two-device {
font-size: 50%;
}
#mixin respond($breakpoint) {
#if $breakpoint == phone {
#media only screen and (min-width: 37.5em) { #content; } //600px
}
#else if $breakpoint == tab-port {
#media only screen and (min-width: 56.25em) { #content;} //900px
}
#else if $breakpoint == tab-land {
#media only screen and (min-width: 75em) { #content; } //1200px
}
#else $breakpoint == big-desktop {
#media only screen and (min-width: 112.5em) { #content; } //1800px
}
}
I am using html2canvas library to take screenshot of html view.
but background-image failed to load. i am getting error message Error loading background:
here is my JSFiddle.
window.takeScreenShot = function() {
html2canvas(document.getElementById("target"), {
onrendered: function (canvas) {
document.body.appendChild(canvas);
},
useCORS:true,
logging:true,
allowTaint:true
});
}
#target{
width:300px;
height:160px;
background:lightblue;
color:#fff;
padding:10px;
background-image: url(https://static.pexels.com/photos/20974/pexels-photo.jpg);
background-repeat:no-repeat;
background-position:center center;
-o-background-size: 100%;
-moz-background-size: 100%;
-webkit-background-size: 100%;
background-size: 100%;
height: 100%;
}
#borderimg1 {
border: 10px solid transparent;
padding: 15px;
-webkit-border-image: url(https://www.w3schools.com/cssref/border.png) 30 round; /* Safari 3.1-5 */
-o-border-image: url(https://www.w3schools.com/cssref/border.png) 30 round; /* Opera 11-12.1 */
border-image: url(https://www.w3schools.com/cssref/border.png) 30 round;
}
#borderimg2 {
border: 10px solid transparent;
padding: 15px;
-webkit-border-image: url(https://www.w3schools.com/cssref/border.png) 30 stretch; /* Safari 3.1-5 */
-o-border-image: url(https://www.w3schools.com/cssref/border.png) 30 stretch; /* Opera 11-12.1 */
border-image: url(https://www.w3schools.com/cssref/border.png) 30 stretch;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.min.js"></script>
<button onclick="takeScreenShot()">to image</button>
<div id="target">
<p>The border-image property specifies an image to be used as the border around an element:</p>
<p id="borderimg1">Here, the middle sections of the image are repeated to create the border.</p>
<p id="borderimg2">Here, the middle sections of the image are stretched to create the border.</p>
<p>Here is the original image:</p><img src="https://www.w3schools.com/cssref/border.png">
<p><strong>Note:</strong> Internet Explorer 10, and earlier versions, do not support the border-image property.</p>
</div>
image for error message
For Internet security reasons, trying to use an image from a different domain in a canvas causes problems. There are two html2canvas options, useCORS and proxy, which are designed to try to get around that problem.
You have to create the proxy in you project and use that into html2canvas proxy option.
Click here to view sample proxy created in different programming languages.
Usage of proxy in html2canvas(c# example)
html2canvas(document.body, {
"logging": true, //Enable log (use Web Console for get Errors and Warings)
"proxy":"html2canvasproxy.ashx",
"onrendered": function(canvas) {
var img = new Image();
img.onload = function() {
document.body.appendChild(img);
};
img.error = function() {
if(window.console.log) {
window.console.log("Not loaded image from canvas.toDataURL");
} else {
alert("Not loaded image from canvas.toDataURL");
}
};
img.src = canvas.toDataURL("image/png");
}
});
I have same problem.
It's just because of not surpoted problem.
Check this:
http://html2canvas.hertzen.com/features
Unsupported CSS properties
These CSS properties are NOT currently supported
background-blend-mode
border-image
box-decoration-break
box-shadow
filter
font-variant-ligatures
mix-blend-mode
object-fit
repeating-linear-gradient()
writing-mode
zoom
I found out the solution to this. Putting a rectangle as border for each PDF page and also starting the second page, and other pages from a litte down, by making difference in the pageHeight.
You can try it like this:
html2canvas(myCanvas).then(function(canvas) {
var imgWidth = 210;
var pageHeight = 290;
var imgHeight = canvas.height * imgWidth / canvas.width;
var heightLeft = imgHeight;
var doc = new jsPDF('p', 'mm');
var position = 0;
var pageData = canvas.toDataURL('image/jpeg', 1.0);
var imgData = encodeURIComponent(pageData);
doc.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight);
doc.setLineWidth(5);
doc.setDrawColor(255, 255, 255);
doc.rect(0, 0, 210, 295);
heightLeft -= pageHeight;
while (heightLeft >= 0) {
position = heightLeft - imgHeight;
doc.addPage();
doc.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight);
doc.setLineWidth(5);
doc.setDrawColor(255, 255, 255);
doc.rect(0, 0, 210, 295);
heightLeft -= pageHeight;
}
doc.save('file.pdf');
});
Hope this will resolve your issue.
I am working in angular application. i have a scenario here, when i am getting the titles from back-end the client requires that to be arranged around a oval (it contains some image)
and when the tiles length are odd then the firs element ( balance ) should be in the top. rest of the titles need to arrange the both side of the oval.
when i am getting the title length as even there is no need to keep the title in the top.
i tried some point. but i didn't get any valuable output.
my be the way i am doing (directive) is wrong? or this should be handle with some other way?
any one help me to find the mathematical logic here please?
click the bottom button to create random titles
Live Demo of my try
If I understand it correctly, you want something like this:
var radiusX = 250,
radiusY = 100,
texts = [],
oval = document.getElementById('oval'),
inp = document.querySelector('input');
document.querySelector('button').onclick = function() {
texts.push(inp.value);
inp.value = '';
while(oval.firstChild) oval.removeChild(oval.firstChild);
texts.forEach(function(text, i, arr){
var angle = Math.PI + (i*2 + 1 - arr.length%2) * Math.PI / arr.length;
var el = document.createElement('div');
el.style.top = radiusY + Math.cos(angle) * radiusY + 'px';
el.style.left = radiusX -Math.sin(angle) * radiusX + 'px';
el.textContent = text;
oval.appendChild(el);
});
};
#oval {
width: 500px;
height: 200px;
background: red;
border-radius: 100%;
margin: 0 auto;
position: relative;
margin-top: 20px;
}
#oval > div {
position: absolute;
line-height: 1.2;
height: 1.2em;
width: 3em;
margin-top: -.6em;
margin-left: -1.5em;
text-align: center;
}
<input id="text" placeholder="Write text..."/>
<button>Add text</button>
<div id="oval"></div>
Basically, divide 2 * Math.PI (360deg) into n equal angles, where n is the number of texts.
Then use Math.cos and Math.sin on that angle, and multiply it by the horizontal or vertical radius of the ellipse. That will give the coordinates relatively to the center of the ellipse.
i m using this CSS to setting my tab's height
.MainPanel .x-tab-bar-strip {
top: 40px !important; /* Default value is 20, we add 20 = 40 */
}
.MainPanel .x-tab-bar .x-tab-bar-body {
height: 43px !important; /* Default value is 23, we add 20 = 43 */
border: 0 !important; /* Overides the border that appears on resizing the grid */
}
.MainPanel .x-tab-bar .x-tab-bar-body .x-box-inner {
height: 41px !important; /* Default value is 21, we add 20 = 41 */
}
.MainPanel .x-tab-bar .x-tab-bar-body .x-box-inner .x-tab {
height: 41px !important; /* Default value is 21, we add 20 = 41 */
}
.MainPanel .x-tab-bar .x-tab-bar-body .x-box-inner .x-tab button {
height: 33px !important; /* Default value 13, we add 20 = 33 */
line-height: 33px !important; /* Default value 13, we add 20 = 33 */
}
The problem is the Icon do not show properly.
Question
I want to change the tabs icon size to 32x32 and align middle.
Try redefining this class :
*.MainPanel .x-tab-icon-el img{
width: 100%; /* did this to center the icons */
height: 100%; /* did this to center the icons */
display: block; /* did this to center the icons */
margin-left: auto; /* did this to center the icons */
margin-right: auto; /* did this to center the icons */
}*
and if needed the rest of the tab content
*.MainPanel .x-tab-inner .x-tab-inner-center{
}*