Float two flex items left and one right in one row - html

I am trying to use flexbox to design my layout. Basically my goal is: move the button "I am a button" all the way to the right end of the flex container, and keep the other two social buttons at the left side of the container.
<div class="quote-box quote">
<h2>This is where the quote text is going to beThis is where the quote text is going to beThis is where the quote text is going to be</h2>
<p class="quote-writter">Quote writer</p>
<div class="buttons">
<span class="my-button">I am a button</span>
<a href="#" class="tweet-quote-butt"><i class="fa fa-2x fa-twitter"></i>
<a href="#" class="tumblr-quote-butt"><i class="fa fa-2x fa-tumblr"></i>
</a>
</div>
</div>
</div>
Here is the CSS
.wrapper {
max-width:750px;
margin: 0 auto;
display:flex;
align-items:center;
order:1;
}
.quote-box {
background:rgba(255,255,255,0.2);
margin:20px;
padding:20px;
border-radius: 4px;
text-align: center;
flex:1;
display:flex;
flex-wrap:wrap;
}
.quote-box .quote-writter{
display: flex;
justify-content: flex-end;
}
.quote-box .buttons{
display: flex;
justify-content: flex-start;
}
.quote-box > * {
flex:1 1 100%;
}
.quote-box .my-button{
display: flex;
justify-content: flex-end;
width: 100vh;
order:3;
}
.quote-box .my-button .get-quote-butt{
display: flex;
flex-basis: 300px;
align-items: center;
}
PLEASE LOOK AT THIS IMAGE

You can use margin-left:auto, and then adjust your button.
.wrapper {
max-width: 750px;
margin: 0 auto;
display: flex;
align-items: center;
order: 1;
}
.quote-box {
background: rgba(255, 255, 255, 0.2);
margin: 20px;
padding: 20px;
border-radius: 4px;
text-align: center;
flex: 1;
display: flex;
flex-wrap: wrap;
}
.quote-box .quote-writter {
display: flex;
justify-content: flex-end;
}
.quote-box .buttons {
display: flex;
justify-content: flex-start;
}
.quote-box>* {
flex: 1 1 100%;
}
.quote-box .my-button {
display: flex;
justify-content: flex-end;
width: 100vh;
order: 3;
margin-left: auto;
}
.quote-box .my-button .get-quote-butt {
display: flex;
flex-basis: 300px;
align-items: center;
background: #f1f1f1;
justify-content: center;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet" />
<div class="quote-box quote">
<h2>This is where the quote text is going to beThis is where the quote text is going to beThis is where the quote text is going to be</h2>
<p class="quote-writter">Quote writer</p>
<div class="buttons">
<span class="my-button">I am a button</span>
<i class="fa fa-2x fa-twitter"></i>
<a href="#" class="tumblr-quote-butt"><i class="fa fa-2x fa-tumblr"></i>
</a>
</div>
</div>
DEMO HERE

Related

Flex boxs overlapping in direction column

I am trying to make a footer that displays a button on the left, and 3 social media icons on the right and a copyright text below it which I seem to have working fine. The issue is for mobile im then trying to make it so they all stack on top of one another but the button and icons seem to be overlapping each other.
HTML
<div class="footer">
<div class="footerHeader">
<div>
<a id="login" href="/login" class="btn btn-primary">Sign in</a>
</div>
<div class="socialMedia">
<img alt="Facebook" class="icon zoom" src="/images/facebook.png">
<img alt="Instagram" class="icon zoom" src="/images/instagram.png">
<img alt="Twitter" class="icon zoom" src="/images/twitter.png">
</div>
</div>
<!-- Copyright -->
<div class="footerCopyright">© 2022 Copyright:
NAME
</div>
</div>
CSS
.footer{
background-color: white;
padding-top:20px;
padding-left: 50px;
padding-right: 50px;
padding-bottom: 5px;
max-height: 100%;
display: flex;
flex-direction: column;
align-items: center;
}
.footerHeader{
display: flex;
justify-content: space-around;
flex-direction: row;
align-items: center;
padding: 0px;
width: 100%;
}
.socialMedia{
width: 64px;
height: 64px;
display: flex;
justify-content: space-evenly;
float: right;
}
.icon{
margin-right: 10px;
margin-left: 10px;
width: 64px;
height: 64px;
transition: transform .2s;
}
.footerCopyright{
margin: 10px;
}
Media querys for footer:
.footer{
min-height: 50vh;
justify-content: space-between;
}
.footerHeader{
flex-direction: column;
justify-content: space-evenly;
padding: 0px;
height: 25vh;
}
.socialMedia{
flex-direction: column;
}
.icon{
margin: 0 auto;
margin-bottom: 20px;
}
This is minimum working demo code in which you can make changes and use it.
.top {
display: flex;
justify-content: space-between;
}
.social-media {
display: flex;
flex-flow: row;
}
.social-media img {
margin-left: 10px;
}
.footerCopyright {
margin-top: 10px;
}
#media screen and (max-width: 480px) {
.social-media {
flex-flow: column;
margin-top: 10px;
margin-bottom: 10px;
}
.social-media img {
margin-left: 0;
margin-top: 10px;
}
.top {
display: block;
}
}
<div class="footer">
<div class="top">
Button
<div class="social-media">
<img alt="Facebook" class="icon zoom" src="/images/facebook.png">
<img alt="Instagram" class="icon zoom" src="/images/instagram.png">
<img alt="Twitter" class="icon zoom" src="/images/twitter.png">
</div>
</div>
<div class="footerCopyright">© 2022 Copyright:
NAME
</div>
</div>

min-height or min-width or responsive won't work

I want to create a layer from windows 10 calculator and i have some problem in height and width in it.
Any help would be appreciated.
Problems:
when i pull up the top of the result or increase the height of the browseer the calculator go up and a large space appear in the bottom of the calculator and i don't know why is that.
when i decrease the width of the window instead of decrease the width of buttons calculator go right and some buttons won't display.
when i decrease the height of window it won't stop any where but i want to stop it in 500 px height;
This is my code.
html:
<!DOCTYPE html>
<html>
<head>
<link href="./calculator.css" rel="stylesheet" type="text/css">
<title>Windows10 Calculator</title>
<script id="MathJax-script" async
src="https://cdn.jsdelivr.net/npm/mathjax#3/es5/tex-mml-chtml.js">
</script>
</head>
<body>
<div class="container">
<div class="calculator-container">
<div class="top-navbar">
<p id="calculator">
Calculator
</p>
<div class="close-bar">
<a id="minimize">-</a>
<a id="maximize">🗆</a>
<a id="close">x</a>
</div>
</div>
<div class="calculator-screen">
<div class="top-screen">
<a id="calculator-menu">≡</a>
<p id="standard">
Standard
</p>
</div>
<div class="result"><span id="result">4</span></div>
<div class="m-row">
<a id="MC">MC</a>
<a id="MR">MR</a>
<a id="Mplus">M+</a>
<a id="Mminus">M-</a>
<a id="MS">MS</a>
</div>
</div>
<hr />
<div class="functions">
<div class="row">
<a class="hide-in-big blue">%</a>
<a class="hide-in-big blue">√</a>
<a class="lucida-font hide-in-big blue"><p>
x<sup>2</sup>
</p></a>
<a class="lucida-font hide-in-big blue"><p><sup>1</sup>∕<sub>x</sub></p></a>
</div>
<div class="row">
<a class="show-in-big blue">%</a>
<a class="cs blue">CE</a>
<a class="cs blue">C</a>
<a class="blue"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAABDklEQVRYR+2W4Q3CIBSErxu4iY6gm+hmbqIj6CZuUHNJMeQFeAelaUzoT8LjPo570Ak7f9PO+hgAw4G/cuAA4AHg1KFzfhtXHegpTv4qgFj8DeAM4NPowrzUyQA9xaldBaCIc451IzUWDJMBFPE7gCOASwQR6l4AboljkgAUcc55LgAUIwS/0CW5rLgAinjYmIXgOFu0FNQiQI14CoJjXpe4ANZWr93s/RCOI1cnHYEKYR2jAwxlCcIF4CKpgKVazQaOtR68BKBCsA0ZuvhmDPB04drahrmUx/0ez9nkIqqBqHkW5COIF1UyoUI0AdhMqGKlefJrmHNiLUQTwFrRZL36R7SJOBcdAMOB3R34AqM1YCEu+sgCAAAAAElFTkSuQmCC" /></a>
<a class="hover-blue blue">\[\div\]</a>
</div>
</div>
<div class="numpad">
<div class="row">
<a class="lucida-font show-in-big blue">√</a>
<a class="number">7</a>
<a class="number">8</a>
<a class="number">9</a>
<a class="hover-blue blue">×</a>
</div>
<div class="row">
<a class="lucida-font show-in-big blue"><p>
x<sup>2</sup>
</p>
<a class="number">4</a>
<a class="number">5</a>
<a class="number">6</a>
<a class="hover-blue blue">-</a>
</div>
<div class="row">
<a class="lucida-font show-in-big blue"><p>
x<sup>3</sup>
</p></a>
<a class="number">1</a>
<a class="number">2</a>
<a class="number">3</a>
<a class="hover-blue blue">&plus;</a>
</div>
<div class="row">
<a class="lucida-font show-in-big blue"><p><sup>1</sup>∕<sub>x</sub></p></a>
<a class="blue">±</a>
<a class="number">0</a>
<a class="blue">∙</a>
<a class="hover-blue blue">&equals;</a>
</div>
</div>
</div>
<div class="history-memory">
<div>
<div class="hidden-close-bar">
<a id="minimize">ー</a>
<a id="maximize">🗆</a>
<a id="close">྾</a>
</div>
<div class="history-memory-bar">
<a id="history">History</a>
<a id="memory">Memory</a>
</div>
</div>
<div class="history-memory-screen">
<span class="grey"> 2×2=</span>
<span class="black">4</span>
<span class="grey">9999+1=</span>
<span class="black">10000</span>
</div>
</div>
</div>
</body>
CSS:
#font-face{
src:
url("//db.onlinewebfonts.com/t/efbd8f0d869bf61fbe0f139a1602cda8.woff2");
font-family:"lucida calligraphy";
}
body{
min-width: 500px;
width: auto !important;
margin: 0 !important;
overflow: hidden;
font-family: Segoe UI;
}
.close-bar, .hidden-close-bar{
margin-right: 10px;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
.container{
min-width: 800px;
min-height: 800px;
width: 100%;
height: 100%;
display: flex;
flex-direction: row;
overflow-y: hidden;
background-color: #E6E6E6;
}
.calculator-container{
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: space-between !important;
}
.top-navbar{
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
.top-navbar p {
margin-left: 10px;
}
.top-screen a{
font-size: 2em;
display: flex;
justify-content: center;
align-items: center;
}
.top-screen p{
display: flex;
align-items: center;
justify-content: center;
}
.calculator-screen{
display: flex;
flex-direction: column;
}
.top-screen{
display: flex;
flex-direction: row;
}
.top-screen * {
margin: 1%;
font-size: 2em;
}
.result{
height: 15vh;
display: flex;
justify-content: flex-end;
font-size: 4em;
font-family: Segoe UI;
font-weight: bold;
}
.row{
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: bottom
}
.cs{
font-size: 1.5em !important;
}
.m-row{
display: flex;
flex-direction: row;
justify-content: start;
align-items: center;
}
.m-row a{
margin-left: 7%;
cursor: pointer;
}
#standard{
font-size: 1.5em;
margin-left: 3%;
}
.row a {
width: 25%;
height: 10%;
display: flex;
justify-content: center;
align-items: center;
height: 10vh;
margin: 1px;
cursor: pointer;
font-size: 2em;
}
.row a:hover{
background-color: #B1B2B5;
}
.blue{
background-color: #F0F0F0;
font-weight: 300;
}
.number{
background-color: #FAFAFA;
font-weight: bold;
font-size: 1.5em !important;
}
.history-memory{
display: none;
}
.history-memory a {
cursor: pointer;
font-size: 1.5em;
}
.row .hide-in-big{
display: flex;
justify-content: center;
align-items: center;
}
.row .show-in-big{
display: none;
}
.hidden-close-bar{
display: none;
}
.close-bar {
margin: 1px;
}
#history {
border-bottom: 2px solid #0097A7;
margin-right: 10%;
}
#trash-can {
display: flex;
justify-content: flex-end;
align-items: center;
margin: 10px;
background-color: #aad3ef;
cursor: default;
}
#trash-can img {
width: 15%;
cursor: pointer;
background-color: #aad3ef;
}
.history-memory-screen{
display: flex;
flex-direction: column;
justify-content: flex-start;
margin-top: 10%;
height: 100%;
}
.history-memory-bar{
display: flex;
flex-direction: row;
justify-content: flex-start;
}
.grey{
align-self: flex-end;
color: #616161;
margin: 5px;
margin-right: 5px;
}
.black{
align-self: flex-end;
justify-self: flex-end;
margin: 5px;
margin-right: 5px;
}
.lucida-font{
font-family:"lucida calligraphy" !important;
font-size: 1em !important;
font-weight: bold !important;
}
.hover-blue:hover{
background-color: #1C87DB !important;
color: white;
display: flex;
justify-content: center;
align-items: center;
}
#media screen and (max-width: 800px){
.calculator-container{
width: 100%;
height: 100%
}
.row .show-in-big{
display: none;
}
.row .hide-in-big {
display: flex;
justify-content: center;
align-items: center;
}
}
#media screen and (min-width:800px){
.history-memory{
display: flex;
width: 40%;
flex-direction: column;
justify-content: space-between;
}
.hidden-close-bar{
display: block;
text-align: right;
}
.hidden-close-bar a{
margin: 1px;
}
.close-bar {
display: none;
}
}
#media screen and (min-width: 1000px){
.row .hide-in-big{
display: none;
}
.row .show-in-big {
display: flex;
justify-content: center;
align-items: center;
}
}
and this is the link to jsfiddle of my code
problem number 1: since you use min-height, you should define the height of your paren. In your case it is body so this will solve the 1st problem:
body{
/* other stuff */
height: 100vh; /* or whatever px, em, etc., except % */
}
problem number 2: As I understand, the problem appears with the 'M' buttons, since all others seem to be resized correctly... so if you add max-width to the .m-row a it would prevent overflow. You also could add the font-size in vw as you did for the other buttons, though I wouldn't do this because all the texts become unreadable in a small window.
.m-row a{
margin-left: 7%;
max-width: 13%; /* because you have 5 buttons (each 20%) - 7% of your margin-left*/
}
problem number 3: You could open a new window with specified dimensions with some javascript and control it's size with window.resizeTo. However I think some browsers won't allow this.. So instead I would simply add min-width, min-height add overflow: auto to the parent (in your case the body).
I hope it helps.

FlexBox: align icons by left corner and keep same gap after them

I have flexbox container with items. They are both horizontally and vertically aligned by center. This is normally rendered on a live website. However I need to align font awesome icons with text in such way:
1). All icons are aligned by the left corner
2). The gap which goes after icons and before text must have the same length.
Here is a CodePen with a draft
So it's shown that icons are not aligned properly.
Code:
.contact-container {
display: -ms-flexbox;
-ms-flex-wrap: wrap;
-ms-flex-direction: column;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-flow: row wrap;
flex-flow: row wrap;
display: -webkit-box;
display: flex;
}
.contact-container .copy {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
justify-content: center;
-webkit-box-align:center;
-ms-flex-align:center;
align-items:center;
}
.contact-container .fa {
font-size: 40px;
-ms-flex-negative: 0;
flex-shrink: 0;
padding-left:20px;
}
.contact-container .item > *{color: #9f6a4a;}
.contact-container .item {
-webkit-box-flex: 0;
flex: 0 1 100%;
-ms-flex: 0 1 100%;
flex: 0 1 47%;
background:#fff;
color:#fff;
}
.contact-container .item{
/*height: calc(720px/4);*/
-ms-flex-item-align: center;
align-self: center;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
text-align: center;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
/*min-height: 100%;*/
min-width: 50%;
}
.contact-container h2{font-size:1.1em;font-weight:500;}
.contact-container h3 {padding-left: 10px;}
By definition, you can't left-justify objects that are centered. You would have to set the parent container to left align the icon/text, then give a left margin/width to allow for them to match up - as each individual container is again in another container.
EDIT: A rough example, here:
.contact-container {
display: flex;
flex-flow: row wrap;
align-items: center;
}
.item {
width: 50%;
}
.item > * {
color: #9f6a4a;
}
.copy {
display: flex;
flex-direction: row;
align-items: center;
width: 70%;
margin: auto;
}
h3 {
margin: 0 .5em;
}
i.fa {
font-size: 40px;
padding-left:20px;
}
/* IGNORE THIS - for illustrative purpose only */
.item:nth-child(1), .item:nth-child(4) {
background-color: #DFD;
}
.item:nth-child(2), .item:nth-child(3) {
background-color: #DDF;
}
<script src="https://use.fontawesome.com/97dc0a8baa.js"></script>
<div class="contact-container">
<div class="item">
<div class="box">
<div class="inner">
<div class="copy"> <i class="fa fa-mobile-phone"></i>
<h3 class="sppb-addon-title sppb-feature-box-title sppb-media-heading">+1 123 45 678 99</h3></div>
</div>
</div>
</div>
<div class="item">
<div class="box">
<div class="inner">
<div class="copy"> <i class="fa fa-envelope-o"></i>
<h3 class="sppb-addon-title sppb-feature-box-title sppb-media-heading"> <span>info#info.com</span></h3></div>
</div>
</div>
</div>
<div class="item">
<div class="box">
<div class="inner">
<div class="copy"> <i class="fa fa-map-marker"></i>
<h3 class="sppb-addon-title sppb-feature-box-title sppb-media-heading">City, Street 22</h3></div>
</div>
</div>
</div>
<div class="item">
<div class="box">
<div class="inner">
<div class="copy"> <i class="fa fa-calendar"></i>
<h3 class="sppb-addon-title sppb-feature-box-title sppb-media-heading">I-V 09:00-17:00<br> VI 09:00-14:00<br>VII closed</h3></div>
</div>
</div>
</div>
</div>

Center items correctly when using justify-content: space-between

I created a header bar and want to place 3 items there. The first should be aligned on the left side, the second in the middle of the header and the third on the right side.
I went for this
body{
background: #eeeeee;
}
#header {
background: #ffffff;
height: 53px;
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
}
.headerEle {
}
<div id="header">
<img class="headerEle" src="https://cdn.discordapp.com/attachments/316916526760591362/390814093340311565/unknown.png">
<a class="headerEle" href="https://www.google.de/">Google</a>
<button class="headerEle">Logout</button>
</div>
but when using justify-content: space-between; the items don't get centered correctly. The image takes a bigger place than the small button on the right.
So the link in the middle is not centered correctly, it overlaps the right side. I want the link being in the horizontal center of the page.
You can do something like this:
body {
background: #eee;
}
#header {
background: #fff;
height: 53px;
display: flex;
/*flex-direction: row; not necessary, by default*/
align-items: center;
justify-content: space-between;
}
#header > span {flex: 1} /* each 33.33% of the parent's width */
img {display: block; max-width: 100%; max-height: 100vh} /* responsiveness; "display: block" removes bottom margin/whitespace */
.link {
display: flex;
justify-content: center; /* horizontally centered */
}
.btn {
display: flex;
justify-content: flex-end; /* placed far right */
}
<div id="header">
<span>
<img class="headerEle" src="https://cdn.discordapp.com/attachments/316916526760591362/390814093340311565/unknown.png">
</span>
<span class="link">
<a class="headerEle" href="https://www.google.de/">Google</a>
</span>
<span class="btn">
<button class="headerEle">Logout</button>
</span>
</div>
You can use absolute positioning for the <a> element to exactly center the link on the header:
body{
background: #eeeeee;
}
#header {
background: #ffffff;
height: 53px;
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
position:relative;
}
#header a {
position:absolute;
left:50%;
top:50%;
transform:translate(-50%, -50%);
}
<div id="header">
<img class="headerEle" src="https://cdn.discordapp.com/attachments/316916526760591362/390814093340311565/unknown.png">
<a class="headerEle" href="https://www.google.de/">Google</a>
<button class="headerEle">Logout</button>
</div>
Is this what you are looking to do?
body{
background: #eeeeee;
}
#header {
background: #ffffff;
height: 53px;
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
}
#header > div {
-webkit-flex: 1; /* Safari 6.1+ */
-ms-flex: 1; /* IE 10 */
flex: 1;
text-align: center;
}
<div id="header">
<div>
<img class="headerEle" src="https://cdn.discordapp.com/attachments/316916526760591362/390814093340311565/unknown.png">
</div>
<div>
<a class="headerEle" href="https://www.google.de/">Google</a>
</div>
<div>
<button class="headerEle">Logout</button>
</div>
</div>

Justify-content not working

I have created a sub-container, containing two items which I would like to display as flex-direction: row with justify-content: space-between. I can't seem to get it to work.
HTML:
<body>
<div class="container">
<div class="randqg">
<div class="title">Random Quote Generator</div>
<div class="subcontainer">
<i class="fa fa-quote-left fa-3x" aria-hidden="true"></i>
<a class="twitter-share-button" href="https://twitter.com/intent/tweet">Tweet</a>
</div>
<blockquote id="text">Original Text</blockquote>
<div class="subcontainer">
<span id="author">author</span>
<i class="fa fa-quote-left" aria-hidden="true"></i>
</div>
</div>
</div>
</body>
<script src="https://use.fontawesome.com/02b956c77d.js"></script>
CSS:
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
background-color: blue;
}
.randqg {
display: flex;
align-items: center;
min-height: 24em;
justify-content: center;
flex-direction: column;
width: 500px;
height: 50%;
border: 5px solid red;
}
.title {
}
.subcontainer{
width: 80%;
height: 80%;
flex-direction: column;
justify-content: space-between;
align-items: center;
margin: auto;
}
JS Fiddle: https://jsfiddle.net/3qx8aw44/
I have checked with dev tools that justify-content is applied to the sub-container, so I don't think it a typo error.
I thought it might be an issue of there not being enough free space to distribute between the items. So changed width to be less than 100%.
I checked
It's because you are using display block, you can't use display block, and give flex property like justify-content in the same div, you need to use display flex:
.subcontainer{
width: 80%;
height: 80%;
flex-direction: column;
justify-content: space-between;
align-items: center;
display: flex; /* added */
}