I've have problem with showing images on my project. I would like to show image when I hover text. It's working correctly if using Chrome but at least in Safari image stays partly hidden inside it's parent element.
Screenshot from Chrome
Screenshot from Safari
Code for parent element:
const PortfolioItemsWrapper = styled.div`
width: 100%;
max-width: 960px;
position: fixed;
bottom: 0;
overflow-x: scroll;
white-space: nowrap;
display: block;
text-align: center;
justify-content: center;
`
<PortfolioItemsWrapper>
{props.allWordpressWpPortfolio.edges.map(portfolioItem => (
<PortfolioWorks
key={portfolioItem.node.id}
image={portfolioItem.node.featured_media.source_url}
id={portfolioItem.node.id}
title={portfolioItem.node.title}
link={`/portfolio/${portfolioItem.node.slug}`}
/>
))}
</PortfolioItemsWrapper>
Code for image:
const Wrapper = styled.div`
display: inline-block;
margin: 0 10px;
`
const ImageWrapper = styled.div`
max-width: 300px;
position: fixed;
top: 50%;
left: 50%;
`
const PortfolioImage = styled.img`
max-width: 300px;
z-index: -5;
opacity: 0;
transition: 0.25s linear;
`
<Wrapper key={id}>
<ImageWrapper>
<PortfolioImage style={imageStyle} src={image} />
</ImageWrapper>
<PortfolioItemNameLink to={link} onMouseEnter={changeStyle} onMouseLeave={resetStyle}>
{title}
</PortfolioItemNameLink>
</Wrapper>
Although I'm not sure this might work:
Try adding overflow-y: visible; to your parents css.
Let me know if that works :)
I got this right by just pretty randomly testing things. Don't know why but it's working. If someone knows why I would like to know.
I set fixed position for parent div of PortfolioItemsWrapper.
const Wrapper = styled.div`
width: 100%;
max-width: 960px;
position: fixed;
bottom: 0;
`
const PortfolioItemsWrapper = styled.div`
width: 100%;
max-width: 960px;
white-space: nowrap;
overflow-y: visible;
overflow-x: scroll;
display: block;
text-align: center;
justify-content: center;
`
Related
I have a few styled components - a container, an image and a div for text to overlay the image. Currently, I have the text centered and vertically aligned with the image, but because I added display: flex; with justify-content: center; and align-items: center; longer words no longer break within the div. How can I accomplish this with or without flexbox?
What it properly looks like positioned without the need to break words:
company 1 no breaking, no need
Unexpected Behavior / What it looks like with the need to break words:
company 2 still no breaking
Styled Components:
const ProfilePicContainer = styled.div`
position: relative;
display: inline-block;
text-align: center;
color: #fff;
`
const ProfilePicText = styled.div`
position: absolute;
height: 80px;
width: 90px;
top: -25%;
left: 35%;
min-width: 90px;
font-size: clamp(1.15em, 3vw, 1em);
line-height: 100%;
overflow-wrap: break-word!important;
word-wrap: break-all!important;
display: inline-block;
vertical-align: middle;
& div {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
overflow-wrap: break-word!important;
word-wrap: break-all!important;
display: flex;
justify-content: center;
align-items: center;
}
`
const CompanyProfilePic = styled.img.attrs({ src: `${imgBlank}` })`
position: relative;
left: 30px;
top: -30px;
margin-bottom: -10px;
#media (max-width: 767px) {
width: auto;
};
`
JSX:
export default function Intro({ company, isExpanded, mainWidth }) {
return (
<Wrapper>
<Banner>
<BannerImg background={company.banner} />
<ProfilePicContainer>
<CompanyProfilePic />
<ProfilePicText><div>{company.name}</div></ProfilePicText>
</ProfilePicContainer>
</Banner>
...
</Wrapper>
)
}
I'm trying to shrink down an iframe that contains one of my other websites, but I want to maintain the scale and center it. Right now I have the scaling part figured out, but I can't seem to get it centered.
I've tried flex with justify-items: center & align-items: center on its parent, but it stays glued to the top left. I've also tried margin: auto which does nothing, but when I add margin-left it moves over a bit. If the parent has 100% width, and there is margin available, why wouldn't margin: auto center it? I'm confused.
Here's the html/jsx:
import './Desktop.css';
import desktopMockup from '../../assets/desktop.png';
const Desktop = ({ site }) => {
const
return (
<div className="desktop">
<div className="iframeDesktop">
<iframe src={site} scrolling="no" title="desktop" width="1920" height="1080"></iframe>
</div>
{/* <img src={desktopMockup} alt="desktop mockup" /> */}
</div>
);
};
export default Desktop;
And here's the css:
.desktop {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-items: center;
align-items: center;
}
.iframeDesktop {
position: relative;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-items:center;
}
iframe {
position: absolute;
top: 0;
right: 0;
left: 0;
bottom: 0;
transform: scale(0.17);
transform-origin: top left;
min-width: 1920px;
min-height: 1080px;
}
I wonder if you could use transform-origin: top center; instead of transform-origin: top left;. Could you give that a try?
So, i'm trying to get my left div to be the same height as the right div, just let me show the code ( i did in react.js ) and the styles
This is the structure
<FlexBoxModal>
<FlexBoxMPhoto onClick={e => e.stopPropagation()}>
<img src={sp.photo} />
</FlexBoxMPhoto>
<FlexBoxMComments
onClick={e => e.stopPropagation()}
></FlexBoxMComments>
</FlexBoxModal>
My styles
export const FlexBoxModal = styles.div`
max-width: 70%;
min-width: 50%;
height: 605px;
margin: auto;
margin-top: 3rem;
margin-bottom: 4rem;
overflow-y: hidden;
overflow-x: auto;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
background: red;
`;
export const FlexBoxMPhoto = styles.div`
flex: 1.25;
display: flex;
align-items: center;
justify-content: flex-end;
img{
max-width: 100%;
min-width: 70%;
min-height: 300px;
max-height: 605px;
object-fit: cover;
}
`;
export const FlexBoxMComments = styles.div`
flex: .75;
width: 100%;
min-height: 300px;
max-height: 605px;
background: white;
`;
The Problem : i've thinking how to can i make this work, but i really don't know where to start, i fixed mi left div so i can position the img between a min-size and max-size, but, how can i make mi right div follow the height of my left div ? Let me show you this output
Test
What i want : So, as you can see, the white div isn't the same height ad the other one, how can i make that happen? both with same height?
Thanks !
The FlexBoxModal container that you have has align-items set to center. Switch that to stretch. That's the container that controls both the children.
I got the following structure:
<header></header>
<main>
<card />
</main>
<footer></footer>
header {
height: 70px;
top: 0;
left: auto;
right: 0;
position: sticky;
width: 100%;
display: flex;
z-index: 1100;
box-sizing: border-box;
flex-shrink: 0;
flex-direction: column;
}
main {
height: calc(100vh - 130px);
display: grid;
place-items: center;
max-width: 600px;
padding-left: 24px;
padding-right: 24px;
width: 100%;
box-sizing: border-box;
margin-left: auto;
margin-right: auto;
}
card {
width: 100%;
padding: 40px 25px;
}
footer {
top: auto;
width: 100%;
bottom: 0;
height: 60px;
display: flex;
position: fixed;
justify-content: center;
}
The card actually is a login form with two inputs and has to be in the center of the screen. I used the main to wrap and center it. But now the problem is that on horizontal orientation and when the height is reduced to some pxs it is not possible to see the whole card. Part of it is covered by the footer. Any idea how I can center it and scrolling to be possible.
Here is my sandbox: https://codesandbox.io/s/recursing-meitner-ocgz9
add this to you'r body maybe youre problem solve
body {
min-height:100vh;
}
if you place it to a code pen, would be easier to help you.
I can only assume that if you change main to the below it might help:
main {
height: calc(100vh - 130px);
display: flex;
place-items: center;
max-width: 600px;
padding-left: 24px;
padding-right: 24px;
width: 100%;
box-sizing: border-box;
margin-left: auto;
margin-right: auto;
background: red;
}
Also check you have body { margin: 0 }. As browsers adds margin automatically, so your 100% layout does have extra height.
from the main container remove the height and add margin-bottom equals to the height of the footer.
paperContainer: {
display: "grid",
placeItems: "center",
marginBottom:'60px'
}
And to avoid some styling issues regarding height, add min-height if required.
Codesandbox demo
Got a very simple solution!!
paper: {
width: "100%",
borderRadius: "8px",
padding: "40px 25px",
paddingBottom: "100px"
},
just give the paddingBottom to the paper, you can also use it conditionally if the user is using mobile and the width of the view > height of the view. It looks fine without that too.
Check this out!!
sandbox link
let me know if you still have an issue.
I have a weird problem, I am pretty bad with CSS therefor I come up with this exercise where I want to build a image slider, which is inside a div called slider-div with width of 1000px, from a array, 10 images are loaded into the div and only 5 are visible so the user have to scroll.
To learn more I added two buttons which should scroll 100px (left or right),
I have a problem with those buttons, they stick to the parent slider-div / Background. I hoped they would always stay on the top and don't move. User can decide to scroll to the end or hit the buttons.
I am using display: flex; flex-direction: row; to get the images into a row.
How can I fix button to the visible edge of a div?
Only solution I worked out is:
position: fixed;
right: 33.6%;
but it is very unprofessional :( also bad when I changing the layout somewhere else.
Can you please look over and tell me where the mistake is what is missing?
Here is the link to codepen:
https://codepen.io/miomate/pen/pBQBya
Code:
.div-1 {
max-width: 1000px;
height: 200px;
overflow-x: scroll;
overflow-y: hidden;
position: absolute;
}
button{
/* position: absolute; */
top:35%;
}
.images {
display: flex;
flex-direction: row;
list-style: none;
margin: 0;
padding: 0;
}
.x {
position: absolute;
top: 30%;
}
.div-2-1{
}
.div-2-2{
right: 0;
}
The images aren't loaded but the result ist the same.
Thank you very much.
This is my solution using the "bottom" property of css.
body {margin: 0 0 0 0;}
.div-1 {
max-width: 1000px;
height: 300px;
overflow-x: scroll;
overflow-y: hidden;
position: relative;
}
.images {
display: flex;
flex-direction: row;
list-style: none;
margin: 0;
padding: 0;
}
.x {
position: absolute;
bottom: 0;
}
.div-2-1{
left:0;
}
.div-2-2{
right: 0;
}