I'm trying to display a panoramic image with a specific size and a hidden overflow to eventually enable user-induced panning (the code is not included below).
I'm adding the image this way:
<div class="pan">
<img src="http://lorempixel.com/image_output/sports-q-c-1920-480-7.jpg">
</div>
I am setting the image size parameters this way:
.pan {
width: 800px;
height: 400px;
overflow: hidden;
border: red solid;
}
However, when I change the width, the height changes proportionally, and I don't have any overflow to hide. The image is 13632 × 2936.
This is the result I get from the code above:
When setting the size this way, I get the image below:
.pan {
width: 400px;
height: 400px;
overflow: hidden;
border: red solid;
}
Trying to override img parameters set to 100% (for other purposes), I get a distorted image--still no hidden overflow:
.pan img {
height: 800px;
width: 400px;
transition: opacity .6s linear .8s;
}
Other code related to .pan and a container (from tutorial cited below) :
.pan img{
transition: opacity .6s linear .8s;
}
.pan img.loaded{ opacity: 1; }
.img-pan-container, .img-pan-container img{ -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; }
.img-pan-container{
position: relative;
overflow: hidden;
cursor: crosshair;
height: 100%;
width: 100%;
}
.img-pan-container img{
-webkit-transform: translateZ(0); -ms-transform: translateZ(0); transform: translateZ(0);
position: absolute;
top: 0;
left: 0;
}
For info, I am trying to implement this example. However, I am not currently focusing my question on the rest of the panning code, as I am having issues just getting the image sized correctly with the hidden overflow.
The img child has to be larger than the parent .pan, see snippet below with an image of 1920px width and 480px height. But this will crop parts of the image.
Snippet
.pan {
width: 800px;
height: 400px;
overflow: hidden;
border: red solid /* demo */
}
img {
display:block /* fix inline gap */
}
<div class="pan">
<img src="http://lorempixel.com/1920/480/" />
</div>
UPDATE
Based on your updated question, it is most likely you have in your css img set as max-width:100%, see the same snippet above with that property set.
Snippet
.pan {
width: 800px;
height: 400px;
overflow: hidden;
border: red solid /* demo */
}
img {
display:block; /* fix inline gap */
max-width:100% /* YOUR ISSUE */
}
<div class="pan">
<img src="http://lorempixel.com/1920/480/" />
</div>
UPDATE OP's Comment:
This may be the case...How can I override img for only this class?
If you can't find the origin and/or want to keep the max-width:100% for other imgs you can override by using max-width:none on .pan > img
.pan {
width: 800px;
height: 400px;
overflow: hidden;
border: red solid /* demo */
}
img {
display: block; /* fix inline gap */
max-width: 100% /* YOUR ISSUE */
}
.pan > img {
max-width: none
}
<div class="pan">
<img src="http://lorempixel.com/1920/480/" />
</div>
You can try to archive cover effect for image using this css:
.pan {
...
position: relative;
}
img {
position: absolute;
top: 50%;
left: 50%;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
transform: translate(-50%, -50%);
}
JSFiddle here
Related
Here is a link to a demo
I'm not sure what I'm missing, I've done this before a few times but It's been a day of fighting this particular CSS. I want the image to enlarge, but stay within the dimensions, so a zoom effect versus any enlargement. I've attempted to move the overflow:hidden into other parent or children, but it doesn't have an effect. I've played around with the display settings as well.
Any advice? The JSfiddle link is above, and the code below. Thanks for taking a look!
#purple-square {
width: 355px;
height: 255px;
background-image: url("../img/website_cards/purple_card.png");
border-radius: 10px;
}
#migraine-dentistry {
width: 355px;
height: 255px;
background-image: url("../img/website_cards/migraine_dentistry_card.png");
border-radius: 10px;
}
/* need position: relative in shell otherwisee the elements disappear */
#shell {
margin: auto;
width: 355px;
height: 255px;
position: relative;
transform-origin: center;
transition: 0.3s ease-in-out;
}
#shell:hover {
transform: scale(1.2);
}
#container {
width: 100%;
overflow: hidden;
display: inline-block;
transition: 0.3s;
margin: 0 auto;
}
#container div {
position: absolute;
left: 0;
transition: 0.3s ease-in-out;
}
#container:hover {
transition: ease-in-out 0.3s;
}
#container div.bottom:hover {
opacity: 0;
}
and here is the HTML setup:
<body>
<div id="shell">
<div id="container">
<div id='purple-square' class="top"></div>
<div id='migraine-dentistry' class="bottom"></div>
</div>
</div>
</body>
Full working code snipped below my steps
remove unnecessary elements Removed purple square, because it's never seen in wanted animation.
Removed the part the full #container div.bottom:hover part.
Removed every style that begins with #shell in the css and later trigger the animation on #container:hover.
main issue Add an #migraine-dentistry after the #container:hover animation, so if someone hovers the container it effects the #migraine-dentistry element. (#container:hover #mi.. {trans..})
In this (#container:hov..) element remove everything and
insert transform: scale(1.2);
because we just want to scale if user is hovering.
Remove whole #container div {..} style element, because we will directly add these styles to the #migraine-dentistry element.
In #container define px values for
> width: 355px; and height: 255px;
just because we not use the #shell element anymore. Also
> set position: relative; and z-index: 2;
that the #migrain.. element is inside his parent. And
> set border-radius: 15px;
for styling. Finally
>remove the display and transition values
because they are simply not needed.
last In #migraine-de.. styles
>set width: 100%; and height: 100%;
to fit div to parent.
> remove border-radius tag
because it's set by the #container
> add transition: 0.3s ease-in-out;
to transition like you wanted.
#container {
border-radius: 15px;
width: 355px;
height: 255px;
overflow: hidden;
z-index: 2;
position: relative;
}
#container:hover #migraine-dentistry {
transform: scale(1.2);
}
#migraine-dentistry {
width: 100%;
height: 100%;
transition: 0.3s ease-in-out;
background-image: url('https://images.unsplash.com/flagged/photo-1563248101-a975e9a18cc6?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1950&q=80');
}
<body>
<div id="shell">
<div id="container">
<div id='migraine-dentistry' class="bottom"></div>
</div>
</div>
</body>
I know these long nights where you just can't get it done.
I need to create an image gallery, in which the individual images are irregular triangles (emphasis on irregular).
I found limited examples on how to achieve triangle images via html and css, without modifying the images themselves. One example I found in this CodePen https://codepen.io/thebabydino/pen/liDCz was a step in the right direction, but looking at it, I can't find a way to make the images irregular triangles.
The result I am trying to achieve is this:
<div class='pageOption'>
<a href='#' class='option'>
<img src='~/images/team/pic_paggas/A.png'>
</a>
<a href='#' class='option'>
<img src='~/images/team/pic_paggas/D.png'>
</a>
</div>
This is the basic HTML I will be using and the CSS is:
.pageOption {
overflow: hidden;
position: relative;
margin: 0 auto;
width: 40em;
height: 27em;
}
.option, .option img {
width: 100%;
height: 100%;
}
.option {
overflow: hidden;
position: absolute;
transform: skewX(-55.98deg);
}
.option:first-child {
left: -.25em;
transform-origin: 100% 0;
}
.option:last-child {
right: -.25em;
transform-origin: 0 100%;
}
.option img {
opacity: .75;
transition: .5s;
}
.option img:hover {
opacity: 1;
}
.option img, .option:after {
transform: skewX(55.98deg);
transform-origin: inherit;
}
Mind that the HTML and CSS I have may not be the optimal for my problem. I think the shape of the images I am using (rectangular) have something to do with this.
Would be better if the solution is better supported across browsers.
You can do it with skew like below if you cannot use clip-path:
.box {
overflow: hidden;
width: 200px;
height: 200px;
display:inline-block;
}
.triangle {
width: 100%;
height: 100%;
transform: skewX(-20deg) skewY(45deg); /* 27deg instead of 20deg to have a regular triangle */
transform-origin: bottom left;
overflow: hidden;
background-size:0 0;
}
.triangle.bottom {
transform-origin: top right;
}
.triangle:before {
content: "";
display: block;
width: inherit;
height: inherit;
background-image: inherit;
background-size:cover;
background-position:center;
transform: skewY(-45deg) skewX(20deg); /* We invert order AND signs*/
transform-origin: inherit;
}
.triangle:hover {
filter:grayscale(100%);
}
.adjust {
margin-left:-120px;
}
body {
background:#f2f2f2;
}
<div class="box">
<div class="triangle" style="background-image:url(https://picsum.photos/id/155/1000/800)"></div>
</div>
<div class="box adjust">
<div class="triangle bottom" style="background-image:url(https://picsum.photos/id/159/1000/800)"></div>
</div>
I'm trying to create an animated picture which contains a lot of layers.
In order to have images with right proportions on different screens I use cover css property value(I've tried it for both object-fit for images and background-size for background images). That's why my images on wide screen are croped by the browser.
The problem is that my layers are transformed(mostly rotated and moved) during the animation so there are moments when it is seen the cropped image.
Please see my example below.
How it can be prevented? Or it there some other technique?
body {
margin: 0;
padding: 0;
/*Just to imitate wide screen*/
width: 1000px;
height: 450px;
}
#container {
width: 100%;
height: 100vh;
/*Just to imitate wide screen*/
height: 100%;
overflow: hidden;
position: relative;
}
.layer {
height: 100%;
position: absolute;
width: calc(100% + 20px);
}
.layer img {
height: 100%;
width: 100%;
object-fit: cover;
}
.gulls {
animation: gulls ease-in-out 13s infinite alternate;
}
#keyframes gulls {
from {
transform: rotate(3deg) scaleX(0.95) skew(-10deg, -10deg);
}
to {
transform: rotate(-3deg) scaleX(1.05) skew(10deg, 10deg);
}
}
<div id="container">
<div class="layer">
<img src="https://firebasestorage.googleapis.com/v0/b/wedding-42174.appspot.com/o/animation%2Fsky.png?alt=media&token=25033588-d58c-4616-94e9-4974ec4157a4" alt="">
</div>
<div class="layer gulls">
<img src="https://firebasestorage.googleapis.com/v0/b/wedding-42174.appspot.com/o/animation%2Fgulls5.png?alt=media" />
</div>
</div>
Currently I have this: https://jsfiddle.net/koljada/c08qdw1m/
first of all i have to say that your birds image is a lot bigger then the birds therself (many padding around) as i see the whole image is 2048/1934...
anyway, when you use
object fit:cover he crop;
the image for save the proportion. you can using
object-fit:scale-down;
for save the proportion by scale down the image until he come inside the parent space. i add a quick exemple about how it works down here:
hope it is what you search for..
Images can be cropped with a container div with overflow: hidden; position: relative, So you can position the image inside with position: absolute. The top and left css attribute of the image has to be set a negative value.
The image exact values can be found by using sine and cosine functions.
body {
margin: 0;
padding: 0;
/*Just to imitate wide screen*/
width: 200px;
height: 100px;
}
#container {
width: 100%;
height: 100vh;
/*Just to imitate wide screen*/
height: 100%;
overflow: hidden;
position: relative;
}
.layer {
height: 100%;
position: absolute;
top: -20px;
left: -20px;
width: calc(100% + 20px);
}
.layer img {
height: 150%;
width: 150%;
}
.gulls {
animation: gulls ease-in-out 3s infinite alternate;
}
#keyframes gulls {
from {
transform: rotate(3deg) scaleX(0.95) skew(-10deg, -10deg);
}
to {
transform: rotate(-3deg) scaleX(1.05) skew(10deg, 10deg);
}
}
<div id="container">
<div class="layer gulls">
<img src="http://via.placeholder.com/350x150/000000" />
</div>
</div>
You can use overflow: hidden; position: relative to crop your images after using container div, and using position: absolute at the images to place the image.
I'm trying to move a div with a dynamically changing height out of it's parent div and back in.
The problem is the dynamically height, otherwise I could easily set the negative height as the bottom value.
For now I just set a large negative number of pixels as the bottom value, but it isn't very nice and does not solve the problem properly. (logically this happens for small numbers: fiddle)
Hopefully the example below clarifies what I try to do.
I was thinking about using transforms instead, but i did not find a solution as well.
Of course I could do this with JavaScript, but as everyone I prefer a pure CSS solution :)
#outer {
position: relative;
width: 400px;
height: 400px;
background: black;
overflow: hidden;
}
#inner {
position: absolute;
bottom: -500px;
/*
It's working but ugly and not perfect.
The value I need would be the height of the inner div, but it is dynamic
*/
width: 100%;
background: red;
transition: 0.4s;
}
#outer:hover #inner {
transition: 0.4s;
bottom: 0;
}
<div id="outer">
<div id="inner">
Some expanding text here
</div>
</div>
You could use CSS transform:translateY(100%) property, so the height is calculated based on the element itself. Then reset the value to 0 on hover.
Inspect the element, you'll be able to see exact the height and position of it.
Also take a look of support tables for transform, and prefix it if necessary.
Updated JsFiddle
.outer {
position: relative;
display: inline-block;
width: 100px;
height: 100px;
background: grey;
overflow: hidden;
}
.inner {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
background: aqua;
transition: 0.4s;
transform: translateY(100%);
}
.outer:hover .inner {
bottom: 0;
transform: translateY(0);
}
<div class="outer">
<div class="inner">Some expanding text here..</div>
</div>
If I understand your issue, you can set a max-height for its normal and :hover state and transition it. However, you must set it to a max-height that you know will always be tall enough (which may lead to random speeds depending on how much content there is).
So something like: JS Fiddle
.outer {
position: relative;
display: inline-block;
width: 400px;
height: 400px;
background: black;
overflow: hidden;
}
.inner {
position: absolute;
bottom: 0px;
width: 100%;
background: red;
transition: 0.4s;
max-height: 0;
overflow: hidden;
}
.outer:hover .inner {
transition: 0.4s;
bottom: 0;
max-height: 40px;
}
Otherwise, I would recommend a JS solution.
For some reason my vertical alignment code is blurring some but not all child elements in Chrome and Safari.
Whats causing it is the translateY(-50%), if I remove this then blurriness is gone however the vertical centring effect is lost.
/* #group Center all the things */
.center-wrapper {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
}
.center-wrapper .center {
position: relative;
overflow: hidden;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
/* This fixes the blurred buttons but breaks centering
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
transform: translateZ(0);*/
}
/* #end */
Tried and tested methods such as below work but they break the vertical centring:
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
transform: translateZ(0);
Faced the same issue while trying to position buttons in the middle, but the button appeared on hover of the parent element and each time text inside was randomly cut.
The solution is:
.positioned-button {
transform: translateY(-50%) scale(1);
filter: blur(0);
line-height: 1;
}
Breaks nothing, fixes Chrome :)
The only way around this blurry issue, from what I could see was to change the vertical alignment method and use display: table instead. Here's how I did it:
1) Keep HTML markup the same
<div class="center-wrapper">
<div class="center">
<p>Centered content here</p>
</div>
</div>
2) Change CSS to the following:
/* #group Center all the things */
.center-wrapper {
min-height: 100%;
padding: 0;
display: table;
width: 100%;
}
.center-wrapper .center {
display: table-cell;
vertical-align: middle;
}
/* #end */
You can see the display table in action here.
.center-wrapper {
min-height: 200px;
padding: 0;
display: table;
width: 100%;
background: black;
}
.center-wrapper .center {
display: table-cell;
vertical-align: middle;
color: white;
}
.center-wrapper .center div {
height: 40px;
background: red;
width: 50%;
margin: 0 auto;
}
<div class="center-wrapper">
<div class="center">
<div>Centered content here</div>
</div>
</div>