Css flex aligments issue - html

I got stuck stacking the elements inside the flex. I want these arrows to be aligned within this square as in the design image.
This is how it looks is code. It's examle of html and css file.
// This is CSS code picture were missed
.external-login {
display: flex;
flex-direction: row;
justify-content: flex-start;
margin-right: 20px;
height: 64px;
text-align: center;
padding: 21px 30.5px 21px 30px;
border-radius: 8px;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.04);
border: solid 1px #dee2eb;
background-color: #ffffff;
h3 {
color: #525458;
}
}
.row {
width: 100%;
height: auto;
display: flex;
flex-direction: column;
margin: 10px 0;
}
.google-image {
background-image: url($url);
background-repeat: no-repeat;
width: 20px;
margin-right: 15px;
}
.facebook-image {
background-image: url('https://www.flaticon.com/svg/static/icons/svg/145/145802.svg');
background-repeat: no-repeat;
width: 20px;
margin-right: 15px;
}
.carat-image {
background-image: url($url);
background-repeat: no-repeat;
width: 20px;
margin-right: 15px;
}
<!-- This is HTML code -->
<div class="row external-login">
<div class="google-image"></div>
<h3>Continue with Google</h3>
<div class="carat-image">
</div>
</div>
<div class="row external-login">
<div class="facebook-image"></div>
<h3>Continue with Facebook</h3>
<div class="carat-image">
</div>
</div>
These pictures were missed in code snippet below.
EDIT
I've changed
justify-content: flex-start;
to
justify-content: space-between;
and got like this, not bad but text is not align.

Try adding height: fit-content; and align-self: center to your .carat-image class.

Simple change will fix the issue. add
height: fit-content
align-self: center
.carat-image {
background-image: url($url);
background-repeat: no-repeat;
width: 20px;
height: fit-content;
align-self: center;
}

To vertically center the elements which are wrapped by flex div, try align-items: center. Also, to align a particular child to the right, Use justify-self: end. Use flex-direction: column to place the elements inline. To fix the width, add flex: 1 to h3
// This is CSS code picture were missed
.external-login {
display: flex;
flex-direction: row;
justify-content: flex-start;
margin-right: 20px;
height: 64px;
text-align: center;
padding: 21px 30.5px 21px 30px;
border-radius: 8px;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.04);
border: solid 1px #dee2eb;
background-color: #ffffff;
h3 {
color: #525458;
}
}
.row {
width: 100%;
height: auto;
display: flex;
align-items: center;
margin: 10px 0;
}
.google-image {
background-image: url($url);
background-repeat: no-repeat;
width: 20px;
margin-right: 15px;
}
.facebook-image {
background-image: url($url);
background-repeat: no-repeat;
width: 20px;
margin-right: 15px;
}
.carat-image {
background-image: url($url);
background-repeat: no-repeat;
width: 20px;
margin-right: 15px;
align-self: center;
justify-self: right;
flex-basis: 50px;
height: fit-content;
}
h3 {
flex:1
}
.content .row:nth-child(2) .carat-image {
background-color: red;
justify-content: flex-end;
}
.content .row:nth-child(3) .carat-image {
background-color: red;
justify-content: flex-end;
}
<!-- This is HTML code -->
<div class="row external-login">
<div class="google-image">.</div>
<h3>Continue with Google</h3>
<div class="carat-image"> ></div>
</div>
<div class="row external-login">
<div class="facebook-image"></div>
<h3>Continue with Facebook</h3>.
<div class="carat-image">></div>
</div>

Related

center div on top of img without using position

I have a main container that contains an image and a div. What I want to achieve is to center the div on top of the image without having to use absolute or relative positioning on it. How can I achieve this? Thanks in advance.
.imgCon {
display: flex;
width: 95%;
height: 95%;
margin: auto;
background-color: blue;
}
.imgCon img {
width: 95.5%;
height: 95%;
margin: auto;
border-radius: inherit;
}
.iconCon {
display: flex;
justify-content: center;
align-items: center;
width: 30%;
height: 30%;
margin: auto;
color: #ffffff;
border-radius: 50%;
background-color: #000000;
}
<div class="imgCon">
<!--center this-->
<div class="iconCon">
C
</div>
<img src="https://www.vitalground.org/wp-content/uploads/2021/11/Bart-the-Bear-II--e1637176991443.jpg" />
</div>
The only way I can think of without using absolute positioning or changing your markup is to use a CSS Grid and make both elements occupy the same cell.
.imgCon {
display: flex;
width: 95%;
height: 95%;
margin: auto;
background-color: blue;
display: grid;
}
.imgCon img {
width: 95.5%;
height: 95%;
margin: auto;
border-radius: inherit;
grid-column-start: 1;
grid-row-start: 1;
}
.iconCon {
display: flex;
justify-content: center;
align-items: center;
width: 4rem;
height: 4rem;
margin: auto;
color: #ffffff;
border-radius: 50%;
background-color: #000000;
grid-column-start: 1;
grid-row-start: 1;
}
<div class="imgCon">
<img src="https://www.vitalground.org/wp-content/uploads/2021/11/Bart-the-Bear-II--e1637176991443.jpg" />
<!--center this-->
<div class="iconCon">
C
</div>
</div>
You could use background-image property and tiny styling changes.
.imgCon {
display: flex;
justify-content: center;
align-items: center;
width: 20rem;
height: 20rem;
margin: auto;
background-color: blue;
background-image: url("https://www.vitalground.org/wp-content/uploads/2021/11/Bart-the-Bear-II--e1637176991443.jpg");
background-position: center center;
background-repeat: no-repeat;
background-size: 100% 80%;
}
.iconCon {
display: flex;
justify-content: center;
align-items: center;
width: 3rem;
height: 3rem;
margin: auto;
color: #ffffff;
border-radius: 50%;
background-color: #000000;
}
.container {
display: flex;
justify-content: center;
align-item: center;
}
<div class="imgCon">
<div class="container">
<!--center this-->
<div class="iconCon">
C
</div>
</div>
</div>

Flexbox cascading items

I have 2 flex box containers. One of these is in row for and the other is in column for. What I am need to do is to have the items be in a cascading way. All items should have the same height and width but should be leveled in different positions.
Adjusting them margin of the container and items is not working.
HTML
<div class="flex-review">
<div class="review-card"></div>
<div class="review-card"></div>
<div class="review-card"></div>
</div>
<div class="flex-container">
<div class="main-card" id="higest-card"></div>
<div class="main-card"></div>
<div class="main-card"></div>
</div>
CSS (firts part is for bottom cotainer with big items, second part is for top cotainer with small items)
.flex-container{
display: flex;
justify-content: center;
align-content: space-between;
}
.main-card{
height: 250px;
width: 400px;
background-color: antiquewhite;
box-shadow: 5px 10px 18px #b8b5b5;
border-radius: 5px;
margin-top: 400px;
margin-right: 40px;
}
.flex-review{
display: flex;
flex-direction: column;
align-items: flex-end;
}
.review-card{
height: 60px;
width: 500px;
background-color: antiquewhite;
box-shadow: 5px 10px 18px #b8b5b5;
border-radius: 5px;
margin-right: 100px;
margin-top: 50px;
}
Currently looks like this:
Is this what you're after?
I set the divs to have relative positioning, and simply moved them using right/bottom.
.flex-container{
display: flex;
justify-content: center;
align-content: space-between;
}
.main-card{
height: 250px;
width: 400px;
background-color: antiquewhite;
box-shadow: 5px 10px 18px #b8b5b5;
border-radius: 5px;
margin-top: 400px;
margin-right: 40px;
position: relative;
}
.main-card:nth-child(1) {
bottom: 100px;
}
.main-card:nth-child(2) {
bottom: 50px;
}
.flex-review{
display: flex;
flex-direction: column;
align-items: flex-end;
}
.review-card{
height: 60px;
width: 500px;
background-color: antiquewhite;
box-shadow: 5px 10px 18px #b8b5b5;
border-radius: 5px;
margin-top: 50px;
position: relative;
}
.review-card:nth-child(1) {
right: 100px;
}
.review-card:nth-child(2) {
right: 50px;
}
<div class="flex-review">
<div class="review-card"></div>
<div class="review-card"></div>
<div class="review-card"></div>
</div>
<div class="flex-container">
<div class="main-card" id="higest-card"></div>
<div class="main-card"></div>
<div class="main-card"></div>
</div>

images and buttons are not horizontally aligned

I have met some problems while doing a image-viewer project. The problem is that my buttons and the image are not following justify-content property, which they don't distributed equally inside my div block, how could it be solved? Also the image is not centered as the title does despite I set the align item property. I dow know how to fix that. I've searched over the website for solutions but none of them seems working.
Could anyone help me, please? Thanks in advance.
Here are the html and css code:
<div class="image-viewer__container">
<div class="image-viewer__title">Image Viewer</div>
<div class="image-viewer__main">
<div class="image-viewer__button"><img src="./images/back.png" id="previous" /></div>
<div class="image-viewer__display" style="background-image: url(./images/loading.gif);background-repeat: no-repeat; background-position: center;">
<img src="https://scontent.ftpe7-2.fna.fbcdn.net/v/t1.0-0/p640x640/119893827_3212042898922322_5684339818610522875_o.jpg?_nc_cat=104&_nc_sid=730e14&_nc_ohc=fGG3wRqLaLEAX8MrIY-&_nc_ht=scontent.ftpe7-2.fna&tp=6&oh=36c5e163223a1e8abca79a2b3892c915&oe=5F976AFF" id="display">
<div class="image-viewer__display-source-wrapper">
<span><a href="https://scontent.ftpe7-2.fna.fbcdn.net/v/t1.0-0/p640x640/119893827_3212042898922322_5684339818610522875_o.jpg?_nc_cat=104&_nc_sid=730e14&_nc_ohc=fGG3wRqLaLEAX8MrIY-&_nc_ht=scontent.ftpe7-2.fna&tp=6&oh=36c5e163223a1e8abca79a2b3892c915&oe=5F976AFF" target="_blank">
https://scontent.ftpe7-2.fna.fbcdn.net/v/t1.0-0/p640x640/119893827_3212042898922322_5684339818610522875_o.jpg?_nc_cat=104&_nc_sid=730e14&_nc_ohc=fGG3wRqLaLEAX8MrIY-&_nc_ht=scontent.ftpe7-2.fna&tp=6&oh=36c5e163223a1e8abca79a2b3892c915&oe=5F976AFF</a>
</span>
</div>
</div>
<div class="image-viewer__button"><img src="./images/next.png" id="next" /></div>
</div>
</div>
.image-viewer__container {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-evenly;
}
.image-viewer__title {
font-size: 5rem;
font-weight: 600;
color: #615dec;
margin: 0;
margin-top: 2rem;
}
.image-viewer__main {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
margin: auto;
}
.image-viewer__button {
display: inline;
background: none;
border: none;
border-radius: 50%;
}
.image-viewer__button img {
width: 80px;
height: 80px;
border: 1px solid transparent;
border-radius: 50%;
cursor: pointer;
}
.image-viewer__display {
position: relative;
padding: 15px;
margin: 3rem;
max-width: 80rem;
display: flex;
flex-direction: column;
flex-wrap: wrap;
align-items: center;
font-size: 0.6rem;
}
.image-viewer__display-source-wrapper {
position: absolute;
font-size: 12px;
left: 50%;
margin-right: 50%;
transform: translate(-50%, -50%);
min-width: 100em;
text-align: center;
bottom: 0;
}
#display {
object-fit: contain;
width: 50rem;
height: 30rem;
margin-bottom: 1rem;
}
#source {
display: inline;
color: black;
}
This is because you've set a fixed width to your image. By setting the main image to 100% the image will fit and fill up the remaining space so the 3 elements are always distributed equally.
main image size = full width - both your arrows
current
#display {
object-fit: contain;
width: 50rem; /*fixed width*/
height: 30rem; /*fixed width*/
margin-bottom: 1rem;
}
amended
#display {
margin-bottom: 1rem;
width: 100%; /*was added*/
height: auto; /*was added*/
}
jsFiddle
Add css float:"right" in css button.

Growing div height based on text

I am creating a card that will have an image, a title, and a button taking someone to the URL of the program. Since the title will be dynamically generated by the content, I will have no way of knowing how long the title will actually be. I want my card, specifically the card bottom, to grow to show all the text. What is the best way of achieving this??
.program{
height: 250px;
width: 200px;
background-color: red;
/* display: flex;
felx-direction: column; */
}
.program_top{
width: 100%;
height: 50%;
background-color: purple;
background-image: url('https://images.unsplash.com/photo-1581309638082-877cb8132535?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60');
background-repeat: no-repeat;
background-size: cover;
}
.program_bottom{
width: 100%;
height: 50%;
background-color: rgb(32, 32, 32);
display: flex;
flex-direction: column;
justify-content: space-around;
}
.program_title{
padding: 10px;
color: white;
}
.program_button{
text-align:center;
margin-bottom: 20px;
}
.program_button a {
color: orange;
text-decoration: none;
border: 2px solid orange;
padding: 0 30px;
border-radius: 15px
}
<div class="program">
<div class="program_top">
</div>
<div class="program_bottom">
<div class="program_title">
Security For Small Business asfdasdfasdfasdfasdfasdfasdfasdfsdfasdfasdfasdfasdfasdf
</div>
<div class="program_button">
View Program
</div>
</div>
</div>
Here is a codepen for it:
codepen
I changed your CSS to accomplish your needs. Please let me know if you need any additional help.
CSS
.program{
height: auto;
width: 200px;
background-color: red;
display: flex;
flex-direction: column;
}
.program_top{
width: 100%;
height: 125px;
background-color: purple;
background-image: url('https://images.unsplash.com/photo-1581309638082-877cb8132535?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60');
background-repeat: no-repeat;
background-size: cover;
}
.program_bottom{
width: 100%;
height: 50%;
background-color: rgb(32, 32, 32);
display: flex;
flex-direction: column;
justify-content: space-around;
}
.program_title{
padding: 10px;
color: white;
}
.program_button{
text-align: center;
margin-bottom: 20px;
}
.program_button a {
color: orange;
text-decoration: none;
border: 2px solid orange;
padding: 0 30px;
border-radius: 15px
}
On option is to fix the height and basically hide any extra content using
.program_title {
padding: 10px;
color: white;
overflow: hidden;
text-overflow: ellipsis;
}
This helps you to avoid any unexpected layout growth when the info on this container is too big.
The problem is when you need to show all this information, in this case you can provide another way to display the full text (a popup with details, mouseover hint)
.program{
height: 250px;
width: 200px;
background-color: red;
/* display: flex;
felx-direction: column; */
}
.program_top{
width: 100%;
height: 50%;
background-color: purple;
background-image: url('https://images.unsplash.com/photo-1581309638082-877cb8132535?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60');
background-repeat: no-repeat;
background-size: cover;
}
.program_bottom{
width: 100%;
height: 50%;
background-color: rgb(32, 32, 32);
display: flex;
flex-direction: column;
justify-content: space-around;
}
.program_title {
padding: 10px;
color: white;
overflow: hidden;
text-overflow: ellipsis;
}
.program_button{
text-align:center;
margin-bottom: 20px;
}
.program_button a {
color: orange;
text-decoration: none;
border: 2px solid orange;
padding: 0 30px;
border-radius: 15px
}
<div class="program">
<div class="program_top">
</div>
<div class="program_bottom">
<div class="program_title">
Security For Small Business asfdasdfasdfasdfasdfasdfasdfasdfsdfasdfasdfasdfasdfasdf
</div>
<div class="program_button">
View Program
</div>
</div>
</div>

Resize and center align an icon inside a circle

I have a list of network icons I am trying to show them in a circle with a white background. Here is what I have right now. I am trying to get the icon to fit into the circle .
.logo {
display: -ms-flexbox;
-ms-flex-align: center;
-ms-justify-content: center;
display: flex;
align-items: center;
overflow: hidden;
color: #1e1e1e;
width: 100%;
height: 100%;
max-height: 88px;
max-width: 88px;
margin: 0 auto;
background: url('/networks/network-logo-bg#2x.png') center center no-repeat;
background-size: contain;
img {
width: 80%;
font-size: 10px;
font-weight: 700;
text-align: center;
color: #000;
margin: 0 auto;
#include lazyLoad(null);
}
}
HTML:
<div key={index} className="logo">
<img className="lazyload" src={logo.icon} alt={logo.name}/>
</div>
I want the icon to be inside the circle and aligned to the center.
You can try something like this:
HTML:
<div class="circle">
<img src="https://image.flaticon.com/icons/svg/826/826356.svg">
</div>
CSS:
.circle {
width: 200px;
height: 200px;
border-radius: 50%;
background-color: black;
display: flex;
justify-content: center;
}
img {
width: 50%;
}
Demo