Why is the last element in my flex column not aligned? - html

Here is how it looks like: https://gyazo.com/77de215669cf2d9cd3ca35a0e064c7bf
I'm not sure why the last box isn't in the center. This is my css code:
.recipe1{
display: flex;
justify-content: space-around;
align-items: center;
flex-wrap: wrap;
}
.recipe2{
border-radius: 10px;
box-shadow: 0px 5px 20px rgb(71,71,71);
margin: 20px;
display: flex;
flex-direction: column;
justify-content: space-evenly;
background: white;
align-items: center;
min-width: 50%;
}
HTML:
<div className="recipe1">
<div className="recipe2">
<h1 className="display-4 p-3">{title}</h1>
<ul> {/*Ingredients is an array of objects, so need to iterate through it with map to display*/}
{ingredients.map(ingredient => (
<li className="lead">{ingredient.text}</li>
))}
</ul>
<p>Calories: {Math.floor(calories)}g</p>
<img className={style.image} src={image} alt="Cannot display :("></img>
</div>
</div>
I'm using react and bootstrap so there's some other stuff in there that looks different.

Related

Why is a new line NOT starting after a flexbox is completed?

I'm learning how to utilize flex and just started running into issues for after the flexbox is completed...
#initial {
display: flex;
flex: 1;
justify-content: space-evenly;
align-items: center;
width: 1200px;
margin-left: auto;
margin-right: auto;
border: 1px solid white;
}
#initial .menu {
display: flex;
flex: 1;
justify-content: space-evenly;
align-items: center;
margin: 15px auto 15px auto;
width: 1100px;
border: 1px solid rgba(245, 245, 245, 0.699);
border-radius: 50px;
line-height: 2rem;
font-size: 1.1rem;
overflow: hidden;
}
#initial .menu .menuItem {
display: flex;
flex: 1;
padding-top: 10px;
padding-bottom: 10px;
width: 100%;
text-align: center;
flex-direction: column;
flex-wrap: wrap;
align-content: space-around;
justify-content: space-evenly;
}
#initial .menu .menuItem:hover {
background-color: #FDB000;
color: black;
cursor: pointer;
display: flex;
flex: 1;
text-align: center;
flex-direction: column;
flex-wrap: wrap;
align-content: space-around;
justify-content: space-evenly;
}
<div id="initial">
<div class="menu">
<div id="initialMenuHeader" class="menuItem" onclick="menuCollapsable(this)">Δ</div>
<div id="initialMenuHVQ" class="menuItem" onclick="initialHVQ()">Hivecoin</div>
<div id="initialMenuRVN" class="menuItem" onclick="initialRVN()">Ravencoin</div>
<div id="initialMenuAVN" class="menuItem" onclick="initialAVN()">Avian</div>
</div>
<div class="body">
<h1>NAME OF POOL GOES HERE</h1>
<p class="intro">¡Intro crap will go here!</p>
</div>
</div>
As it stands, my .menu looks like this. Please note that the image is uncensored and includes expletives
Everything I could find online suggests that when the flex-box is completed, it should go back to the normal flow (e.g. not floating).
Please let me know what I'm doing wrong and/or missing.
JSFiddle of my code (added some things that I didn't include above like body for background-color and color
Since you make #initial as flex, and by default flex-direction set to row your menu align with with your body. If your want menu & body in 2 lines add below css:
#initial{
flex-direction: column;
}

(S)CSS Flexbox Justify-Content: Flex End Not Applying

I am trying to achieve this (my Figma mockup):
Where as I keep getting this in my real coding (text is dummy):
This is my (S)CSS for the page:
.navbarcont {
margin-top: 2em;
display: flex;
background-color: hsl(206, 97%, 13%);
border-radius: 34px;
width: 80vw;
height: 3em;
margin-left: auto;
margin-right: auto;
.links {
display: flex;
justify-content: flex-start;
margin-left: 2em;
align-items: center;
}
ul {
display: inherit;
flex-direction: row;
flex-wrap: wrap;
gap: 1em;
}
.langcont {
display: inherit;
justify-content: flex-end;
align-items: center;
}
}
And this is my React HTML:
<div className="navbarcont">
<div className="links">
<ul> {/*TODO: Remember to put icons before the a tags! (USE BOOTSTRAP ICONS!) */}
<li>
Hello
</li>
<li>
Hello
</li>
<li>
Hello
</li>
</ul>
</div>
<div className="langcont">
<div className="langtext">
<p>Language Select</p>
</div>
</div>
</div>
I really do not know where I am going wrong, or why I cannot use justify-content: flex-end; on the langcont class.
Thanks a lot for your help.
You need an additional justify-content in the navbarcontent-class
.navbarcont {
...
justify-content: space-between;
}
This will add space between the two divs and should display your elements like intended.
You have to use justify-content: space-between property on .navbarcont
.navbarcont {
display: flex;
justify-content: space-between;
...
}

Justify-content: space-between not applying on nested flex box

I am styling a cart in angular. I am trying to get the price to be all the way to the right of the cart however it is not applying.
I tried using space-between and I tested it on the outer div and it worked, but when I try to apply on the inner div it doesn't work. What am I missing or just plain not understanding here?
here is a pen of the code
https://codepen.io/awschneider-dev/pen/rNedLJg
HTML Below
<div class="container">
<h2>Cart</h2>
<div class="cartProducts" *ngFor="let item of items">
<!-- <input type="checkbox" name="deleteItem" id=""> -->
<hr>
<div class="item">
<div class="itemImage">
<img class="productImage" src="../../assets/images/phones/{{item.image}}" alt=""/>
</div>
<div class="information">
<div class="description">
Link to Item Page
</div>
<div class="price">
{{item.price | currency}}
</div>
</div>
</div>
</div>
</div>
CSS Below
div.item{
display: flex;
}
div.information{
display: flex;
justify-content: space-between;
flex-direction: row;
}
div.container{
max-width: 1080px;
margin-left: auto;
margin-right: auto;
}
div.itemImage{
min-width: 150px;
}
img.productImage{
max-width: 100px;
max-height: 150px;
margin: 10px;
}
hr {
display: block;
margin-top: 0.5em;
margin-bottom: 0.5em;
margin-left: 1.0em;
margin-right: 1.0em;
border-style: inset;
border-width: 1px;
border: 0;
height: 1px;
background: #333;
background-image: linear-gradient(to right, #ccc, #333, #ccc);
}
a.fakeLink{
font-weight: 750;
font-size: larger;
text-decoration: none;
color: #0645AD;
}
Resources I accessed below.
How to fix flex box with justify-content space between
Justify-content: space-between works incorrect
Any and all help would be appreciated.
To make it work, you can set the width of div.information.
For example:
div.information{
display: flex;
justify-content: space-between;
flex-direction: row;
width: 100%; /* use any value you want */
}
Add the following property in your css rule:
div.information{
display: flex;
justify-content: space-between;
flex-direction: row;
flex-grow: 2; // add this line
}

align flex child at top-center and bottom-center, flexbox

I need a layout using flexbox, where 2 flex-items, item-1 should be aligned at top-center, while item-2 should be at bottom-center. I could not figure out how to do that.
See the below code:
.container{
padding:10px;
background: #fff;
border-radius:5px;
margin: 45px auto;
box-shadow: 0 1.5px 0 0 rgba(0,0,0,0,1.1);
}
.item{
color: #fff;
padding: 15px;
margin: 5px;
background: #3db5da;
border-radius: 3px;
}
.container{
display: flex;
min-height: 50vh;
justify-content: center;
align-items: center;
flex-direction: column;
}
.item{
/*margin: auto;*/
/*align-self: flex-start;*/
}
.item-4{
align-self: flex-start;
}
<div class="container">
<div class="item item-4">
Flex Item
<p>Vertical and horizontal align easy!</p>
</div>
<div class="item item-5"> bottom-center</div>
</div>
Here is fiddle link : https://jsfiddle.net/q5cw4xvy/
What you are looking for is justify-content: space-between; to align the items until the corners.
Add that to the .container and there you go.
.container{
/*justify-content: center;*/
justify-content: space-between;
}
On .item-4 you have align-self: flex-start; but you don't need that. just remove it.
https://jsfiddle.net/q5cw4xvy/2/
To better help you understand flexbox, there is a really nice css-tricks article.
Do you mean something like this?
https://jsfiddle.net/da4jdff7/1/
.container{
display: flex;
min-height: 50vh;
align-items: center;
flex-direction: column;
}
.item-5 {
margin-top: auto
}

Aligning single child elements vertically with flexbox

I'm trying to have a variable number of columns evenly spaced, which contain a variable number of child elements vertically centered. I'm almost where I want to, but if I reduce the amount of child elements to one, the vertical alignment fails (row one and five).
What am I doing wrong?
The Code (http://codepen.io/anon/pen/bpvMda):
.myView {
margin: auto;
display: flex;
flex-direction: row;
justify-content: space-around;
height: 500px;
width: 500px;
}
.wpType {
flex: 0 1 auto;
display: flex;
flex-flow: row wrap;
align-items: space-around;
align-content: center;
padding: 0;
margin: 0;
list-style: none;
border: 1px solid silver;
}
.wpType:nth-child(even){
background: blue;
}
.wpType:nth-child(odd){
background: red;
}
.wp {
flex: 0 1 auto;
padding: 5px;
width: 100px;
height: 100px;
margin: 10px;
background: white;
line-height: 100px;
color: white;
font-weight: bold;
font-size: 2em;
text-align: center;
}
<div class="myView">
<div class="wpType">
<div class="wp"></div>
</div>
<div class="wpType">
<div class="wp"></div>
<div class="wp"></div>
<div class="wp"></div>
</div>
<div class="wpType">
<div class="wp"></div>
<div class="wp"></div>
<div class="wp"></div>
</div>
<div class="wpType"><div class="wp"></div>
<div class="wp"></div></div>
<div class="wpType"><div class="wp"></div></div>
</div>
Use these properties on your parent div of all of the centered elements.
display: -webkit-flex;
display: flex;
-webkit-flex-direction: column;
flex-direction: column;
-webkit-align-items: center;
align-items: center;
-webkit-justify-content: center;
justify-content: center;
Codepen