I have this element that is on my login screen that I would like when the screen changes size, it holds position. Only today I test on different screen sizes, it moves. How can I make him get stuck in this position?
My code:
export const ContainerLogin = styled(Grid).attrs({
item: true,
})`
background-color: var(--white-100);
position: absolute;
z-index: 2;
left: 1242px;
width: 520px;
height: 528px;
top: 226px;
border-radius: 4px;
`;
Update:
Code:
return (
<ContainerMain >
<ContainerImagem >
<img src={backgroundFull} style={{ position: 'fixed', minWidth: '100%', minHeight: '100%', backgroundSize: 'cover', backgroundPosition: 'center', bottom: 0, left: 0, top: 0, right: 0 }} />
</ContainerImagem>
<ContainerLogin>
<motion.div
>
{children}
</motion.div>
</ContainerLogin>
</ContainerMain>
);
};
Style:
export const ContainerMain = styled(Grid).attrs({
container: true,
})`
align-items: center;
overflow: hidden;
`;
export const ContainerImagem = styled(Grid).attrs({
item: true,
})`
align-items: center;
display: flex;
`;
export const ContainerLogin = styled(Grid).attrs({
item: true,
})`
/* position: fixed; */
background-color: var(--white-100);
position: fixed;
z-index: 2;
right: 0;
width: 520px;
height: 528px;
top: 226px;
border-radius: 4px;
/* z-index: 2;
left: 1242px;
width: 520px;
height: 528px;
top: 226px;
border-radius: 4px; */
`;
Imagem result:
image example
My screen in this image is zoomed to 80%
if you go into full page view and resize the window.it will always be on the right side of the window
img {
width: 60vw;
}
.rightelem {
background-color: cyan;
position: absolute;
z-index: 2;
right: 0;
width: 220px;
height: 228px;
top: 126px;
border-radius: 4px;
}
<div>
<img src="https://images.unsplash.com/photo-1664736607930-288b58f7e720?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=764&q=80">
</div>
<div class="rightelem">
i am on the right side</div>
Related
I'm trying to convert my css to styled-components
`
.background{
width: 430px;
height: 520px;
position: absolute;
transform: translate(-50%,-50%);
left: 50%;
top: 50%;
}
.background .shape{
height: 200px;
width: 200px;
position: absolute;
border-radius: 50%;
}
.shape:first-child{
background: linear-gradient(
#1845ad,
#23a2f6
);
left: -80px;
top: -80px;
}
.shape:last-child{
background: linear-gradient(
to right,
#ff512f,
#f09819
);
right: -30px;
bottom: -80px;
}
`
In this how do I write the styled-components?
I have came across something about what I could do for first-child and last-child but even that too had mistakes.
How about this. Create separate styles for Background and Shape. Then you create a union style, where you put styles from Background and Shape + add whatever styles you want (it will override the previous styles)
const Background = styled.div`
width: 430px;
height: 520px;
position: absolute;
transform: translate(-50%, -50%);
left: 50%;
top: 50%;
`;
const Shape = styled.div`
&:first-child {
background: linear-gradient(#1845ad, #23a2f6);
left: -80px;
top: -80px;
}
&:last-child {
background: linear-gradient(to right, #ff512f, #f09819);
right: -30px;
bottom: -80px;
}
`;
const BgWithShape = styled.div`
${Background}
${Shape}
height: 200px;
width: 200px;
position: absolute;
border-radius: 50%;
`;
I am making tooltip with antd library. I wanted to change the basic styles, so I needed to override styles. Here is the code:
import * as Styled from './Tooltip.styles';
type Props = {
title: string;
children: React.ReactNode;
};
export const CustomTooltip = ({ title, children }: Props) => (
<Styled.Tooltip
visible
title={title}
getPopupContainer={(triggerNode) => triggerNode}>
{children}
</Styled.Tooltip>
);
import styled from 'styled-components';
import { Tooltip as TooltipAnt } from 'antd';
export const Tooltip = styled(TooltipAnt)`
.ant-tooltip-content {
position: relative;
overflow-x: hidden;
overflow-y: visible;
padding-bottom: 20px;
display: inline-block;
left: -35px;
top: 25px;
}
.ant-tooltip-arrow {
display: none;
}
.ant-tooltip-inner {
padding: 10px 15px;
background: white;
display: inline-block;
border-radius: 10px;
border: 3px solid #D04A02;
border-bottom-right-radius: 0;
z-index: 2;
max-width: 200px;
color: #000;
box-shadow: none;
}
.ant-tooltip-content:before {
content: '';
position: absolute;
width: 25px;
height: 25px;
background: white;
bottom: 14px;
right: -8px;
transform: rotate(25deg);
border-bottom: 3px solid #D04A02;
}
.ant-tooltip-content:after {
content: '';
width: 3px;
background: #D04A02;
height: 50%;
position: absolute;
right: -0.5px;
bottom: 12px;
}
`;
And component where I would like to call this Tooltip:
import { CustomTooltip } from 'components/Tooltip/Tooltip';
export const SomeComponent = () => {
return (
<div>
<CustomTooltip title="Home">
<p>Home</p>
</CustomTooltip>
</div>
);
};
The problem is, the tooltip is not above the children. How can I fix this?
Codesanbox: https://codesandbox.io/s/stupefied-cohen-sgxr3s?file=/src/App.tsx
I have here a problem on overlapping the button on another button.
I wanted to follow the pic I've attached below
Codesandbox CLICK HERE
const MainButton = styled.button`
border-radius: 50%;
border: 2px solid red;
position: relative;
background-color: #fff;
display: block;
width: 40px;
height: 40px;
position: relative;
margin-bottom: 0.5rem;
overflow: hidden;
& > img {
width: 100%;
height: 100%;
object-fit: contain;
}
`;
const IconButton = styled.button`
border-radius: 50%;
border: 2px solid red;
position: absolute;
background-color: #fff;
display: block;
width: 22px;
height: 22px;
position: relative;
margin-bottom: 0.5rem;
overflow: hidden;
& > img {
width: 100%;
height: 100%;
object-fit: contain;
}
`;
In order to absolutely position IconButton relative to MainButton it needs to be rendered as a child of MainButton.
<MainButton type="button">
<img
src="https://4.img-dpreview.com/files/p/E~TS590x0~articles/3925134721/0266554465.jpeg"
alt="test"
/>
<IconButton>+</IconButton>
</MainButton>
Next adjust the positioning of IconButton.
const IconButton = styled.span` // <-- use span since nesting button is invalid
background-color: #fff;
border-radius: 50%;
border: 2px solid red;
cursor: pointer;
position: absolute;
display: block;
width: 22px;
height: 22px;
line-height: 22px; // <-- center text vertically
position: relative;
margin-bottom: 0.5rem;
overflow: hidden;
left: 50%; // <-- position halfway across parent
bottom: 0; // <-- position at bottom of parent
transform: translate(-50%, -50%); // <-- translate to center button
& > img {
width: 100%;
height: 100%;
object-fit: contain;
}
`;
Remove the overflow: hidden; rule on parent MainButton.
Update
Move the image to be a background image and tweaked the positioning.
const MainButton = styled.button`
border-radius: 50%;
border: 2px solid red;
position: relative;
background-color: #fff;
background-image: ${({ src }) => `url(${src});`}
background-position: center center;
background-size: contain;
display: block;
width: 40px;
height: 40px;
position: relative;
margin-bottom: 0.5rem;
cursor: pointer;
& > img {
width: 100%;
height: 100%;
object-fit: contain;
}
`;
const IconButton = styled.div`
background-color: #fff;
border-radius: 50%;
border: 2px solid red;
cursor: pointer;
position: absolute;
display: block;
width: 22px;
height: 22px;
line-height: 22px;
position: relative;
margin-bottom: 0.5rem;
overflow: hidden;
text-align: center;
user-select: none;
left: 50%;
top: 100%;
transform: translate(-50%, -50%);
& > img {
width: 100%;
height: 100%;
object-fit: contain;
}
`;
Just learning React!
I need help with why this menu overlaps like this image show:
The red ring, images go under the Menu and there's a horizontal scrollbars but there should not be one.
See CodeSandbox
This is the wrapper for the left Menu and the right MasonryGrid.
import React from 'react'
import '../Styles//Components/Wrapper-style.scss'
import Menu from './Menu'
const Wrapper = (props) => {
return (
<div className="wrapper">
<div className="menu-container">
<Menu />
</div>
<div className="children-container">
{props.children}
</div>
</div>
)
}
export default Wrapper
And this is the SCSS for the Wrapper
.wrapper{
display: flex;
flex-direction: column;
color: white;
width: 100vw;
height: 100vh;
background-color: rgba(255, 255, 255, 0.479);
.menu-container{
width: 100%;
height: 10%;
}
.children-container{
position: relative;
height: 85%;
.content-container{
&.page-enter {
opacity: 0;
}
&.page-enter-active {
position: absolute;
left: 0;
top: 0;
width: 100%;
opacity: 1;
transition: opacity 600ms ease-in-out;
}
&.page-exit {
opacity: 1;
}
&.page-exit-active {
opacity: 0;
transition: opacity 600ms ease-in-out;
position: absolute;
left: 0;
top: 0;
width: 100%;
}
}
}
}
#media(min-width:576px){
.wrapper {
flex-direction: row;
width: 96vw;
height: 96vh;
border-radius: 5px;
.menu-container {
height: 100%;
padding: 0;
min-width: 20%;
max-width: 20%;
}
.children-container {
height: 100%;
min-width: 80%;
max-width: 80%;
}
}
}
Any ides why dies happened would be grate?
If you want to remove the horizontal scrollbar, this will help.
Please add the marked line in AlbumPage-style.scss file.
.album.content-container .album-photos-container
{
position: relative;
display: flex;
flex-flow: wrap;
justify-content: center;
overflow-x: hidden; <-------
}
I am simply trying to make this gauge smaller. When I try and do that (modify the container class) it warps the whole gauge element. I change the position to relative and the edge of the gauge seems to break. Any ideas on how to scale this without breaking the gauge? I eventually will nest this inside of a column in bootstrap and just trying to get this working on a basic level. Any advice on this css issue would be helpful
const Gauge = Vue.extend({
template: `
<div class="container">
<div class="gauge-bg"></div>
<div class="gauge-middle"></div>
<div class="gauge-overlay" :style="{ transform: rotate }"></div>
<div class="gauge-data">
<span>{{ percentage }}%</span>
</div>
</div>
`,
props: ['percentage'],
computed: {
rotate() {
const v = this.percentage * 180 / 100;
return `rotate(${v}deg)`;
} } });
new Vue({
el: '#app',
components: {
Gauge
}
});
body {
background-color: #4d4d4d;
}
.container {
width: 400px;
height: 200px;
position: absolute;
top: 0;
overflow: hidden;
}
.gauge-bg {
z-index: 1;
width: 400px;
height: 200px;
position: absolute;
background-color: #a3f6ba;
border-radius: 250px 250px 0 0;
}
.gauge-middle {
z-index: 3;
position: absolute;
background-color: #4d4d4d;
width: 250px;
height: calc(250px / 2);
top: 75px;
margin-left: 75px;
margin-right: auto;
border-radius: 250px 250px 0 0;
}
.gauge-overlay {
z-index: 2;
position: absolute;
background-color: #5df086;
width: 400px;
height: 200px;
top: 200px;
border-radius: 0 0 200px 200px;
transform-origin: center top;
}
.gauge-data {
z-index: 4;
color: #5df086;
position: absolute;
width: 400px;
bottom: 0;
text-align: center;
font-size: 24px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<gauge percentage="33"></gauge>
</div>
The quick and dirty solution is to use transform: scale():
.container {
transform: scale(.5) translateY(-100%);
transform-origin: 0 100%;
}
combined with a font-size increase (optional).
Vue.config.devtools = false;
Vue.config.productionTip = false;
const Gauge = Vue.extend({
template: `
<div class="container">
<div class="gauge-bg"></div>
<div class="gauge-middle"></div>
<div class="gauge-overlay" :style="{ transform: rotate }"></div>
<div class="gauge-data">
<span>{{ percentage }}%</span>
</div>
</div>
`,
props: ['percentage'],
computed: {
rotate() {
const v = this.percentage * 180 / 100;
return `rotate(${v}deg)`;
} } });
new Vue({
el: '#app',
components: {
Gauge
}
});
body {
background-color: #4d4d4d;
}
.container {
width: 400px;
height: 200px;
position: absolute;
top: 0;
overflow: hidden;
transform: scale(.5) translateY(-100%);
transform-origin: 0 100%;
}
.gauge-bg {
z-index: 1;
width: 400px;
height: 200px;
position: absolute;
background-color: #a3f6ba;
border-radius: 250px 250px 0 0;
}
.gauge-middle {
z-index: 3;
position: absolute;
background-color: #4d4d4d;
width: 250px;
height: calc(250px / 2);
top: 75px;
margin-left: 75px;
margin-right: auto;
border-radius: 250px 250px 0 0;
}
.gauge-overlay {
z-index: 2;
position: absolute;
background-color: #5df086;
width: 400px;
height: 200px;
top: 200px;
border-radius: 0 0 200px 200px;
transform-origin: center top;
}
.gauge-data {
z-index: 4;
color: #5df086;
position: absolute;
width: 400px;
bottom: 0;
text-align: center;
font-size: 48px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<gauge percentage="33"></gauge>
</div>
The proper solution would be to rewrite its CSS so that it takes a variable ($gaugeWidth !?) and factors in all its hard-coded sizes so it scales correctly (what the original dev should have done in the first place).