I'm not a coder (which will soon become apparent) but I'm working on something for a work project and I'm stuck on the final bit.
I need to add a calc() working into the scale but it just won't work. Without going in to the in's and outs of why I need this, I know generally there would be better ways of doing what I want to achieve but I just want to know how I can get this working the way I need it.
I want the Transform: Scale() to adapt in size relative to the viewport size. I would assume from my research I add a calc() function using 100vw and my other workings.
I've put where I am so far below the scale function works as should i.e indivual values from 0-1 change the scale up to 100%. The Calc() function works fine with basic sums i.e 10 - 5 gives a value of 5 and 500% zoom but as soon as I add 100VW it stops working please please help!
body {
margin: 0;
padding: 0;
width: 100vw;
text-align: center;
}
#wrap {
width: 1535;
height: 900;
padding: 0;
overflow: hidden;
}
#frame {
width: 1535;
height: 900;
overflow: hidden;
-webkit-transform: scale(calc(100vw/1535));
-webkit-transform-origin: 0 0;
}
Two things here.
Your #wrap and #frame need to have some kind of unit on their widths. So this is your chance to change sizes relative to the viewport. For example, if you want them to be 1535px wide when the viewport is 1920px wide, but you want them to maintain that ratio as the viewport shrinks, set them to be 79.947917vw wide. (1535 / 1920 = 0.79947917). You can do something similar with the heights as well.
A scale transformation doesn't need units. Scales take a unitless number, which serves as a multiple of the element's original size. So scale(2) is twice as large as normal, or scale(0.5) is half as large as normal. You can also use two numbers to adjust the element's width and height differently. For example, scale(2, 3) would make the element grow to twice its original width and three times its original height.
Since transforms are relative to the element and not to the document, this means that you don't need to use any kind of calc inside your transform expression because having the element itself shrink and grow as the viewport shrinks and grows will also cause the amount of scaling to shrink and grow proportionally as well.
Related
I have an image which width should be as large as possible and I want it's height to not exceed the height of the parent while also maintaining the aspect ratio of 16:9. The issue right now is, it works well till the screen size is 1591px, if it gets bigger than that, the height exceeds and the vertical scroll bar appears. I don't want that behavior. How can I achieve that?
the scrollBar appears because of the overflow you can do 2 things
use the "overflow: hidden;"
body{
overflow: hidden;
}
you can use max-width to determine the max-width of the element and set it on both of the elements
I hope it was helpful 😁
UPDATE: the original answer assumed from the question that the image was an HTML img. The solution was to set width to 100% [of its container] and height to 70vh and use object-fit.
However, it is not an img it is a canvas.
The required aspect ratio is known to be 16 / 9. This snippet therefore sets the max-width to 100% (of whatever is the container) and the max-height to 70vh.
This way there can never be any overflow and the canvas will be as big as it can be within those constraints.
body {
width: 100vw;
margin: 0;
}
canvas {
max-width: 100%;
max-height: 70vh;
aspect-ratio: 16 / 9;
background: green;
}
<canvas width="1600" height="900"></canvas>
I want every image in a container to shrink so all of them combined don't go over the max-height of the container.
I am an admin in a forum running Xenforo (but not sadmin, so I'm limited to template access).
We've been limiting signature size by cutting off anything over a given height (490px) and hiding the overflow. We also resize images in signatures to a maximum of a value approaching the max signature value (400px) leaving some small vertical real estate for text and whatnot.
.signature .bbCodeImage {
max-height: 400px;
max-width: 700px;
height: auto;
}
.message .signature {
max-height: 490px;
max-width: 700px;
margin: 0 auto;
overflow: hidden;
}
"signature" is the container, "bbCodeImage" are the elements within I'm trying to shrink.
https://codepen.io/anon/pen/rgLKKJ
The codepen link shows the current behavior.
This works pretty well for a single image, but as soon as there's more than one, or even if there's text content inside the same container but prior to the image itself, then it cuts off excess (or goes out of max-height bounds if we don't hide the overflow) instead of just shrinking the image further to fit everything in the container.
In the above codepen example, I'd like all three pictures to display within 490px vertically, total. I could, of course, set .bbcodeImage max-height to a dimension that could fit inside 490px three times, but the idea is that the CSS should shrink however many images to fit inside 490px, as need be.
Can it be done with just CSS?
I would like to have a vertically and horizontally centered div that is 70vw wide and 70vh high. Something like this:
.centeredBox {
width: 70vw;
height: 70vh;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
}
However, I don't want the width and height to be recalculated every time that the viewport's size changes. If possible I would like the 70vw and 70vh to only be calculated at page load, so it starts at that size, but also stays that size regardless of if the browser window is resized. Is it possible to convert vw or vh values to a pixel count?
Please, no Javascript. I need this "NoScript compliant".
No, it's not possible with CSS. I would suggest to play around with pixels and see what comes close to what you're thinking.
Speaking for myself, I wouldn't choose pixels though. The beauty of relative units is that they allow you to build something suitable for different devices. Why wouldn't you want your design to be responsive?
On this page, the columns for the video thumbnails don't seem to display consistently (equally) on Chrome. On IE and FF, both column widths are equally displayed.
My global CSS for image have been set to:
img {
height: auto;
max-width: 100%;
}
Altering any values will affect other image rendering. Any ideas?
The issue is that you don't actually set a width, meaning browsers and images can render any way they want, giving unpredictable results as you've seen.
The easiest solution is to just size your columns to a fixed 50% width, like so:
.page-videos .view-video td {
width: 50%;
}
Leave the max-width: 100% in place, it will ensure that even large images fit this 50% perfectly.
Feel free to replace the classes of my sample code, they are simply a best guess at ensuring we only change this one table, but you may know better/more-specific classes for this project.
Removing max-width globally fixes it, or override it with min-width instead. max-width only sets the maximum width permitted, not an actual width
.cboxElement img {
height: auto;
min-width: 100%;
}
Hello fellow stackies,
I'm developing a site and I have a small "problem". It's not that important, the site works but it's just one of those annoying things that u keep scratching ur head about over and over.
What I'm trying to do is mix static height with dynamic height.
Example:
HTML:
< HTML >
< BODY >
< DIV class="header_with_menu" >
< /DIV >
< DIV class="main_content" >
< /BODY >
< /HTML >
CSS:
body{ margin: 0; padding 0;
width: 100%; height: 100%; }
.header_with_menu {display: block; margin-left: 100%; margin-right: 100%; height: 160px; }
.main_content {display: block; margin-left: 100%; margin-right: 100%; height: 80% }
As u can see, nothing fancy. I use a custom scrollbar javascript on main_content.
It works fine until I start screwing with the window height of firefox (or any other browser).
What I expect: When I make the window of firefox smaller and smaller, main_container will get smaller and smaller, but, remain inside of the firefox window (since it's height is dynamic, it will simply adjust because it's cool.)
What happens: The height of main_container will eventually get stuck at a certain height, which I don't specify, and content will start disappearing out of view at the bottom of the browser window.
I want main_content to stay inside of the viewscreen and auto adapt to the height of the browserwindow.
How do I do this??
It's annoying when you have a smaller monitor with just 768 px of height and about 10px fall outside of the scrollable area... And the worst thing is, I can't seem to get it behave on my own. I've tried making things absolute, they just overlap each other and now way stopping that since they're both absolute and outside of normal flow. I've tried experimenting with maximum and minimum heights in percentages for both header and only container... didn't work. Searched for javascript to auto-fiddle with my css' height or max-height percentage, didn't work out too well...
basically i've been sparing with this for two days now and I'm just not creative enough to come up with some solution.
Is there a pure css solution for this?
(P.S. I'm using 77% height now for main_content since that seems to be the perfect border: not too small for 1920x1080, and not too large so content will start to disappear # 1440x900. 78% will make content start disappearing and below 75% just makes it seem ugly at 1920x1080.)
I'm sorry for answering my own question, but the answer is: use a flow layout with a script that calculates the space to the bottom of the screen using percentages calculated by the current width and height of the window, to calculate the height of the content and/or footer div.
If I have time I'll post the script here as an edit.