I know there have been several questions on the subject but none of them quite answers my problem... I have 13 SVGs piled one over the other (I am using a JS script to make one appear and the other disappear, thus creating an "animation" effect where something moves from one position to the other) and I positioned them as absolute to have them piled. The problem is: I work on a 17" screen and when I look with screenfly what my page looks like on bigger screens (24"), my elements are not well positioned anymore.
I have already tried positioning it with all the units I knew of (px, %, vw/vh, em, rem) but none of this works for my case...
Here is a schematic HTML code:
<svg id="step1">Lots of stuff</svg>
<svg id="step2">Same here</svg>
.
.
.
<svg id="step13">Some more stuff</svg>
And here are the CSS rules I use:
#step1, #step2, #step3, #step4, #step5, #step6, #step7, #step8, #step9, #step10, #step11, #step12, #step13 {
position: absolute;
top: 1vh;
left: 8.5vw;
margin: 0 auto;
visibility: hidden; /*They are hidden by default and I use JS to make them visible alternatively.*/
height: 150px;
}
Here is the webpage for the animation, the one I am talking about is the "Tetris" animation for mobile phones so maybe you'll have to resize your browser to see it well...
If anyone has an idea about how to make it responsively positioned, I'd be really thankful.
Benjamin
Have you looked at flexbox with a columnar direction? The items will stay vertically centered no matter the screen height. Also, I removed the ids, since they are no longer necessary.
const steps = document.querySelectorAll('.step');
let delay = .25;
steps.forEach(step => {
step.style.animationDelay = `${delay}s`;
delay += .25;
});
body {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
}
.step {
visibility: hidden;
opacity: 0;
border: 1px solid;
animation-name: makeVisible;
animation-duration: 1s;
animation-fill-mode: forwards;
padding: 1em;
}
#keyframes makeVisible {
to {
opacity: 1;
visibility: visible;
border-color: transparent;
}
}
<div class="step">One</div>
<div class="step">Two</div>
<div class="step">Three</div>
<div class="step">Four</div>
<div class="step">Five</div>
jsFiddle
You can use media query to resolve responsive issue. Try this i hope it'll help you out. Thanks
#media only screen and (max-width: 768px) {
.step {
position: static;
display: block;
}
}
.step {
position: absolute;
top: 1vh;
left: 8.5vw;
margin: 0 auto;
visibility: hidden; /*They are hidden by default and I use JS to make them visible alternatively.*/
height: 150px;
}
#media only screen and (max-width: 768px) {
.step {
position: static;
display: block;
}
}
<svg class="step" id="step1">Lots of stuff</svg>
<svg class="step" id="step2">Same here</svg>
.
.
.
<svg class="step" id="step13">Some more stuff</svg>
Related
I came across a problem I could not find a solution to online.
I am creating a navbar for the mobile version, and want to set a media query to make the navbar visible on smaller screen size.
After trying a lot with the visibility and display feature, I noticed that the visibility is working one way but not the other.
When I set the mobile-navbar on visible at bigger scale and invisible in smaller screen-scale, that works perfectly. Setting the navbar to be invisible on normal size and visible on the mobile screen however doesn't.
I am pretty new to this, so maybe there are some other arguments, which interfere with these attributes. Below I will place anything that is related with the class names/id.
#media only screen and (max-width: 1000px) {
.navbar-mobile-container {
visibility: hidden;
}
}
.navbar-mobile-container {
visibility: visible;
z-index: 10;
position: fixed;
bottom: 0%;
width: 100%;
height: 50px;
display: flex;
justify-content: space-between;
background-color: #04AA6D;
}
.navbar-mobile-container>button>img {
transform: scale(1.5);
}
.navbar-mobile-container>button {
background-color: transparent;
}
<body>
<div class="navbar-mobile-container">
<button><img src="./svg/svg-cah/three-dots-vertical.svg"></button>
<button><img src="./svg/svg-cah/shuffle.svg"></button>
<button><img src="./svg/svg-cah/arrow-clockwise.svg"></button>
<button><img src="./svg/svg-cah/check.svg"></button>
</div>
</body>
When working with media queries you can play around with min-width and max-width, it depends on what you're looking for.
A different thing to keep in mind, is that CSS 'reads' from top to bottom. So if you declare something at the top of your file, it can be overwritten later on in your file. In this case, when I transfer your media query to the bottom of the CSS file, it seems to work..
Order of operation...
.navbar-mobile-container {
visibility: visible;
z-index: 10;
position: fixed;
bottom: 0%;
width: 100%;
height: 50px;
display: flex;
justify-content: space-between;
background-color: #04AA6D;
}
.navbar-mobile-container>button>img {
transform: scale(1.5);
}
.navbar-mobile-container>button {
background-color: transparent;
}
#media only screen and (max-width: 1000px) {
.navbar-mobile-container {
visibility: hidden;
}
}
<body>
<div class="navbar-mobile-container">
<button><img src="./svg/svg-cah/three-dots-vertical.svg"></button>
<button><img src="./svg/svg-cah/shuffle.svg"></button>
<button><img src="./svg/svg-cah/arrow-clockwise.svg"></button>
<button><img src="./svg/svg-cah/check.svg"></button>
</div>
</body>
I have a fixed position tooltip that works in all browsers except Safari. In safari, the tooltip is being cut off by the parent's container which has properties of overflow: scroll
Any ideas on how I can fix this?
This is the screenshot of how it's supposed to look like:
This is how it looks on safari:
These are the properties for the tooltip:
.announcement {
position: fixed;
width: 3.1rem;
height: 3.1rem;
background-image: url("./../assets/icons/announcement-alert-right.svg");
background-size: cover;
margin: 0 0 0 -2.8rem;
z-index: 1;
&:hover {
margin: -3.6rem 0 0 -14.8rem;
width: 15.3rem;
height: 6.7rem;
background-image: url("./../assets/icons/announcement-profile.svg");
}
#media screen and (max-width: $desktop) {
display: none;
}
}
This is the parent's perspective:
.profile {
position: fixed;
z-index: map-get($zindex, sidebar);
right: 0;
width: 15%;
height: 100%;
transition: 0.5s;
padding: 3rem;
box-shadow: 0 1.5rem 3rem $color-shadow;
background-color: $color-white;
overflow: scroll;
-ms-overflow-style: none;
scrollbar-width: none;
&::-webkit-scrollbar {
display: none;
}
}
I've tried several different fixes such as:
-webkit-transform: translateZ(0); transform: translate3d(0, 0, 0); -webkit-transform: translate3d(0, 0, 0); z-index:9999 !important) and none of them works.
Any help would be much appreciated!
Thanks!
Without knowing your html code i speculated that the parent container and the tool tip element are not at the same level so even if you increase z-index value it won't change.
Place the element at the same level that would work.Something like this
<parent-container>
//parent content
</parent-container>
<tooltip-element>
//tooltip-content
</tooltip-element> //same level
Check the parents' properties and the overlapping element's properties. Some of them has a position or a z index value that is blocking it from your desired behavior
I bet is that maybe you will need to split up the position: fixed and overflow tags across two nested div classes in Safari? I know this could be a bit annoying and inconvenient, but then that way - I don't think that the z-index will be blocked off...
HTML:
<div class="wrapper1">
<div class="wrapper2">
<div class="inner">
/* Stuff inside here */
</div>
</div>
</div>
CSS:
.wrapper {
...
position: fixed;
...
}
.wrapper2 {
...
overflow: hidden;
position: absolute;
...
}
I wouldn't have thought that the overflow: scroll would affect any of the z-index properties but we'll see. Good luck on finding a solution, hopefully I've somewhat helped!
What the html looks like
My problem is at a large view the .hover looks fine, but when the screen is small the .hover stops being aligned how I'd like it.
How can I make the .hover look visibly better at smaller views?
You might want to check at which breakpoint your hover stops being the way you want it. You can toggle a :hover in your inspector to see at which width the hover div is not in the desired position anymore.
After you know at what width the div is misplaced, you could add media queries. In that query where you say (max-width: 1000px){} you could change the margin of the hover div.
I think what you could do is place the .hover element into the element that triggers it to show. The .hover element then needs to be positioned absolutely inside of an element that is not position:static;
The benefit of having the hover content inside of a container together with the label means that they move around together when the page gets resized.
You can change where the .hover appears based on the media query.
HTML:
<div class="container">
<div class="label">Label</div>
<div class="hover-content">This is the hover</div>
</div>
CSS:
.container {
position: absolute;
top: 100px;
left: 300px;
border: 1px solid #000;
}
.hover-content {
position: absolute;
top: 0;
left: 100%;
margin-left: 20px;
display: none;
}
.label {
padding: 10px;
}
.container:hover .hover-content {
display: block;
width: 200px;
background-color: #000;
color: #fff;
padding: 10px;
}
#media (max-width: 600px) {
.hover-content {
left: auto;
right: 100%;
margin-left: 0;
margin-right: 20px;
}
}
http://codepen.io/anon/pen/XjobdN
I'm building an web app which has a 100% height/width/fullscreen layout. I am looking for a CSS-trick to proportionally resize an elements dimensions according to its height.
Right now I am looking for an equivalent of what this trick does to the x-axis:
html, body{
height:100%;
margin:0;
}
#view {
min-height: 100%;
position: relative;
width: 100%;
background-color: #333333;
}
#test-hld {
position: absolute;
display: flex;
align-items: center;
justify-content: center;
background-color: tomato;
width: 100%;
height: 75%;
}
.test{
position: relative;
width: 30%;
}
.test:before{
content: "";
display: block;
padding-top: 75%;
}
.content{
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
background: black;
}
<div id="view">
<div id="test-hld">
<div class="test">
<div class="content"></div>
</div>
</div>
</div>
But changing (for example) .test{height: 80%} and .test:before{padding-left: 75%} makes the browser render no dimensions of the box at all.
My question(s) is
Why is the opposite not working?
Has it something fundamental to do with setting heights of elements with CSS?
Can flex/flexbox solve this?
I know it's possible to fix this with some lines of JS but I just can't believe it's not doable with CSS until someone slaps my face telling me to get real.
First of all, just to know why the padding trick works.
Padding-top and padding-bottom are vertical dimensions that are related to the width (so, an horizontal dimension) of the container.
That allows the ratio of an element to be fixed, and related to the width of the container. But there isn't any horizontal dimension that is related to some vertical of the container, so the equivalent trick over the height is not posible right now.
I have tried to get this same result using another technique, but I have had a very partial success.
My failed attempt is try to use an image to set the ratio
body, html {
height: 99%;
}
.base {
height: 40%;
border: solid 1px green;
display: inline-block;
position: relative;
}
.ratio {
content: url("http://placehold.it/400x200");
opacity: 0.05;
height: 100%;
width: auto;
position: relative;
}
<div class="base">
<img class="ratio" />
</div>
This is working in IE and Chrome, and failing in FF. But just on initial loading.
Changing the browser size won't work until the page is reloaded. I just can't figure out why, or how to solve it
I found a nice tutorial for making my images enlarge (like a zoom effect) on hover. The main difference between my needs and a tutorial is that I want my all images contained in a single box like container. So when I implemented the tutorial I realize that part of the enlarged image gets cut off when you hover. The effect is constrained to the container. I would like a way for the zoom to go wherever it needs to go on the page. (So you can see the whole zoomed image)
Here is my implementation of the tutorial: http://mulnix.contestari.com/wp/example225/1.php
JSFiddle: http://jsfiddle.net/dsRAH/
Original Code
Remove the overflow: hidden and all other overflows,
than for your images containers DIV remove float:left; and add display:inline-block;
* {
margin: 0;
box-sizing: border-box;
}
.wrapper {
position: relative;
background: #000;
color: #fff;
z-index: 0;
}
.photos {
position: relative;
display: flex;
flex-flow: row wrap;
}
.photo {
box-shadow: 0 0 0 2px #444;
margin: 5px;
position: relative;
max-height: 200px;
transform: translateZ(0);
transition: transform 0.5s;
}
.photo:hover {
z-index: 1;
transform: translateZ(0) scale(1.6);
}
.photo img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
}
.photo-legend {
position: absolute;
bottom: 0;
width: 100%;
padding: 1em;
background: rgba(0,0,0,0.3);
}
<div class="wrapper">
<div class="photos">
<div class="photo">
<img src="https://placehold.it/200x150/0bf" />
<div class="photo-legend">TEST DESCRIPTION</div>
</div>
<div class="photo">
<img src="https://placehold.it/200x200/f0b" />
</div>
<div class="photo">
<img src="https://placehold.it/200x150/bf0" />
</div>
</div>
</div>
It's not perfect but it's a start. I changed the overflow:hidden; in the wrapper to visible. I also put your code into jsfiddle so people can tinker with it.
http://jsfiddle.net/m8FXH/
You can try to use z-index. An element with greater z-index is always in front of an element with a lower z-index. If you main container is not overflow:hidden than you can try this out.
here is an example where you can see how it works. Hope that is helpful.
https://developer.mozilla.org/en-US/docs/Web/CSS/z-index
I would suggest giving your divs one of the following classes:
colleft for the ones that are at left column
colright for the ones that are at right column
rowtop for the ones at the top row
rowbottom for the ones at the bottom row
And then assign them the following properties
.colleft {
transform-origin-x: 0%;
}
....
transform-origin-x: 100%;
transform-origin-y: 0%;
transform-origin-y: 100%;
(respectively)
That will make the zoom go in the desired direction.
evan stoddard modified fiddle