HTML template with flexbox - html

I would like to succeed in doing this using flexbox, I have already tried something but without success.
You have to put the title, the price and the input in flex-direction column, right?
Css
.container {
display: flex;
flex-direction: column;
width: 80%;
margin: auto;
}
.details {
flex-grow: 2;
}
.center {
text-align: center;
}
.quantity {
display: flex;
justify-content: center;
}
.quantity button {
width: 20px;
height: 20px;
border: none;
border-radius: 0;
}
.quantity input {
width: 20px;
text-align: center;
border: none;
}
<div class="container">
<h2>Mon Panier</h2>
<div>
<div class="details">
<img src="https://aaaestrie.ca/wp-content/uploads/2017/10/livres.jpg" width="150">
<span>title</span>
<span>39 €</span>
<div class="quantity">
<button class="btn-minus">-</button>
<input type="text" id="quantity" value="1">
<button class="btn-plus">+</button>
</div>
</div>
</div>
</div>
expected template

Is this you are trying to get? It's not quite you showed in the image but it's near.
Let me know if it doesn't work for you.
.container {
display: flex;
flex-direction: column;
width: 80%;
margin: auto;
}
.details {
flex-grow: 2;
}
.center {
text-align: center;
}
.quantity {
display: flex;
justify-content: center;
}
.quantity button {
width: 20px;
height: 20px;
border: none;
border-radius: 0;
}
.quantity input {
width: 20px;
text-align: center;
border: none;
}
.details span:nth-child(2) {
position: absolute;
margin-left: 10px;
font-size: 1.3rem;
}
.details span:nth-child(3) {
display: inline;
float: right;
}
.container {
background-color: lightcoral;
}
.details img {
border: 2px solid gray;
padding: 20px;
}
.inc-dec {
border: 1px solid black;
display: flex;
/* transform: translate(-100%,-100%); */
}
<div class="container">
<h2>Mon Panier</h2>
<div>
<hr>
<div class="details">
<img src="https://aaaestrie.ca/wp-content/uploads/2017/10/livres.jpg" width="150">
<span>title</span>
<span>39 €</span>
<div class="quantity">
<div class="inc-dec">
<button class="btn-minus">-</button>
<input type="text" id="quantity" value="1">
<button class="btn-plus">+</button>
</div>
</div>
</div>
</div>
</div>

you added "Angular" tag to your question so I assume you are using Angular.
if that's the case I highly recommend to use the npm package angular-flex-layout so you don't need to write so much CSS.
import the angular-flex-layout module in your app and watch the magic :)
<div>
<h2>Mon Panier</h2>
<div>
<hr>
<div>
<img src="https://aaaestrie.ca/wp-content/uploads/2017/10/livres.jpg" width="150">
// magic starts here
<div
fxLayout="column"
fxLayoutAlign="center center"
fxLayoutGap=".5rem"
>
<span>title</span>
<span>39 €</span>
<div class="inc-dec">
<button class="btn-minus">-</button>
<input type="text" id="quantity" value="1">
<button class="btn-plus">+</button>
</div>
</div> // magic ends here
</div>
</div>
</div>

Related

How to move up this picture next to the text "EMAIL :"

I want to move the photo to top of the site and next to the text: "EMAIL :" Create a BITLAB NEWS layout web page using HTML + CSS
.top-bar {
background-color: #00008B;
color: white;
display: flex;
justify-content: space-between;
padding: 10px;
}
.top-bar .left {
color: white;
font-weight: bold;
font-size: 20px;
}
.top-bar .right {
color: white;
}
.login-bar {
display: flex;
justify-content: flex-start;
padding: 10px;
}
.login-bar .left {
color: black;
}
.input {
padding-left: 10px;
margin-bottom: 20px;
}
.password-bar {
display: flex;
justify-content: flex-start;
}
.password-bar .left {
color: black;
padding-left: 10px;
}
.input2 {
padding-left: 10px;
padding-top: 10px;
}
.button {
background-color: green;
margin-top: 20px;
margin-left: 10px;
color: white;
width: 60px;
border-radius: 5px;
height: 15px;
font-size: 12px;
text-align: center;
padding: 10px;
}
.blue {
color: #0000FF;
}
.center {
float: left;
width: 33.33%;
padding: 5px;
margin-left: 300px;
margin-bottom: 800px;
}
<div class="top-bar">
<div class="left">BITLAB NEWS</div>
<div class="right">About Contacts FAQ Login </div>
</div>
<body>
<div class="login-bar">
<div class="left">EMAIL :</div>
</div>
<div class="input"><input type="text" placeholder="Insert Email" style="width:200px; height: 25px;">
</div>
<div class="password-bar">
<div class="left">PASSWORD :</div>
</div>
<div class="input2"><input type="text" placeholder="Insert Password" style="width:200px; height: 25px;">
</div>
<div class="button">
<div class="signin-btn">SIGN IN</div>
</div>
<p> I want to create <span class="blue">new account</span></p>
<div class="center">
<p>Boeing 777: Dozens grounded after Denver engine failure</p>
<img src="3a.jpg" style="width: 100%;">
</div>
</body>
Try using a flexbox
.top-bar {
background-color: #00008B;
color: white;
display: flex;
justify-content: space-between;
padding: 10px;
}
.top-bar .left {
color: white;
font-weight: bold;
font-size: 20px;
}
.top-bar .right {
color: white;
}
.login-bar {
display: flex;
justify-content: flex-start;
padding: 10px;
}
.login-bar .left {
color: black;
}
.input {
padding-left: 10px;
margin-bottom: 20px;
}
.password-bar {
display: flex;
justify-content: flex-start;
}
.password-bar .left {
color: black;
padding-left: 10px;
}
.input2 {
padding-left: 10px;
padding-top: 10px;
}
.button {
background-color: green;
margin-top: 20px;
margin-left: 10px;
color: white;
width: 60px;
border-radius: 5px;
height: 15px;
font-size: 12px;
text-align: center;
padding: 10px;
}
.blue {
color: #0000FF;
}
.login-flex{
display: flex;
}
<body>
<div class="top-bar">
<div class="left">BITLAB NEWS</div>
<div class="right">About Contacts FAQ Login </div>
</div>
<div class="login-flex">
<div class="login-container">
<div class="login-bar">
<div class="left">EMAIL :</div>
</div>
<div class="input"><input type="text" placeholder="Insert Email" style="width:200px; height: 25px;">
</div>
<div class="password-bar">
<div class="left">PASSWORD :</div>
</div>
<div class="input2"><input type="text" placeholder="Insert Password" style="width:200px; height: 25px;">
</div>
<div class="button">
<div class="signin-btn">SIGN IN</div>
</div>
<p> I want to create <span class="blue">new account</span></p>
</div>
<div class="right-side">
<p>Boeing 777: Dozens grounded after Denver engine failure</p>
<img src="3a.jpg" style="width: 100%;">
</div>
</div>
</body>
I'm not quite sure of the positioning you want, but you can easily obtain your result by using display: flex
You can check some documentation about it here on css-tricks and practice with this quick mini game
flexboxfroggy so that you can obtain the result you want.
.top-bar {
background-color: #00008B;
color: white;
display: flex;
justify-content: space-between;
padding: 10px;
}
.top-bar .left {
color: white;
font-weight: bold;
font-size: 20px;
}
.top-bar .right {
color: white;
}
.login-bar {
display: flex;
width: 90%;
justify-content: space-between;
align-items: flex-start;
flex-direction: row;
padding: 10px;
}
.login-bar .left {
color: black;
}
.input {
padding-left: 10px;
margin-bottom: 20px;
}
.password-bar {
display: flex;
justify-content: flex-start;
}
.password-bar .left {
color: black;
padding-left: 10px;
}
.input2 {
padding-left: 10px;
padding-top: 10px;
}
.button {
background-color: green;
margin-top: 20px;
margin-left: 10px;
color: white;
width: 60px;
border-radius: 5px;
height: 15px;
font-size: 12px;
text-align: center;
padding: 10px;
}
.blue {
color: #0000FF;
}
<div class="top-bar">
<div class="left">BITLAB NEWS</div>
<div class="right">About Contacts FAQ
Login </div>
</div>
<body>
<div class="login-bar">
<div>
<div class="left">EMAIL :</div>
<div class="input"><input type="text" placeholder="Insert Email" style="width:200px; height: 25px;">
</div>
<div class="password-bar">
<div class="left">PASSWORD :</div>
</div>
<div class="input2"><input type="text" placeholder="Insert Password" style="width:200px; height: 25px;">
</div>
<div class="button">
<div class="signin-btn">SIGN IN</div>
</div>
<p> I want to create <span class="blue">new account</span></p>
</div>
<div>
<p>Boeing 777: Dozens grounded after Denver engine failure</p>
<img src="https://nationwideradiojm.com/wp-content/uploads/2021/02/Capture-2.jpg" style="width: 120px;">
</div>
</div>
</body>

How to fix a footer which was designed using flexbox

I'm trying to clone the Google home page and I designed the footer using flexbox, but now I can't position it at the bottom of the page. How can I fix that or is there any other technique to tackle this problem.
Here is the screenshot and code of the page. I know it's messy and lack of design. First I just want to get the structure right.
screenshot of the page
```html
<body>
<div class="heading">
<div></div>
<div class="gmail">
<p>Gmail</p>
</div>
<div class="images">
<p>images</p>
</div>
<div class="gapps">
<button></button>
</div>
<div class="dp">
<p>dp</p>
</div>
</div>
<div class="container">
<div class="google-logo">
<img
src="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"
alt="Google logo"
/>
</div>
<div class="search-bar">
<input
type="search"
name="q"
aria-label="Search through site content"
/>
</div>
<div class="search-buttons">
<div class="search-button">
<button>Google Search</button>
</div>
<div class="feeling-lucky">
<button>I'm Feeling Lucky</button>
</div>
</div>
</div>
<div class="footer">
<div class="srilanka">
<p>Sri Lanka</p>
</div>
<div class="footer-bottom">
<div class="footer-bottom-left">
<div class="about">
<p>About</p>
</div>
<div class="advertising">
<p>Advertising</p>
</div>
<div class="business">
<p>Business</p>
</div>
<div class="how-search-works">
<p>How Search Works</p>
</div>
</div>
<div class="footer-bottom-right">
<div class="privacy">
<p>Privacy</p>
</div>
<div class="terms">
<p>Terms</p>
</div>
<div class="settings">
<p>Settings</p>
</div>
</div>
</div>
</div>
</body>
```
```css
body {
height: 100%;
}
body {
font-size: 14px;
font-family: arial, sans-serif;
color: #222;
}
.heading {
display: flex;
justify-content: flex-end;
padding-bottom: 100px;
}
.gmail {
padding: 0 15px;
}
.images {
padding: 0 15px;
}
.gapps {
padding: 0 15px;
}
.dp {
padding: 0 15px;
}
.container {
display: flex;
flex-direction: column;
align-items: center;
}
.google-logo {
padding-bottom: 3vh;
}
.search-bar {
padding-bottom: 3vh;
}
.search-buttons {
display: flex;
justify-content: center;
}
.feeling-lucky {
padding-left: 2vh;
}
.footer {
display: flex;
flex-direction: column;
}
.footer-bottom {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.footer-bottom-left {
display: flex;
}
.srilanka {
padding: 0 15px;
}
.about {
padding: 0 15px;
}
.advertising {
padding: 0 15px;
}
.business {
padding: 0 15px;
}
.how-search-works {
padding: 0 15px;
}
.privacy {
padding: 0 15px;
}
.terms {
padding: 0 15px;
}
.settings {
padding: 0 15px;
}
.footer-bottom-right {
display: flex;
justify-items: flex-end;
}
```
Come on broh, add a lil bit of semantics there
<html>
<head></head>
<body>
<header></header>
<main></main>
<footer class=“footer”></footer>
</body>
It doesn’t matter if you use: flex, flow, grid
as those properties are defined with display. If you want to set your element at the bottom, we are talking about a position.
So you need to set its position
.footer {
position: fixed;
left:0;
bottom:0;
width:100%;
}
It's better to post your code as well, not just a screenshot.
btw you can use the following code on your footer and it will stick to the bottom of your page
footer{
position:fixed;
bottom: 0
width: 100%
}

How can I make these radiobuttons clickable in CSS/HTML?

How can I make these radio buttons responsive? I'm not sure what I'm doing wrong. I'd like to be able to click the grid item each option is in and have it behave like a radio button, but I'm not sure what I'm missing. Any recommendations for streamlining this code would also be extremely helpful. Thanks!
body {
font-family: Arial, Helvetica;
font-size: 3vh;
background-color: #b0b0b0;
}
.wrapper {
width: 50%;
margin-left: 25%;
margin-right: 25%;
display: grid;
grid-template-columns: 100px 100px 100px;
grid-gap: 20px;
grid-auto-rows: 100px;
justify-content: center;
background-color: ;
}
.item {
border-radius: 50px;
color: white;
padding: 10px;
display: flex;
align-items: center;
justify-content: center;
}
.item input {
opacity: 0;
position: absolute;
/*this makes it not interfere with the text location*/
}
.item:nth-child(odd) {
background: gray;
}
.item:nth-child(odd):hover {
background: limegreen;
cursor: pointer;
}
.item:nth-child(odd):label {}
.wrapper h2 {
grid-row: 1;
grid-column: 1/-1;
}
<div id="trialDiv" style="font-size: 13pt;">
<div id="TrialQuestions">
<div id="Questions" class="wrapper">
<h2 style="text-align:center"><i>What emotion was the face expressing? </i></h2>
<div id="gap" class="item"></div>
<div id="HappyButton" class="item">
<label>
<p><input class="responseButton" id="emotion_1" name="emotion" onclick = "GrabEmotionClickTime()" type="radio" value="1" /> Happiness</p>
</label>
</div>
<div id="gap" class="item"></div>
<div id="AngryButton" class="item">
<label>
<p><input class="responseButton" id="emotion_2" name="emotion" onclick = "GrabEmotionClickTime()"type="radio" value="2" /> Anger</p>
</label>
</div>
<div id="gap" class="item"></div>
<div id="FearButton" class="item">
<label>
<p><input class="responseButton" id="emotion_4" name="emotion" onclick = "GrabEmotionClickTime()"type="radio" value="3" /> Fear</p>
</label>
</div>
<div id="gap" class="item"></div>
<div id="NeutralButton" class="item">
<label>
<p><input class="responseButton" id="emotion_4" name="emotion" onclick = "GrabEmotionClickTime()"type="radio" value="4" /> Neutral</p>
</label>
</div>
</div>
</div>
</div>
Without doing all the work for you, your arrangement of elements is incorrect. Here is a simple example:
https://codepen.io/seanstopnik/pen/8a2ca693e9fe1f1334b921a6d75dbe99
/* For demo only */
body {
font-family: sans-serif;
padding: 40px;
}
/* Emotion button */
.emotion-button {
position: relative;
margin: 20px; /* For demo only */
}
.emotion-button__input {
position: absolute;
left: -9999px;
}
.emotion-button__label {
display: inline-block;
width: 100px;
height: 100px;
text-align: center;
line-height: 100px;
border-radius: 50%;
background-color: #ccc;
cursor: pointer;
transition: all 0.15s ease-in-out;
}
.emotion-button__input:checked ~ .emotion-button__label {
color: #fff;
background-color: green;
}
<div class="emotion-button">
<input id="r1" class="emotion-button__input" type="radio" name="emotion"/>
<label for="r1" class="emotion-button__label">Happiness</label>
</div>
<div class="emotion-button">
<input id="r2" class="emotion-button__input" type="radio" name="emotion"/>
<label for="r2" class="emotion-button__label">Anger</label>
</div>
Same idea as #SeanStopnik, did all the work for you:
body {
font-family: Arial, Helvetica;
font-size: 13pt;
background-color: #b0b0b0;
}
#Questions h2 {
font-style: italic;
}
.wrapper {
width: 50%;
margin-left: 25%;
margin-right: 25%;
display: grid;
grid-template-columns: 100px 100px 100px;
grid-gap: 20px;
grid-auto-rows: 100px;
justify-content: center;
background-color: ;
}
.item label {
display: block;
border-radius: 50%;
color: white;
padding: 10px;
display: flex;
align-items: center;
justify-content: center;
height: 80px;
background: gray;
}
.item label:hover {
background: lime;
}
.item input {
display: none;
}
.item input:checked + label {
background: blue;
}
.wrapper h2 {
grid-row: 1;
grid-column: 1/-1;
}
<div id="trialDiv">
<div id="TrialQuestions">
<div id="Questions" class="wrapper">
<h2 style="text-align:center">What emotion was the face expressing?</h2>
<div class="gap"></div>
<div id="HappyButton" class="item">
<input class="responseButton" id="emotion_1" name="emotion" type="radio" value="1" />
<label for="emotion_1">Happiness</label>
</div>
<div class="gap"></div>
<div id="AngryButton" class="item">
<input class="responseButton" id="emotion_2" name="emotion" type="radio" value="2" />
<label for="emotion_2">Anger</label>
</div>
<div class="gap"></div>
<div id="FearButton" class="item">
<input class="responseButton" id="emotion_3" name="emotion" type="radio" value="3" />
<label for="emotion_3">Fear</label>
</div>
<div class="gap"></div>
<div id="NeutralButton" class="item">
<input class="responseButton" id="emotion_4" name="emotion" type="radio" value="4" />
<label for="emotion_4">Neutral</label>
</div>
</div>
</div>
</div>
Explanation:
radio inputs are made invisible
they are placed right before their labels
labels are associated with them using for="id" attribute, so that clicking the label will check the radio button
I'm using the CSS pseudoclass :checked to target checked radio for styling
the CSS operator + allows to target the label right after the checked radio
Also:
you shouldn't have javascript event handlers in your HTML. Better use addEventListener from javascript for that. Your onclick made the click fail.
you shouldn't repeat ids in html
you shouldn't style your fonts inline
you shouldn't use <i> to make your titles italic. You should use CSS for that
Use font-style: italic; for the h2 element, nowdays <i> is used to insert icons
You can the id value only once in your HTML! Can't give more than one element the same id.
By clicking on the label we check the input, so we hide the input and style the label : width + height = 100%
We give all the inputs the same name to prevent checking more than one input[radio].
AddEventListener for all the inputs to toggle the class active on each one item (depends on which is the checked one).
Print to the console the id of the input that is checked.
var inputs = document.querySelectorAll('.item label');
for (let i = 0; i < inputs.length; i++){
inputs[i].addEventListener('click', (e) => {
checkEmotion(inputs[i], e);
});
}
function checkEmotion(input, e){
for(let i = 0; i < inputs.length; i++){
inputs[i].parentElement.classList.remove('active');
}
e.target.parentElement.classList.add('active');
console.log(input.nextElementSibling.getAttribute("id"));
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, Helvetica;
background-color: #b0b0b0;
}
h2 {
margin: 20px 0;
font-style: italic;
}
.wrapper {
display: flex;
justify-content: center;
}
.item {
border-radius: 50px;
color: white;
display: flex;
align-items: center;
justify-content: center;
width: 90px;
height: 90px;
margin: 0 10px;
background: gray;
position: relative;
overflow: hidden;
transition: all 0.2s;
}
.item.active {
background: #121212;
}
.item input {
opacity: 0;
display: absolute;
height: 0;
width: 0;
}
.item label {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
}
.item:hover {
background: limegreen;
}
<h2 style="text-align:center">What emotion was the face expressing?</h2>
<div class="wrapper">
<div class="item">
<label for="emotion-happy">Happy</label>
<input type="radio" id="emotion-happy" name="emotion">
</div>
<div class="item">
<label for="emotion-sad">Sad</label>
<input type="radio" id="emotion-sad" name="emotion">
</div>
<div class="item">
<label for="emotion-angry">Angry</label>
<input type="radio" id="emotion-angry" name="emotion">
</div>
<div class="item">
<label for="emotion-confused">Confused</label>
<input type="radio" id="emotion-confused" name="emotion">
</div>
</div>

Need help getting the correct layout

I have some problems laying out my elements. I tried to achieve the following layout in my web application:
I tried to use div´s and style them but it looks like this when I run it
I wanted to create a grid with three container in each row. Also for responsiveness I used flexbox.
Any suggestions how the layout could improve? I think I messed it up a little.
.contacts-container {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
}
h1.subheading {
color: red;
}
.contact {
flex: 0 0 32%;
/* don't grow, don't shrink, width */
margin-bottom: 5px;
border: 1px solid #ddd;
}
.contact a {
color: black;
text-decoration: none;
}
.contactInfo {
padding: 1.4em;
float: left;
}
.contactInfo h2 {
margin-top: 0;
margin-bottom: 0.5em;
font-weight: normal;
}
.contactInfo p {
font-size: 95%;
}
.contactInfo .contactName {
float: right;
}
.contactDetails {
float: left;
}
.contactDetails img {
width: 50px;
height: 50px;
}
#contact .contact-buttons {
position: absolute;
bottom: 0;
left: 0;
}
/* Using flexbox with media queries to make the layout responsive*/
#media screen and (min-width: 40em) {
.contacts-container {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
margin-top: -1em;
}
.contact-info {
display: flex;
flex: 0 1 calc(50% - 0.5em);
margin-bottom: 1em;
}
}
#media screen and (min-width: 60em) {
.contacts-container {
margin-top: inherit;
}
.contact-info {
flex: 0 1 calc(33% - 1em);
margin-bottom: 2em;
}
}
<div class="contacts">
<h1 class="subheading">Deine Kontakte</h1>
<div class="contacts-container">
<div v-for="contact in contacts" class="contact" :key="contact.name">
<div class="contactInfo">
<img :src="getImage(contactImg)" />
<div class="contactName">
<p>Prename Surname</p>
<p>City</p>
<p>Country</p>
</div>
</div>
<div class="contactDetails">
<div>
<img :src="getImage(contactImg)" style="" /> test#test.com
</div>
<div>
<img :src="getImage(contactImg)" /> test#test.com
</div>
<div>
<img :src="getImage(contactImg)" /> test#test.com
</div>
</div>
<div class="contact-buttons">
<button v-on:click="counter += 1">Add 1</button>
<button v-on:click="counter += 1">Add 1</button>
</div>
</div>
</div>
</div>
.contacts {
width: 300px;
padding: 40px;
border: 1px solid black;
}
.contact {
display: flex;
flex-wrap: wrap;
flex-direction: column;
}
.contact .contactInfo {
display: flex;
margin-bottom: 30px;
}
.contact .contactInfo img {}
.contact .contactInfo .contactName {
margin: auto 0;
margin-left: 30px;
}
.contact .contactDetails {
margin-bottom: 30px;
border: 1px solid black;
}
.contact .contactDetails div {
display: flex;
margin: 10px;
}
.contact .contactDetails div p {
margin-left: 30px;
}
.contact .contact-buttons {
width: 100%;
display: flex;
justify-content: space-between;
}
<div class="contacts">
<h1 class="subheading">Deine Kontakte</h1>
<div class="contacts-container">
<div v-for="contact in contacts" class="contact" :key="contact.name">
<div class="contactInfo">
<img src="https://via.placeholder.com/150" />
<div class="contactName">
<p>Prename Surname</p>
<p>City</p>
<p>Country</p>
</div>
</div>
<div class="contactDetails">
<div>
<img src="https://via.placeholder.com/50" />
<p>test#test.com</p>
</div>
<div>
<img src="https://via.placeholder.com/50" />
<p>test#test.com</p>
</div>
<div>
<img src="https://via.placeholder.com/50" />
<p>test#test.com</p>
</div>
</div>
<div class="contact-buttons">
<button v-on:click="counter += 1">Add 1</button>
<button v-on:click="counter += 1">Add 1</button>
</div>
</div>
</div>
</div>
.contact {
margin-bottom: 5px;
border: 1px solid #ddd;
padding: 10px;
}
.contactInfo {
display: flex;
align-items: center;
}
.contactDetails {
border: 1px solid #ddd;
padding: 10px;
}
.contactDetailsRow {
display: flex;
flex-wrap: nowrap;
align-items: center;
}
.contactName,
.contactDetailsRowName {
flex: 1;
padding-left: 10px;
}
.contact-buttons {
display: flex;
}
.contact-buttons > button {
flex: 1;
margin: 10px;
}
<div class="contact">
<div class="contactInfo">
<div>
<img src="https://via.placeholder.com/100" />
</div>
<div class="contactName">
<h5>Prename Surname</h5>
<p>City</p>
<p>Country</p>
</div>
</div>
<div class="contactDetails">
<div class="contactDetailsRow">
<div>
<img src="https://via.placeholder.com/50"/>
</div>
<div class="contactDetailsRowName">
test#test.com
</div>
</div>
<div class="contactDetailsRow">
<div>
<img src="https://via.placeholder.com/50"/>
</div>
<div class="contactDetailsRowName">
test#test.com
</div>
</div>
<div class="contactDetailsRow">
<div>
<img src="https://via.placeholder.com/50"/>
</div>
<div class="contactDetailsRowName">
test#test.com
</div>
</div>
</div>
<div class="contact-buttons">
<button>Add 1</button>
<button>Add 1</button>
</div>
</div>
Been a while but something like this?
:root {
--baseMargin: 1.4em;
--buttonBorderRadius: 0.5em 0.5em 0.5em 0.5em;
--paddingBaseFill: calc(var(--baseMargin) * 2);
}
.contactInfo img {
min-width: 10em;
}
.contacts-container {
display: flex;
flex-direction: column;
flex-wrap: wrap;
justify-content: space-around;
}
h1.subheading {
color: red;
}
.contact {
flex: 0 1;
display: flex;
flex-direction: column;
/* don't grow, don't shrink, width */
margin-bottom: 5px;
border: 1px solid #ddd;
}
.wrapper {
margin: 0 var(--baseMargin);
}
.contact a {
color: black;
text-decoration: none;
}
.contactInfo {
flex: 1 1;
display: flex;
padding: var(--paddingBaseFill) 0;
}
.contactInfo h2 {
margin-top: 0;
margin-bottom: 0.5em;
font-weight: normal;
}
.contactInfo p {
font-size: 95%;
}
.contactInfo .contactName {
flex: 1 1;
margin-left: var(--baseMargin);
text-align: center;
}
.contactDetails {
flex: 1 1;
padding: 1em;
border: 0.1em solid black;
}
.contactDetails div {
display: flex;
align-items: center;
}
.contactDetails img {
width: 50px;
height: 50px;
padding: 0.5em;
}
.contact-buttons {
flex: 1 1;
display: flex;
justify-content: space-between;
padding: var(--baseMargin) 0;
}
.contact-buttons button {
font-size: 1.2em;
background: #018bff;
border-radius: var(--buttonBorderRadius);
padding: 0.25em;
color: #fff;
}
<div class="contacts">
<h1 class="subheading">Deine Kontakte</h1>
<div class="contacts-container">
<div v-for="contact in contacts" class="contact" :key="contact.name">
<div class="contactInfo wrapper">
<img :src="getImage(contactImg)" />
<div class="contactName">
<p>Prename Surname</p>
<p>City</p>
<p>Country</p>
</div>
</div>
<div class="contactDetails wrapper">
<div>
<img :src="getImage(contactImg)" style="" /> test#test.com
</div>
<div>
<img :src="getImage(contactImg)" /> test#test.com
</div>
<div>
<img :src="getImage(contactImg)" /> test#test.com
</div>
</div>
<div class="contact-buttons wrapper">
<button v-on:click="counter += 1">Add 1</button>
<button v-on:click="counter += 1">Add 1</button>
</div>
</div>
</div>
</div>

how to Center align a whole div inside a container div using flex-box?

I'm trying to make a layout using flex box and i've tried every combination but i'm not able to achieve what i want to have.
I want this whole "<div class="swpm-login-widget-logged">" to at the center of the container wihout any change in the structutre.
Is that possible to achieve using flex-box.
Current structure:
Required structure:
.swpm-logged-username,
.swpm-logged-status,
.swpm-logged-membership,
.swpm-logged-expiry {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
font-size: 15px;
margin-bottom: 5px;
}
.swpm-logged-username-label,
.swpm-logged-status-label,
.swpm-logged-membership-label,
.swpm-logged-expiry-label {
-webkit-flex-basis: 150px;
-ms-flex-preferred-size: 150px;
flex-basis: 150px
}
.swpm-logged-logout-link a {
display: inline-block;
padding: 5px 15px;
color: #fff;
background-color: #83a83d;
text-decoration: none;
border-radius: 3px;
margin-top: 15px;
}
<div class="swpm-login-widget-logged">
<div class="swpm-logged-username">
<div class="swpm-logged-username-label swpm-logged-label">Logged in as:</div>
<div class="swpm-logged-username-value swpm-logged-value">vikrant negi</div>
</div>
<div class="swpm-logged-status">
<div class="swpm-logged-status-label swpm-logged-label">Account Status:</div>
<div class="swpm-logged-status-value swpm-logged-value">Active</div>
</div>
<div class="swpm-logged-membership">
<div class="swpm-logged-membership-label swpm-logged-label">Membership:</div>
<div class="swpm-logged-membership-value swpm-logged-value">Paid Members</div>
</div>
<div class="swpm-logged-expiry">
<div class="swpm-logged-expiry-label swpm-logged-label">Account Expiry:</div>
<div class="swpm-logged-expiry-value swpm-logged-value">Never</div>
</div>
<div class="swpm-logged-logout-link">
Logout
</div>
</div>
you can add to your css
.swpm-login-widget-logged {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
Try This
.swpm-login-widget-logged {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
.swpm-login-widget-inner {
width: auto;
}
.swpm-logged-username,
.swpm-logged-status,
.swpm-logged-membership,
.swpm-logged-expiry {
display: -webkit-box;
font-size: 15px;
margin-bottom: 5px;
}
.swpm-logged-username-label,
.swpm-logged-status-label,
.swpm-logged-membership-label,
.swpm-logged-expiry-label {
-webkit-flex-basis: 150px;
-ms-flex-preferred-size: 150px;
flex-basis: 150px
}
.swpm-logged-logout-link a {
display: inline-block;
padding: 5px 15px;
color: #fff;
background-color: #83a83d;
text-decoration: none;
border-radius: 3px;
margin-top: 15px;
}
<div class="swpm-login-widget-logged">
<div class=".swpm-login-widget-inner">
<div class="swpm-logged-username">
<div class="swpm-logged-username-label swpm-logged-label">Logged in as:</div>
<div class="swpm-logged-username-value swpm-logged-value">vikrant negi</div>
</div>
<div class="swpm-logged-status">
<div class="swpm-logged-status-label swpm-logged-label">Account Status:</div>
<div class="swpm-logged-status-value swpm-logged-value">Active</div>
</div>
<div class="swpm-logged-membership">
<div class="swpm-logged-membership-label swpm-logged-label">Membership:</div>
<div class="swpm-logged-membership-value swpm-logged-value">Paid Members</div>
</div>
<div class="swpm-logged-expiry">
<div class="swpm-logged-expiry-label swpm-logged-label">Account Expiry:</div>
<div class="swpm-logged-expiry-value swpm-logged-value">Never</div>
</div>
<div class="swpm-logged-logout-link">
Logout
</div>
</div>
</div>
I added
{
margin:auto;
width: 255px;
}
to .swpm-login-widget-logged
.swpm-login-widget-logged{
margin:auto;
width: 255px;
}
.swpm-logged-username,
.swpm-logged-status,
.swpm-logged-membership,
.swpm-logged-expiry {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
font-size: 15px;
margin-bottom: 5px;
}
.swpm-logged-username-label,
.swpm-logged-status-label,
.swpm-logged-membership-label,
.swpm-logged-expiry-label {
-webkit-flex-basis: 150px;
-ms-flex-preferred-size: 150px;
flex-basis: 150px
}
.swpm-logged-logout-link a {
display: inline-block;
padding: 5px 15px;
color: #fff;
background-color: #83a83d;
text-decoration: none;
border-radius: 3px;
margin-top: 15px;
}
<div class="swpm-login-widget-logged">
<div class="swpm-logged-username">
<div class="swpm-logged-username-label swpm-logged-label">Logged in as:</div>
<div class="swpm-logged-username-value swpm-logged-value">vikrant negi</div>
</div>
<div class="swpm-logged-status">
<div class="swpm-logged-status-label swpm-logged-label">Account Status:</div>
<div class="swpm-logged-status-value swpm-logged-value">Active</div>
</div>
<div class="swpm-logged-membership">
<div class="swpm-logged-membership-label swpm-logged-label">Membership:</div>
<div class="swpm-logged-membership-value swpm-logged-value">Paid Members</div>
</div>
<div class="swpm-logged-expiry">
<div class="swpm-logged-expiry-label swpm-logged-label">Account Expiry:</div>
<div class="swpm-logged-expiry-value swpm-logged-value">Never</div>
</div>
<div class="swpm-logged-logout-link">
Logout
</div>
</div>