Div passing full width of parent div - css

Hello I have a daughter div that is passing the full width of the parent div for some reason I still can't find the solution:
like this:
for some reason instead of skipping paragraph it is always horizontal I've tried everything and found no solution.
code:
<Styled.ChatBox>
<Styled.ChatLog>
<Styled.MessageWrapper user={true}>
<Styled.ChatMessage user={true}>{props.children}</Styled.ChatMessage>
</Styled.MessageWrapper>
</Styled.ChatLog>
</Styled.ChatBox>
css:
const messageBot = css`
align-self: flex-start;
background-color: #e0e0e0;
color: black;
border-radius: 8px;
padding: 10px 10px 10px 15px;
font-size: 15px;
font-family: sans-serif;
`;
const messageClient = css`
align-self: flex-end;
background-color: #1a6fe8;
color: white;
border-radius: 8px;
padding: 10px 10px 10px 15px;
font-size: 15px;
font-family: sans-serif;
`;
const ChatBox = styled.div`
display: ${props => (props.widget ? 'none' : 'flex')};
position: absolute;
position: fixed;
right: 20px;
bottom: 20px;
flex-direction: column;
max-width: 22em;
width: 100%;
height: 30em;
border-radius: 6px;
box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 10px 2px;
background: ${props => (props.widget ? 'red' : 'blue')};
`;
const ChatLog = styled.div`
display: flex;
flex-direction: column;
max-height: 400px;
width: 100%;
overflow-y: auto;
flex: 1 100%;
background: red;
padding: 10px 10px 0px 10px;
box-sizing: border-box;
`;
const MessageWrapper = styled.div`
background: yellow;
display: flex;
align-items: center;
flex-direction: row;
box-sizing: border-box;
width: 100%;
justify-content: ${props => (props.user ? 'flex-end' : 'flex-start')};
`;
const ChatMessage = styled.div`
position: relative;
margin: 1ex;
padding: 1ex;
border-radius: 2px;
:before {
content: '';
position: absolute;
top: 50%;
right: ${props => (props.user ? '-5px' : '')};
left: ${props => (props.user ? '' : '1px')};
height: 15px;
width: 15px;
background: ${props => (props.user ? '#1a6fe8' : '#e0e0e0')};
transform: rotate(45deg);
transform-origin: top right;
}
${props => (props.user ? messageClient : messageBot)}
`;
I know that my div that is passing the size is ChatMessage
I believe she is the problem
img:
example on:
https://codesandbox.io/s/cool-water-1dwqx

You need to handle the overflow of the element.
const ChatMessage = styled.div`
...
overflow: hidden;
word-break: break-all;
`;

Related

Cannot hide images under fixed div

Images are visible from underneath fixed div and I cannot hide them. Tried with z-index but didn't rly work. It looks like only image is visible from underneath since div in which these images are mapped cannot be seen. What is causing the problem?
styles of component with fixed div (MenuPopUp)
export const MenuWrapper = styled.div``;
export const IconWrapper = styled.div<{
isActive: boolean;
isDarkMode: boolean;
}>`
height: 40px;
width: 40px;
display: flex;
align-items: center;
justify-content: center;
background-color: ${(props) =>
guessIconBgColor(props.isActive, props.isDarkMode)};
border-radius: 50%;
cursor: pointer;
&:hover {
background-color: ${pallete.DarkerGray};
}
svg {
height: 20px;
color: ${(props) => guessIconColor(props.isActive, props.isDarkMode)};
}
`;
export const MenuPopUp = styled.div`
position: fixed;
width: 675px;
height: 672px;
right: 16px;
background-color: ${pallete.LightGray};
border-radius: 0 0 4px;
-webkit-box-shadow: 6px 6px 15px -7px rgba(66, 68, 90, 1);
-moz-box-shadow: 6px 6px 15px -7px rgba(66, 68, 90, 1);
box-shadow: 6px 6px 15px -7px rgba(66, 68, 90, 1);
`;
styles of images
export const UserStoryWrapper = styled.div`
position: relative;
display: flex;
align-items: center;
justify-content: center;
flex: 1;
height: 100%;
border-radius: 8px;
overflow: hidden;
`;
export const Image = styled.img<{ isOverlay: boolean }>`
height: 100%;
width: 100%;
scale: ${(props) => (props.isOverlay ? "1.05" : "1")};
transition: 0.3s ease-in-out;
`;
export const Overlay = styled.div<{ isOverlay: boolean }>`
position: absolute;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0);
opacity: ${(props) => (props.isOverlay ? "0.3" : "0")};
cursor: pointer;
`;
styles of images container
export const UserStoriesWrapper = styled.div`
display: flex;
flex-direction: row;
align-items: center;
gap: 8px;
height: 200px;
`;

Search bar won't stay at top with CSS position: sticky property

I am trying to make a search bar stay at the top of a div with position: sticky but the property doesnt seem to work. Googling it, I see that overflow: hidden and overflow: hidden on a parent element can make it unresponsive if there is no height specified but I have a height specified so I don't think that's it. Here is the relevant CSS:
.container {
background-color: white;
box-shadow: rgba(100, 100, 111, 0.2) 0px 7px 29px 0px;
border-radius: 1rem;
height: 85vh;
width: 60vw;
overflow-y: scroll;
overflow-x: hidden;
margin: auto;
}
.search-bar {
position: sticky;
top: 0;
margin: 1rem 1rem;
padding: 0.5rem;
font-size: 20px;
width: 100%;
display: block;
outline: 0;
border-width: 0 0 2px;
}
Note that .search-bar is a child element of .container. If needed, here is the JSX file (it's a react app):
import React, { useState, useEffect } from 'react';
import { average } from './utils/util.js';
import Card from './components/Card/Card';
import './App.css';
function App() {
const [loading, setLoading] = useState(true);
const [query, setQuery] = useState({ name: '', tag: '' });
const [users, setUsers] = useState([]);
const [filteredUsers, setFilteredUsers] = useState([]);
return (
<div className='container'>
<input
className='search-bar'
placeholder='Search by name'
onChange={(e) => {
setQuery({ ...query, name: e.target.value });
}}
/>
<input
className='search-bar'
placeholder='Search by tag'
onChange={(e) => {
setQuery({ ...query, tag: e.target.value });
}}
/>
{filteredUsers.map((user) => (
<Card
id={user.id}
pic={user.pic}
name={`${user.firstName} ${user.lastName}`}
email={user.email}
company={user.company}
skill={user.skill}
average={average(user.grades)}
grades={user.grades}
tags={user.tags}
onTagChange={tagChange}
/>
))}
</div>
);
}
export default App;
I tried to reproduce your issue here,
https://codesandbox.io/s/winter-breeze-5spod8?file=/src/styles.css
but it seems to work fine with your code. The only thing I changed was to add two .search-bar classes and height into it, because you have two input elements which you want sticky and they start to overlap on each other when we start scrolling.
.container {
background-color: white;
box-shadow: rgba(100, 100, 111, 0.2) 0px 7px 29px 0px;
border-radius: 1rem;
height: 85vh;
width: 60vw;
overflow-y: scroll;
overflow-x: hidden;
margin: auto;
}
.search-bar1 {
position: sticky;
top: 0;
margin: 1rem 1rem;
padding: 0.5rem;
font-size: 20px;
width: 100%;
height: 3%;
display: block;
outline: 0;
border-width: 0 0 2px;
}
.search-bar2 {
position: sticky;
top: 5.8%;
margin: 1rem 1rem;
padding: 0.5rem;
font-size: 20px;
width: 100%;
height: 3%;
display: block;
outline: 0;
border-width: 0 0 2px;
}

How to make close effect after clicking on close in Styled-components?

I'm trying to make an in and out animation for my comment -
import {
Popup,
Overlay,
NavBarPopupHeader,
NavBarPopupContainer,
NavBarPopupImg,
NavBarPopupClose,
NavBarPopupContent,
NavBarPopupTitle,
NavBarPopupInfo,
NavBarPopupContentImg,
NavBarPopupFooter,
NavBarPopupSignOut,
} from "./styled.js";
function NavBarPopup(props) {
const { isPopupOpen } = props;
return (
<Overlay>
<Popup active={false}>
<NavBarPopupHeader>
<NavBarPopupClose
src="./popup_close.svg"
alt="close"
onClick={() => isPopupOpen(false)}
active={true}
/>
<NavBarPopupContainer>
<NavBarPopupImg />
</NavBarPopupContainer>
</NavBarPopupHeader>
<NavBarPopupContent>
<NavBarPopupTitle>You are logged as</NavBarPopupTitle>
<NavBarPopupInfo>'UserName'</NavBarPopupInfo>
<NavBarPopupInfo>'Email'</NavBarPopupInfo>
<NavBarPopupContentImg src="./popup_img.png" />
</NavBarPopupContent>
<NavBarPopupFooter>
<NavBarPopupSignOut>Sign Out...</NavBarPopupSignOut>
</NavBarPopupFooter>
</Popup>
</Overlay>
);
}
export default NavBarPopup;
I am using styled-components :
import styled, { keyframes, css } from "styled-components";
import { fadeIn, bounceInRight, bounceInLeft } from 'react-animations';
const fader = keyframes`${fadeIn}`;
const bounceIn = keyframes`${bounceInRight}`;
const bounceOut = keyframes`${bounceInLeft}`;
const Popup = styled.div`
position: fixed;
top: 0;
right: 0;
height: 100vh;
width: 400px;
background-color: #ffffff;
transition: ${(active) =>
active
? css`
${bounceIn} 0.5s linear
`
: css`${bounceOut} 0.5s`};
`;
const Overlay = styled.div`
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100vh;
background-color: rgba(0, 0, 0, 0.8);
animation: 0.2s ${fader};
`;
const NavBarPopupHeader = styled.div`
width: 100%;
height: 15%;
background-color: #000000;
`;
const NavBarPopupContainer = styled.p`
text-align: center;
margin: 0;
padding: 30px 0 0 0;
`;
const NavBarPopupImg = styled.img`
width: 80px;
height: 80px;
border-radius: 50px;
border: none;
background-color: white;
color: black;
font-size: 25px;
`;
const NavBarPopupClose = styled.img`
position: absolute;
top: 5px;
left: 5px;
cursor: pointer;
`;
const NavBarPopupContent = styled.div`
height: 75%;
`;
const NavBarPopupTitle = styled.h3`
margin:0;
padding: 10px 0 10px 0;
text-align: center;
font-size: 30px;
`
const NavBarPopupInfo = styled.h4`
width: 80%;
margin: 10px auto;
padding:5px;
text-align: center;
font-size: 25px;
background-color: black;
color:white;
border-radius: 15px;
`
const NavBarPopupContentImg = styled.img`
width:100%;
margin-top:90px;
`
const NavBarPopupFooter = styled.div`
width: 100%;
height: 10%;
background-color: #000000;
`;
const NavBarPopupSignOut = styled.p`
width:200px;
text-align: center;
margin: 0 auto;
padding: 15px 0 0 0;
font-weight: 700;
font-size: 32px;
color: white;
text-decoration: underline;
cursor: pointer;
`;
export {
Popup,
Overlay,
NavBarPopupHeader,
NavBarPopupContainer,
NavBarPopupImg,
NavBarPopupClose,
NavBarPopupContent,
NavBarPopupTitle,
NavBarPopupInfo,
NavBarPopupContentImg,
NavBarPopupFooter,
NavBarPopupSignOut
};
I want my popup to be animated with $bounceIn when it appears, and disappear with $bounceOut when it closes. I tried to do it by passing an attribute to styled-components but now it only works when my Popup appears. Perhaps I chose the wrong approach, in which case please guide me in the right direction.

Parent with height: self doesn't have children's height

Hello I have a parent with positon absolut and height: self that is not with the height of children like this:
css:
const UserProfile = styled.div`
display: flex;
justify-content: center;
align-items: center;
padding: 0 0.5rem;
cursor: pointer;
position: relative;
& .user_text {
cursor: pointer;
display: flex !important;
flex-direction: column;
padding-right: 0.75rem !important;
span:first-of-type {
font-size: 1rem;
color: #b5b5c3 !important;
font-weight: 500 !important;
text-align: right !important;
}
span:last-of-type {
font-size: 1rem;
color: #464e5f !important;
font-weight: 600 !important;
text-align: right !important;
}
}
& .user_avatar {
border-radius: 50%;
flex-shrink: 0;
position: relative;
transition: border-color 0.2s;
width: 45px;
z-index: 1;
img {
min-height: 100%;
object-fit: cover;
-o-object-fit: cover;
width: 100%;
}
}
`;
const UserCanvas = styled.div`
position: absolute;
min-width: 10rem;
display: ${props => (props.isOpen ? "block" : "none")};
border: 1px solid rgba(0, 0, 0, 0.15);
border-color: rgba(120, 130, 140, 0.13);
box-shadow: 0 3px 12px rgba(0, 0, 0, 0.05);
top: 100%;
bottom: 0;
font-size: 1rem;
color: #212529;
background-color: #fff;
background-clip: padding-box;
border-radius: 0.25rem;
& .test {
min-width: 10rem;
height: 200px;
}
`;
jsx:
<UserProfile onClick={() => setOpen(!isOpen)}>
<div className="user_text">
<span>SpiriT</span>
<span>Web Developer</span>
</div>
<div className="user_avatar">
<img src={LogoImage} />
</div>
<UserCanvas isOpen={isOpen}>
<div className="test">a</div>
</UserCanvas>
</UserProfile>
example:
https://codesandbox.io/s/youthful-hooks-ceo85?file=/src/App.js:743-2099
basically i need the div with position absolute and height auto to follow the height of yours children
Change the display to table for the parent component and table-row t like this:
const UserCanvas = styled.div`
// ... other properties
display: ${props => (props.isOpen ? "table" : "none")};
& .test {
min-width: 10rem;
height: auto;
display: table-row;
}
`;
Alternately, you can add height: max-content; to the Parent Component.

React native, how to make a shape

i'm trying to made this in react native,
I tried to had a square and an oval, i tried to have border radius in a singular square, but everytime i cannot reach this result.
This is what i tried, but as i said i don't know how to reach this
export const StyledText = styled.Text`
text-align: center;
font-family: ${FONTS.fontFamily.bold};
font-size: 29px;
color: white;
`;
export const StyledContainer = styled.View`
align-items: center;
justify-content: center;
height: 250px;
`;
export const StyledOval = styled.View`
width: 110%;
height: 150px;
border-radius: 100-5;
border-width: 10;
background-color: red;
border-color: black;
position: absolute;
top: 50;
z-index: 10;
`;
export const StyledSquare = styled.View`
flex: 1;
align-content: center;
justify-content: center;
width: 100%;
height: 100px;
background-color: red;
position: absolute;
top: 0;
z-index: 11;
`;

Resources