Well, in my react app, I want multiple rows having two columns. Just like first pink picture below.
But I am getting it like this. The divs are floating on the left side only, and nothing is working.
I think there should be a solution for using in map method. react component code.
{dog.map((data) => (
<div key={data.id} className="dogs-list">
<div id={data.id} className="first-column">
<img src={dogPic} alt="dog"></img>
<h3>Dog's Name</h3>
<h3>{data.name}</h3>
</div>
</div>
))}
Nothing is working. Can anyone please help?
this is the styling of this area.
.page .dogs-list {
/* display: flex; */
color: white;
width: 100%;
}
.page .dogs-list .first-column {
width: 50%;
/* border: 2px yellow solid; */
/* display: flex;
flex-direction: column; */
float: right;
}
.dogs-list img {
height: 250px;
width: 100%;
}
.dogs-list h3 {
display: flex;
align-items: center;
justify-content: center;
padding-bottom: 10px;
font-size: 18px;
}
Looking forward!
If you do not have a given structure to follow, (there was none mentioned?) try the following.
.dogs-list {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.dog{
width: calc(50% - 4px);
background-color: beige;
border: 2px yellow solid;
display: flex;
flex-direction: column;
}
.dogs-list img {
height: 250px;
width: 100%;
}
.dogs-list h3 {
display: flex;
align-items: center;
justify-content: center;
padding-bottom: 10px;
font-size: 18px;
}
<div className='dogs-list'>
{dog.map(data => (
<div id={data.id} className='dog'>
<img src={data.dogPic} alt='dog' />
<h3> Dog 's Name</h3> <h3> {data.name} </h3>
</div>
))}
</div>
Related
Tell me how this functionality is implemented, we scroll the block (red in the screenshot) and start reducing the left button filters (green in the screenshot), in which way should I go? Maybe you have examples with code?
.wrapper {
display: flex;
height: 3rem;
width: 220px;
}
button {
display: flex;
align-items: center;
}
.tags {
overflow-x: scroll;
display: flex;
gap: 10px;
}
.tag {
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
font-weight: 700;
padding: 0 10px;
background: grey;
color: white;
}
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"/>
<div class="wrapper">
<button>
<span class="material-icons orange600">face</span>
Filter
</button>
<div class="tags">
<div class="tag">one</div>
<div class="tag">two</div>
<div class="tag">three</div>
<div class="tag">four</div>
</div>
</div>
EDIT 1: Video example https://www.veed.io/view/6599056d-4f98-4995-8a7a-d052c86812d3
I have a header-component that has a title to the left and some links to the right of the page. The size and position of these divs are (partially) responsive and I am happy with the way they move along when I resize my window. However, I would like the left div to act as a wall for the others. As in when I resize my window to really small the links will 'hit' the title and only then start wrapping into multiple lines. How can I do this?
<html>
<head>
<style>
.body {
position: fixed;
top: 0;
background-color: lightgoldenrodyellow;
box-sizing: border-box;
width: 100vw;
height: calc(2% + 75px);
z-index: 10000;
}
.titleContainer {
position: fixed;
left: 0;
display: flex;
align-items: center;
font-size: calc(18px + 0.5vw);
width: 250px;
min-width: 200px;
height: calc(2% + 75px);
transition: 0.3s;
margin-left: 10px;
}
.titleContainer:hover{
cursor: pointer;
}
#title {
margin-right: auto;
padding-left: 5px;
text-decoration: none;
font-size: 32px;
font-weight: 750;
font-family: Arial, Helvetica, sans-serif;
}
.pageLinkContainer {
position: fixed;
right: 0;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
height: calc(2% + 75px);
width: auto;
}
.pageLink {
margin-right: 10px;
margin-left: 2px;
font-size: calc(12px + 0.3vw);
}
</style>
</head>
<body>
<div className="titleContainer">
<h3><Link id="title" to="/" >TITLE</Link></h3>
</div>
<div className="pageLinkContainer">
<Link className="pageLink" to="/upload">Upload a funny Gif</Link>
<Link className="pageLink" to="/gifs"> Look at funny Gifs</Link>
<Link className="pageLink" to="/database">Database</Link>
</div>
</body>
</html>
EDIT #3:
As per Niwo's answer below, here's my current css. I use Styled Components that create a body as a wrapper around the component. I've tried to explain the flow of the page as clearly as possible. Another idea I had was to use the window.innerWidth to make the links disappear if the window is resized.
I've updated this CSS to the working answer, for anyone who cares to know. I've also added back in my styled Components (which I removed in order to remove the React from this). All credits go to Niwo of course.
CSS
//GLOBAL STYLE
const GlobalStyle = createGlobalStyle`
body {
margin: 0;
padding: 0;
background-color: rgba(0,0,50,0.3);
height: 100%;
width: 100%;
position: absolute;
}
`
//GLOBAL CONTAINER
//A WRAPPER-DIV AROUND ALL COMPONENTS
const GlobalContainer = styled.div`
{
height: 100%;
width: 100%;
position: absolute;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
`
//HEADER COMPONENT
//ANOTHER WRAPPER-DIV JUST FOR THIS COMPONENT
const HeaderStyle = styled.div`
{
position: fixed;
top: 0;
display: flex;
justify-content: space-between;
background-color: rgba(100,200,100,0.6);
width: 100vw;
height: calc(2% + 75px);
z-index: 10000;
}
.titleContainer {
display: flex;
flex-shrink: 0;
align-items: center;
font-size: calc(18px + 0.5vw);
width: 250px;
transition: 0.3s;
margin-left: 10px;
}
.titleContainer:hover{
cursor: pointer;
}
#title {
text-decoration: none;
font-size: 32px;
font-weight: 750;
font-family: Arial, Helvetica, sans-serif;
}
.pageLinkContainer {
right: 0;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
height: calc(2% + 75px);
}
.pageLink {
white-space: nowrap;
margin: 0 0.5rem;
font-size: calc(12px + 0.3vw);
}
`
HTML
<GlobalStyle />
<GlobalContainer>
<HeaderStyle>
<div className="titleContainer">
<h3><Link id="title" to="/" >Movie Scores</Link></h3>
</div>
<div className="pageLinkContainer">
<Link className="pageLink" to="/upload">Upload a funny Gif</Link>
<Link className="pageLink" to="/gifs"> Look at funny Gifs</Link>
<Link className="pageLink" to="/database">Movies We've Seen</Link>
</div>
</HeaderStyle>
</GlobalContainer>
Use flexbox to prevent other elements from overlapping
If you want the solution on fiddle, it's right here: https://jsfiddle.net/Niwo04/o1df63L2/1/
I've cleaned your code a bit up and replaced your React stuff with normal HTML (because I don't know something about React). I also did some coloring, because I thought that might make everything visually better to understand.
If you have any questions about my changes, feel free to reply on this answer ; )
body {
margin: 0;
background-color: darkgray;
}
.body {
position: fixed;
display: flex;
justify-content: space-between;
background-color: lightgoldenrodyellow;
width: 100vw;
height: 75px;
z-index: 10000;
}
.titleContainer {
display: flex;
align-items: center;
width: 250px;
background-color: red;
flex-shrink: 0;
}
.pageLinkContainer {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
background-color: blue;
}
.pageLink {
white-space: nowrap;
margin: 0 0.5rem;
}
<html>
<body>
<div class="body">
<div class="titleContainer">
<h3>TITLE</h3>
</div>
<div class="pageLinkContainer">
<a class="pageLink">Upload a funny Gif</a>
<a class="pageLink">Look at funny Gifs</a>
<a class="pageLink">Database</a>
</div>
</div>
</body>
</html>
On picture you can see thet my arrows are top:50% relative to height of slide container
[1]: https://i.stack.imgur.com/DjEZh.png
I made a quick demo on Codepen: https://codepen.io/basti-n/pen/NWNRKYX?editors=1111
<div class="main-content">
<div class="arrow-left"><</div>
<img src="https://hatrabbits.com/wp-content/uploads/2017/01/random.jpg" alt="elephant">
<div class="arrow-right">></div>
</div>
<div class="description">
<caption>Lorem Ipsum</caption>
</div>
</div>
body {
box-sizing: border-box;
height: 100vh;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
}
.container {
display: flex;
flex-flow: column;
align-items: center;
}
.main-content {
display: flex;
align-items: center;
img {
height: 300px;
width: auto;
margin: 0 10px;
}
}
.description {
margin-top: 12px;
}
I dont really know what exacly write.
I have 4 boxes with width 300px, if document width is (I dont know maybe) 600px then 2 boxes should stay at page and others should be hide.
Is there a way to make it dynamic? Maybe js or jquery? Hope you can help me with this! ^^
Here is what I have now.
HTML
<html>
<head>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>
<body>
<article class='Conteiner' id='howItWorks'>
<section class='Conteiner-Highlight howItWorks-Highlight'>Jak to działa?</section>
<section class='Steps'>
<section class='step'><div class='digit'>1</div><span class='digit-description'>Analizujemy <br> potrzeby klienta</span></section>
<section class='step_hidden'><div class='digit'>2</div><span class='digit-description'>Tworzymy <br> projekt graficzny</span></section>
<section class='step_hidden'><div class='digit'>3</div><span class='digit-description'>Przedstawiamy <br> propozycję klientowi</span></section>
<section class='step_hidden'><div class='digit'>4</div><span class='digit-description'>Przystępujemy <br> do pisania strony</span></section>
</section>
<section class='steps-Controls'>
<span class='steps_check'>
<i class='material-icons'>radio_button_checked</i>
<i class='material-icons'>radio_button_unchecked</i>
<i class='material-icons'>radio_button_unchecked</i>
<i class='material-icons'>radio_button_unchecked</i>
</span>
<span class='steps_arrows'>
<span class='step_arrow' id='step_arrow_left'><i class='material-icons'>keyboard_arrow_left</i></span>
<span class='step_arrow' id='step_arrow_right'><i class='material-icons'>keyboard_arrow_right</i></span>
</span>
</section>
</article>
</body>
</html>
SCSS
:root{
--red: rgb(231,76,77);
--white: rgb(242,241,244);
--darker-blue: rgb(14,60,91);
}
*{
margin:0;
padding: 0;
box-sizing: border-box;
}
html, body{
width: 100%;
height: 100vh;
color: #0E3C5B;
font-size: 16px;
}
/* Modern browsers */
#media screen and (min-width: 25em){
html { font-size: calc( 16px + (24 - 16) * (100vw - 400px) / (800 - 400) ); }
}
/* Safari <8 and IE <11 */
#media screen and (min-width: 25em){
html { font-size: calc( 16px + (24 - 16) * (100vw - 400px) / (800 - 400) ); }
}
#media screen and (min-width: 50em){
html { font-size: calc( 16px + (24 - 16) * (100vw - 400px) / (800 - 400) ); }
}
.Conteiner-Highlight{
width: 100%;
height: 100px;
font-family: Roboto;
font-weight: 900;
display: flex;
justify-content: center;
align-items: center;
margin: 50px auto;
font-size: 1.2rem;
}
.Conteiner{
width: 100%;
min-height: 1000px;
height: auto;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
border-bottom: 1px solid rgb(14,60,91);
}
#howItWorks{
.Steps{
width: 80%;
height: auto;
display: flex;
justify-content: center;
align-items: center;
flex-flow: row;
.step , .step_hidden{
max-width: 300px;
width: 80%;
max-height: 500px;
height: 60vh;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
box-shadow: 0px 4px 10px rgba(144,144,144,.5);
margin: 0 50px;
border-bottom: 10px solid rgb(231,76,77);
padding: 10px;
transition: all .3s ease-in-out;
opacity: 1;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
.digit{
height: 40%;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
font-size: 3rem;
font-family: Roboto;
font-weight: 900;
color: rgb(231,76,77);
}
.digit-description{
height: 30%;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
font-size: .5rem;
font-family: Raleway;
font-weight: 400;
}
}
.step_hidden{
opacity: .3;
}
.arrow{
width: 80px;
height: 80px;
display: flex;
align-items: center;
justify-content: center;
}
}
.steps-Controls{
width: 100%;
height: 100px;
display: flex;
justify-content: center;
align-items: center;
flex-flow: column;
margin: 50px 0;
.steps_arrows{
display: flex;
flex-flow: row;
margin: 10px 0;
cursor:pointer;
.step_arrow{
display: flex;
justify-content: center;
align-items: center;
width: 35px;
height: 35px;
margin: 0 10px;
background-color: var(--red);
i{
color: var(--white);
}
}
}
.steps_check{
display: flex;
flex-flow: row;
cursor:pointer;
i{
font-size: .4rem;
}
}
}
}
CodePen
There are several ways to do this.
You could just make the css-container of those elements non-wrapping, so if there isn't enough space, they are just not visisble by window-size.
In this scenario it is possible to see 2 + 1/2 Elements when you resize the window because they "disappear" gradualy.
The other solution is just to use javascript. You could write a function that is fired on each resize-event and write an if-condition where those elements' visibility is hidden when the window-size gets too small.
For both solutions there are plenty of examples and documentation out there, so i would just suggest you search for those and pick one that is easy to understand for you and fit's your situation.
edit: Since other comments on your question came up: If you only make your decision based on the whole viewport-size, then you can use #media-queries. You can't use them if you are depending not on the viewport but some outer html-element and layouting.
You can achive this by media queries. if you expand the snippet you can see all other hidden boxes.
.container{
display: flex;
flex-direction : row;
}
.container .box{
margin: 5px;
background-color : #333;
width : 50px;
height: 50px;
}
#media screen and ( max-width: 982px ) {
.container .box:not(:first-of-type){
display:none;
}
}
<div class="container">
<div class="box">
</div>
<div class="box">
</div>
<div class="box">
</div>
<div class="box">
</div>
</div>
example according to you code :
https://codepen.io/anon/pen/EeOgxE
I don't really know what exactly (to) reply ;)
You could skip script entirely and go with CSS, assuming that each box is 300px wide and 600px combined, you could do something like this:
/* Showing 2 */
#media (min-width: 600px)
{
.my-container-with-four-boxes {
width: 600px;
height: 300px;
overflow: hidden;
}
}
/* Showing 3 */
#media (min-width: 900px)
{
.my-container-with-four-boxes {
width: 900px;
height: 300px;
overflow: hidden;
}
}
/* Showing 4 */
#media (min-width: 1200px)
{
.my-container-with-four-boxes {
width: 1200px;
height: 300px;
}
}
You'd probably have to adjust the screen limitations and container sizes with padding or something else not mentioned here ;)
I have an outerWrapper, innerWrapper, and children. outerWrapper has a height of 300px, and is display: flex. innerWrapper is also display: flex, and is flex-direction: column.
When I add align-items with a value of anything but stretch to outerWrapper, the children display one long column. They ignore the 300px height. Here's an image of how it displays:
It should display like this:
Just with align-items: flex-end.
Why is this happening, and how can I use align-items: flex-end and have the children display like the second image?
JSFiddle
#outerWrapper {
height: 300px;
background-color: lightgreen;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: flex-end;
}
ul {
padding: 0;
margin: 0;
display: flex;
align-items: center;
flex-wrap: wrap;
flex-direction: column;
}
li {
list-style-type: none;
width: 100px;
height: 100px;
background-color: lightblue;
border: 1px solid;
}
<div id="outerWrapper">
<ul id="innerWrapper">
<li class="child">I'm #01</li>
<li class="child">I'm #02</li>
<li class="child">I'm #03</li>
<li class="child">I'm #04</li>
<li class="child">I'm #05</li>
</ul>
</div>
Update
The answer to this question, is to add a height of 210px to innerWrapper. But I need to get to that number using JavaScript, because the amount of boxes will be dynamic.
I tried the following code:
innerWrapper.style.height = (lastChild.offsetTop - innerWrapper.offsetTop + lastChild.offsetHeight) + 'px';
but it didn't fix it. It just made the height to: 5 * 102 (5 = number of boxes; 102 = height + border).
How can I set the correct height to innerWrapper using JavaScript? (I can't do height: 100% because I won't be able to set align-items: flex-end or center.)
JSFiddle
var innerWrapper = document.getElementById('innerWrapper');
var lastChild = innerWrapper.lastElementChild;
newHight = lastChild.offsetTop - innerWrapper.offsetTop + lastChild.offsetHeight;
innerWrapper.style.height = newHight + 'px';
#outerWrapper {
height: 300px;
background-color: lightgreen;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: flex-end;
}
ul {
padding: 0;
margin: 0;
display: flex;
align-items: center;
flex-wrap: wrap;
flex-direction: column;
/*height: 206px;*/
}
li {
list-style-type: none;
width: 100px;
height: 100px;
background-color: lightblue;
border: 1px solid;
}
<div id="outerWrapper">
<ul id="innerWrapper">
<li class="child">I'm #01</li>
<li class="child">I'm #02</li>
<li class="child">I'm #03</li>
<li class="child">I'm #04</li>
<li class="child">I'm #05</li>
</ul>
</div>
You've defined a height for #outerWrapper: height: 300px.
Just give the child – #innerWrapper – an equal height: height: 100%. Now they wrap.
Then, if you want the items positioned at the container bottom, use flex auto margins on the odd-numbered items.
Use an invisible pseudo-element to make the last odd-numbered item always align with the top row.
#outerWrapper {
height: 300px;
background-color: lightgreen;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: flex-end;
}
ul {
padding: 0;
margin: 0;
display: flex;
align-items: center;
flex-wrap: wrap;
flex-direction: column;
height: 100%; /* NEW */
}
li {
list-style-type: none;
width: 100px;
height: 100px;
background-color: lightblue;
border: 1px solid;
}
li:nth-child(odd) { margin-top: auto; } /* NEW */
ul::after {
content: ""; /* NEW */
width: 100px; /* NEW */
height: 100px; /* NEW */
border: 1px solid; /* NEW */
visibility: hidden; /* NEW */
}
<div id="outerWrapper">
<ul id="innerWrapper">
<li class="child">I'm #01</li>
<li class="child">I'm #02</li>
<li class="child">I'm #03</li>
<li class="child">I'm #04</li>
<li class="child">I'm #05</li>
</ul>
</div>
Revised Fiddle
Try adding the height of the flexbox container:
ul {
...
height: 100%;
}
Since both the outerWrapper and menu element have flex positioning, you'll have to make some adjustments to the menu elements' dimensions and alignment as well. Here's an updated fiddle with the behavior you're looking for / matches the second image:
https://jsfiddle.net/wtyqo1su/1/
#outerWrapper {
width: 100%;
height: 300px;
background-color: lightgreen;
display: flex;
justify-content: center;
align-items: center;
}
ul {
height: 250px;
width: 300px;
padding: 0;
margin: 0;
display: flex;
flex-wrap: wrap;
flex-direction: column;
align-items: center;
}
li {
list-style-type: none;
width: 100px;
height: 100px;
background-color: lightblue;
border: 1px solid;
}
I restricted the ul to a specific width / height (so the children would actually wrap as expected). Let me know if you have any questions!