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>
)
}
Related
When I press the "push me" button, the green cover is down to the third item. However, there is still space after scrolling down. I need to cover the entire height of div (it is better to use the pseudo-element "after"). How I can do it?
.cover:after {
padding: 0;
position: absolute;
display: flex;
justify-content: center;
align-items: center;
top: 0;
z-index: 99;
height: 100%;
width: 100%;
content: "Cover, cover, cover";
background: green url("src/img.svg") no-repeat 50% 33%;
font-weight: 600;
font-size: 18px;
text-align: center;
color: white;
}
Full code: https://codepen.io/Roman-H91/pen/eYroQPq
You can add the property overflow:clip to keep all the height
.cover {
overflow:clip;
}
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;
`
I have markup like so:
HTML:
<ListElementRoot>
<ListElementText>
{children}
</ListElementText>
<ListElementDescription>
{description}
</ListElementDescription>
</ListElementRoot>
//platform.web.js
export const ListElementRoot = div(style.root)
export const ListElementIcon = div(style.icon)
export const ListElementText = div(style.text)
export const ListElementDescription = div(style.description)
//CSS
.root {
display: flex;
width: 100%;
height: 56px;
align-items: center;
border-top: 1px solid var(--color-gray2);
padding: 0;
}
.icon {
position: absolute;
width: 28px;
height: 28px;
align-items: center;
padding-left: 18px;
}
.text {
color: #000;
font-size: calc(var(--font-size-body) / 10)rem;
padding-left: 64px;
}
.description {
color: #000;
font-size: calc(var(--font-size-body) / 12.3)rem;
padding-left: 64px;
}
I'm new to flexbox.
How can I make element just under ?
I'm trying to find a solution but it is heavily twisted in flexbox for me (for now). Any ideas?
EDIT:
Without flex-direction: column;
With flex-direction: column;
You need to have a flex-direction property set to column for your flex container (.root).
Here you can find a jsfiddle example.
EDIT:
Change align-items: center to be align-items: flex-start in order to have the elements align to the left
I had a webpage that I split into sections, each section with it's own content. Unfortunately i needed it to be responsive, so i gave the body element a display: flex style. sect-1 and sect-2 were children of the body, so they are stacking, as expected. The issue is the content inside the flex items was being positioned absolutely, however now it is no longer being positioned from the sect-1 and sect-2, and now the whole page. Why does absolute positioning ignore flex item parents, and what can i do to position the children of the flex objects?
The HTML :
<body>
<div id="sect-1">
<h2 id="quote">I AM A WEB DESIGNER_</h2>
</div>
</body>
The container css :
body {
display: flex;
flex-direction: column;
overflow-x: hidden;
}
The first flex object :
#sect-1 {
background: none;
width: 100vw;
height: 100vh;
left: 0vw;
z-index: 98;
}
And the object I need positioning inside the flex object (not container) :
#quote {
align-content: left;
font-family: Courier New;
color: black;
font-size: 25px;
letter-spacing: 5px;
line-height: 0px;
width: 500px;
position: absolute;
top: calc(50vh - 12.5px);
left: calc(50vw - 190px);
}
For the quote to position itself inside the flex item sect-1, the sect-1 need to have a position other than static, normally relative is what one use.
body {
display: flex;
flex-direction: column;
overflow-x: hidden;
}
#sect-1 {
position: relative; /* added */
background: none;
width: 100vw;
height: 100vh;
left: 0vw;
z-index: 98;
}
#quote {
align-content: left;
font-family: Courier New;
color: black;
font-size: 25px;
letter-spacing: 5px;
line-height: 0px;
width: 500px;
position: absolute;
top: calc(50vh - 12.5px);
left: calc(50vw - 190px);
}
<body>
<div id="sect-1">
<h2 id="quote">I AM A WEB DESIGNER_</h2>
</div>
</body>
I have a
#menu {
width: calc(100vw - 60px);
left: 30px;
}
How can the words be justified in the available space?
I'm tryin the
text-align:justify
but it doesn't work.
https://jsfiddle.net/ju0mz9t0/1/
I assume you mean the text. This is because text-align: justify doesn't justify the last line of a block of text. One workaround is to add a css generated content item that acts like an inline text item but stretches the full width of the container like so:
#menu:after {
content: '';
display:inline-block;
width: 100%;
}
#menu{
font-family: Arial;
font-size:22px;
width: calc(100vw - 60px);
left: 30px;
text-align: justify;
text-justify: inter-word;
position:fixed;
}
#menu:after {
content: '';
display:inline-block;
width: 100%;
}
<div id="menu">
SS17 FW16/17 ABOUT STOCKISTS
</div>
Do you mean something like this?
This solution uses display: flex and it's property justify-content: space-between;
Read more about flexbox here
#menu {
display: flex;
font-family: Arial;
font-size: 22px;
width: calc(100vw - 60px);
left: 30px;
text-align: justify;
text-justify: inter-word;
position: fixed;
justify-content: space-between;
}
<div id="menu">
<span>SS17</span><span>FW16/17</span><span>ABOUT</span><span>STOCKISTS</span>
</div>