"Flex-box: row" CSS rule not working as expected - html

My flex row won't work and I don't know why. I've tried everything. I need the images to be three in a row then break and start a new row. How can I overcome this issue?
.flex-div > div {
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-content: space-between;
}
/*kitchen hacks*/
#kitchen-hacks {
padding-top: 80px;
}
.row-one {
width: 100%;
}
#kitchen-hacks h2 {
text-align: center;
margin-bottom: 15px;
border: solid black;
border-radius: 10px;
}
#kitchen-hacks p {
height: auto;
width: 54%;
margin-top: 5px;
margin-bottom: 50px;
border: solid black;
}
<div class="flex-div">
<div id="kitchen-hacks">
<h2 id="hacks"> Kitchen Hacks</h2>
<div class="row-one" style="order: 4"> <img src="/assets/images/kitchen-hack.one.png" alt="Chalk board on the inside of a shelf with mesuring cups hanong from it"> <p> Place a chalkboard and hangers on the inside of your kitchen shelf to store measuring cups the fashion way. </p> </div>
<div class="row-one" style="order: 2"><img src="/assets/images/kitchen-hack-two.png" alt="A shelf inside a shelf with plates on it"> <p> Store shelves in your shelves to optimize spacce and to better take advantage of the empty space not used. </p> </div>
<div class="row-one" style="order: 3"><img src="/assets/images/kitchen-hack-three.png" alt="Coffe pouring into an ice tray">
<p>Fill an ice tray with coffee so that you can enjoy your coffee without watering it down. </p> </div>
<div class="row-one" style="order: 1"> <img src="/assets/images/kitchen-hack-four.png" alt="Spices attached to the fridge with magnets"> <p> Put magnets under your spices to make them stick to the fridge. That way you can multitask</p>
</div>
<div class="row-one" style="order: 5"><img src="/assets/images/kitchen-hack-five.png" alt="Kitchen sink area"> <p> Using your sink as a temporary chopping surface frees the rest of your counter for other cooking steps. </p> </div>
<div class="row-one" style="order: 6"><img src="/assets/images/kitchen-hack-six.png" alt="An egg in a glass of water and two eggs beside the glass">
<p> Fill a tall glass of water and lower an egg in it. If it sinks to the bottom, the egg is fresh. If it floats to the top, it’s time to toss it </p> </div>
</div>
</div>

Make a parent container that will contain all the images you want in a row and use flex properties.
e.g:
.row-one, .row-two{
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
<div class="row-one">
<span>Image 1</span>
<span>Image 2</span>
<span>Image 3</span>
</div>
<br>
<br>
<div class="row-two">
<span>Image 4</span>
<span>Image 5</span>
<span>Image 6</span>
</div>

Try Grids; it is much better to display galleries.
But in this scenario with flex elements, I would use the following approach:
.flex-div{
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.flex-div > .image{
width: 30%;
display: flex;
align-items: center;
flex-direction: column;
justify-content: space-around;
background-color: magenta;
}
<div class="flex-div">
<div class="image">
<img src="custom image" alt="custom image" loading="lazy">
<p>Some text</p>
</div>
<div class="image">
<img src="custom image" alt="custom image" loading="lazy">
<p>Some text</p>
</div>
<div class="image">
<img src="custom image" alt="custom image" loading="lazy">
<p>Some text</p>
</div>
</div>
Codepen: https://codepen.io/rohhthone/pen/wvjVBWy
This video shows how to create a grid media scroller, which might be useful to you.

Related

Why aren't all the product cards within the list wrapper?

Question is straightforward. Why aren't the product cards "flowing" to the right? The second product card isn't within the list-wrapper.
Extra question (maybe related): is there anything wrong with my choice of where to put my divs?
.list-wrapper {
display: inline-flex;
flex-wrap: wrap;
left-margin: 5em;
border: 2px solid grey;
justify-content: space-evenly;
width: 100%;
}
.product-card {
display: flex;
border: 1px dotted grey;
margin: 20px 10px 20px 10px;
padding: 5px;
width: 30%;
height: 200px;
}
<div>
<div class="list-wrapper">
<div class="product-card">
<ol>
<div class="wrapper">
<div class="product-name">Product Name</div>
<div class="product-basic-description">Comes in many colors and sizes</div>
<div class=product-price>300.00 $</div>
<div class=product-image><img src="" alt="{{ image-description }}"></div>
</div>
</div>
</div>
<div class="product-card">
<div class="wrapper">
<div class="product-name">Product Name</div>
<div class="product-basic-description">Comes in many colors and sizes</div>
<div class=product-price>300.00 $</div>
<div class=product-image><img src="" alt="{{ image-description }}"></div>
</div>
</div>
</div>
</ol>
</div>
</div>
I believe there are some nesting errors in your html.
The <ol> right in product-card is never properly closed and the last three closing tags (</ol> and 2x </div>) are loose and dont have a opening counterpart.
In addition you're defining an ordered list using <ol> but never use the list-item tags inside (<li>). See this on details but heres how list markup in general should look:
<ol>
<li>Mix flour, baking powder, sugar, and salt.</li>
<li>In another bowl, mix eggs, milk, and oil.</li>
<li>Stir both mixtures together.</li>
<li>Fill muffin tray 3/4 full.</li>
<li>Bake for 20 minutes.</li>
</ol>
(Source: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ol)
As it seems the ol element isnt neccessary for what youre trying to achieve, therefore i removed it.
Also i fixed the nesting and moved the second product-card element inside the list-wrapper element too.
.list-wrapper {
display: inline-flex;
flex-wrap: wrap;
left-margin: 5em;
border: 2px solid grey;
justify-content: space-evenly;
width: 100%;
}
.product-card {
display: flex;
border: 1px dotted grey;
margin: 20px 10px 20px 10px;
padding: 5px;
width: 30%;
height: 200px;
}
<div>
<div class="list-wrapper">
<div class="product-card">
<div class="wrapper">
<div class="product-name">Product Name</div>
<div class="product-basic-description">Comes in many colors and sizes</div>
<div class=product-price>300.00 $</div>
<div class=product-image><img src="" alt="{{ image-description }}"></div>
</div>
</div>
<div class="product-card">
<div class="wrapper">
<div class="product-name">Product Name</div>
<div class="product-basic-description">Comes in many colors and sizes</div>
<div class=product-price>300.00 $</div>
<div class=product-image><img src="" alt="{{ image-description }}"></div>
</div>
</div>
</div>
</div>

How do i organize flex items properly?

The issue I am facing is not that big of a problem but it could potentially ruin the look of my page. The problem is I have a div card that is a flex object i.e it's parent div has its display set to flex
.season-list{
display: flex;
flex-wrap: wrap;
justify-content: space-evenly;
flex-direction: row;
}
<div class="season-list container">
<div class="card">
<img class="image" src="some.jpg" alt="">
<div class="overlay">
<div class="text">
<small>Some text</small><br>
<small>something else</small>
<br>
<small class="tempt">something;</small>
</div>
</div>
</div>
</div>
Now what happens is that setting justify-content as space-evenly does organize the card object properly i.e three in a row, however, when i have lets say 7 cards, it organizes the first three normally but ends up aligning the last card in the bottom-centre of the previous row. I have tried messing around with different justify-content values but to no avail. Like i said this is not a big problem but could make the page look a little less pleasing to the eye.
You could switch to the grid display to avoid this :
example with a card of 250px (update this value to your needs)
.season-list {
display: grid;
grid-template-columns: repeat(auto-fit, 200px);
justify-content: space-evenly;
gap: 1em;
}
<div class="season-list container">
<div class="card ">
<img class="image " src="https://picsum.photos/id/1011/200/100" alt="">
<div class="overlay">
<div class="text">
<small>Some text</small><br>
<small>something else</small>
<br>
<small class="tempt">something;</small>
</div>
</div>
</div>
<div class="card ">
<img class="image " src="https://picsum.photos/id/1011/200/100" alt="">
<div class="overlay">
<div class="text">
<small>Some text</small><br>
<small>something else</small>
<br>
<small class="tempt">something;</small>
</div>
</div>
</div>
<div class="card ">
<img class="image " src="https://picsum.photos/id/1011/200/100" alt="">
<div class="overlay">
<div class="text">
<small>Some text</small><br>
<small>something else</small>
<br>
<small class="tempt">something;</small>
</div>
</div>
</div>
</div>
Play in full screen to check its behavior or play with the codepen : https://codepen.io/gc-nomade/pen/BapgbYx (added a few examples borders to the card and grid-auto-rows to set each rows the same height.)
enter image description here
I think this is exactly what you're looking for
.season-list {
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
flex-direction: row;
}
.card {
background-color: rgb(247, 56, 56);
color: rgb(255, 255, 255);
width: 10rem;
height: 10rem;
margin: 3rem;
display: flex;
justify-content: center;
align-items: center;
}

How can I align span text with text in other columns?

I have a row with six columns of image and text here: https://i.imgur.com/UKGGCrX.png
I want to align the two-line text (e.g. Resources and Reserves) with "Exploration" and "Geological Data". https://i.imgur.com/Tplzivb.png
Adding a margin below the image doesn't do the trick, nor does adding a margin above the text... also tried setting a min-height for the icon, but that doesn't do it either.
How can I accomplish this?
Using flexbox you can easily align your text on "top".
This is default flexbox behaviour and does align your text on "baseline":
.container{
display: flex;
flex-flow: row nowarp;
}
.text{
max-width: 30px;
}
<html>
<div class="container">
<div class="imgt">
<img src="https://dummyimage.com/20x20">
<div>Some Text</div>
</div>
<div class="imgt">
<img src="https://dummyimage.com/20x20">
<div class="text">Some Long long Text</div>
</div>
</div>
</html>
I assume you have a margin-top: auto; and margin-bottom: auto;, or some flexbox properties like align-items: center; somewhere, that your text gets centered inside the div.
You can use flex styles to obtain your desired results. I created an example showing how the align-items: stretch; property will help with keeping icons/images/and content aligned with siblings.
Live example: https://codepen.io/SROwl/pen/xNrRmw
HTML:
<h3> align content top </h3>
<div class="bucket-row">
<div class="bucket">
<img src="https://dummyimage.com/85x85">
<span>Single Line</span>
</div>
<div class="bucket">
<img src="https://dummyimage.com/85x85">
<span>Double Line Title</span>
</div>
<div class="bucket">
<img src="https://dummyimage.com/85x85">
<span>Double Line Title</span>
</div>
<div class="bucket">
<img src="https://dummyimage.com/85x85">
<span>Single Line</span>
</div>
<div class="bucket">
<img src="https://dummyimage.com/85x85">
<span>Triplen Extra Line Title</span>
</div>
<div class="bucket">
<img src="https://dummyimage.com/85x85">
<span>Double Line Title</span>
</div>
</div>
<h3> align content bottom </h3>
<div class="bucket-row content-end">
<div class="bucket">
<img src="https://dummyimage.com/85x85">
<span>Single Line</span>
</div>
<div class="bucket">
<img src="https://dummyimage.com/85x85">
<span>Double Line Title</span>
</div>
<div class="bucket">
<img src="https://dummyimage.com/85x85">
<span>Double Line Title</span>
</div>
<div class="bucket">
<img src="https://dummyimage.com/85x85">
<span>Single Line</span>
</div>
<div class="bucket">
<img src="https://dummyimage.com/85x85">
<span>Triplen Extra Line Title</span>
</div>
<div class="bucket">
<img src="https://dummyimage.com/85x85">
<span>Double Line Title</span>
</div>
</div>
SCSS:
body {
font-family: sans-serif;
}
.bucket-row {
display: flex;
flex-direction: row;
align-items: stretch;
justify-content: space-between;
width: 600px;
margin-bottom: 40px;
.bucket {
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
max-width: 85px;
background-color: #eee;
padding-bottom: 20px;
img {
margin-bottom: 15px;
}
}
&.content-end {
.bucket {
span {
margin-top: auto;
}
}
}
}

CSS float right weird behaviour

I have 2 threads in an imageboard stacked on top of each other, each thread has some text and an image file.
I want images to be always on right of the thread, instead of being on top of reply button.
When I float image to right by float: right; the images keep stacking on top of each other instead and form a branch like structure
How do I force images with post-image class to not break <div> structure of following thread and stay on right of screen?
<div class="you" id="thread_27" data-board="b" align="Right">
<div class="files">
<div class="file">
<p class="fileinfo">File: 1454704253855.jpg <span class="unimportant">(78.69 KB, 1024x768, <span class="postfilename">soft-color-background.jpg</span>)</span>
</p>
<img class="post-image" src="/b/thumb/1454704253855.png" style="width: 255px; height: 192px; max-width: 98%;" alt="">
</div>
</div>
<div class="post op" id="op_27">
<p class="intro">
<input class="delete" name="delete_27" id="delete_27" type="checkbox">
<label for="delete_27"><span class="name">Anonymous (You)</span>
<time data-local="true" datetime="2016-02-05T20:30:54Z">02/05/16 (Fri) 22:30:54</time>
</label> <a class="post_no" id="post_no_27" onclick="highlightReply(27)" href="/b/res/27.html#27">No.</a><a class="post_no" onclick="citeReply(27)" href="/b/res/27.html#q27">27</a>[Reply]</p>
<div class="body">xxxxxx2</div>
</div>
<br class="clear">
<hr>
</div>
<div class="you" id="thread_26" data-board="b" align="Right">
<div class="files">
<div class="file">
<p class="fileinfo">File: 1454704190918.jpg <span class="unimportant">(157.33 KB, 1024x768, <span class="postfilename" title="mac-style-presentation-background.jpg">mac-style-presentation-bac….jpg</span>)</span>
</p>
<img class="post-image" src="/b/thumb/1454704190918.png" style="width: 255px; height: 192px; max-width: 98%;" alt="">
</div>
</div>
<div class="post op" id="op_26">
<p class="intro">
<input class="delete" name="delete_26" id="delete_26" type="checkbox">
<label for="delete_26"><span class="name">Anonymous (You)</span>
<time data-local="true" datetime="2016-02-05T20:29:51Z">02/05/16 (Fri) 22:29:51</time>
</label> <a class="post_no" id="post_no_26" onclick="highlightReply(26)" href="/b/res/26.html#26">No.</a><a class="post_no" onclick="citeReply(26)" href="/b/res/26.html#q26">26</a>[Reply]</p>
<div class="body">xxxxx</div>
</div>
<br class="clear">
<hr>
</div>
when I add CSS
.post-image
{
float: right;
}
it breaks everything.
jsfiddle before
js fiddle after floating post-image to the right
This happens because of float left or right. clear controls the float behavior hence, the ideal way is to make all the float properties inside a container usually div. Sometimes, browser renders it differently so whenever coming to a new container or sibling, ideal way is to clear the float(if you don't need the floating property).
In your code you could probably
Add this:
.clear{
clear:both;
}
to better understand. Also don't forget to play with it to put it ideally where it is required.
If you can use flexbox (no way to old browsers) try something like:
.row{
display: flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: flex-start;
align-content: stretch;
align-items: flex-start;
}
.col1{
position: relative;
flex: 1 1 100%;
align-self: stretch;
overflow: hidden;
}
.col2{
position: relative;
display: flex;
flex-direction: column;
flex: 0 1 45px;
align-self: stretch;
}
on a html strukture like
<div class="row">
<div class="col1">
</div>
<div class="col2">
</div>
</div>
Add one more div with "clear: both" styling will fix your problem.
<div class="file">
your code here...
<div style="clear:both"></div>
</div>
jsfiddle

Flexbox alignment with images and text inside same container

I am making a flexbox Employee ID card layout. The employee's picture will go to the left and the employee's info (name, employee-id, department, etc) will go to the right of the image in a list format top-to-bottom.
I need to do this using flexbox.
Here is a link to my JSFiddle with what I have done so far:
http://jsfiddle.net/Hopped_Up_Designs/3teLbqqf
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-flex-direction: row;
flex-direction: row;
-webkit-align-items: center;
align-items: center;
flex-wrap: wrap;
min-width: 320px;
max-width: 1220px;
}
.flex-item {
height: 120px;
width: 300px;
background-color: #e46119;
border: 1px solid #626262;
margin: 3px;
padding: 10px 0 0 10px;
}
span {
padding-left: 5px;
}
<div class="flex-container">
<div class="flex-item"><img src="http://placehold.it/100x100">
<span>Text fields will go here</span>
</div>
<div class="flex-item"><img src="http://placehold.it/100x100">
<span>Text fields will go here</span>
</div>
<div class="flex-item"><img src="http://placehold.it/100x100">
<span>Text fields will go here</span>
</div>
<div class="flex-item"><img src="http://placehold.it/100x100">
<span>Text fields will go here</span>
</div>
<div class="flex-item"><img src="http://placehold.it/100x100">
<span>Text fields will go here</span>
</div>
<div class="flex-item"><img src="http://placehold.it/100x100">
<span>Text fields will go here</span>
</div>
<div class="flex-item"><img src="http://placehold.it/100x100">
<span>Text fields will go here</span>
</div>
<div class="flex-item"><img src="http://placehold.it/100x100">
<span>Text fields will go here</span>
</div>
<div class="flex-item"><img src="http://placehold.it/100x100">
<span>Text fields will go here</span>
</div>
</div>
Any and all help would be much appreciated. Thanks, Jason
The most unobtrusive approach which I found was to add this:
.flex-item {
display:flex;
align-items: center;
}
.flex-item img{
flex-grow:0;
flex-shrink:0;
}
If you add multiple <span> immediately after the img, they'll continue displaying in row fashion (like a float). This may not be the what you want, though. One option could be to set each item to a fixed width - but that breaks the spirit of flexbox.
But if you modify your text wrapper to contain a single <div>, I think you'll be fine. The <div> will display as a block level element until you choose otherwise.
<div class="flex-item">
<img src="http://placehold.it/100x100">
<div>
<ul>
<li>Text fields will go here</li>
<li>and here</li>
</ul>
</div>
</div>
Here's a fork of your fiddle where I did this. http://jsfiddle.net/Paceaux/7fcqkb50/1/
Just wrap your info in a container set to display: inline-block:
HTML
<div class="flex-item">
<img src="http://placehold.it/100x100"/>
<div class="info-container">
<p>Field 1</p>
<p>Field 2</p>
<p>Field 3</p>
</div>
</div>
CSS
.info-container{
display: inline-block;
vertical-align: top;
padding: 0 0 0 5px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.info-container p{
padding: 0;
margin: 0 0 10px;
}
FIDDLE