How do i wrap the buttons? - html

Here is how my code currently renders, but I want it to look like this
* {
box-sizing: border-box;
}
body {
background: rgb(75, 109, 221);
color: black;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
div {
display: flex;
justify-content: center;
position: relative;
top: 100px;
}
button {
height: 100px;
width: 150px;
background-color: white;
font-size: large;
}
<div className="Home">
<button class="donate-blood-button">Donate Blood</button>
<button class="request-blood-button">Request Blood</button>
</div>

You can do this using flex-direction: column, which basically flips the uses of justify-content and align-items. Then, set align-items: center and justify-content: space-between and set a height for the container (I used 300px).
* {
box-sizing: border-box;
}
body {
background: rgb(75, 109, 221);
color: black;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
div {
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
position: relative;
top: 100px;
height: 300px;
}
button {
height: 100px;
width: 150px;
background-color: white;
font-size: large;
}
<div className="Home">
<button class="donate-blood-button">Donate Blood</button>
<button class="request-blood-button">Request Blood</button>
</div>
Any time you need help with display: flex;, you should test your ideas on the Yoga Layout Playground. It's an extremely powerful tool for positioning elements.

.Home
{
display: inline;
}
.Home
{
display: inline;
}
<div class="Home">
<button class="donate-blood-button">Donate Blood</button>
<button class="request-blood-button">Request Blood</button>
</div>

* {
box-sizing: border-box;
}
body {
background: rgb(75, 109, 221);
color: black;
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}
.Home {
margin:13% 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-around;
}
.Home > button {
height: 100px;
width: 150px;
background-color: white;
font-size: large;
margin:50px 0;
}
<div class="Home">
<button class="donate-blood-button">Donate Blood</button>
<button class="request-blood-button">Request Blood</button>
</div>

Related

onclick stay focused untill click another component from the area

I try to make a chat-app, now i'm trying to implement the cheats and when user click on one chat, styles must change and remain until the user focus it's gonna to another chat
In my example let's assume someone clicked on User 2. The chat changed style and now have the style that should have when someone open that chat. How can i make the style to stay like that until someone open another chat? I didn't find any css propriety or some react tricks.
.userChatBubbles {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 5%;
width: 100%;
height: 100%;
}
.allOfMessage {
width: 100%;
height: 20%;
display: flex;
flex-direction: row;
align-items: center;
margin-left: 13%;
margin-bottom: 1px;
}
.messageBubleNEWMSG {
display: flex;
flex-direction: row;
align-items: center;
width: 90%;
height: 80%;
font-size: 15px;
background: #1d1335;
opacity: 1;
border-radius: 2%;
padding-left: 4%;
margin-right: 10%;
font-family: 'Roboto', sans-serif;
}
.messageBuble {
display: flex;
flex-direction: row;
align-items: center;
width: 90%;
height: 80%;
font-family: 'Roboto', sans-serif;
font-size: 15px;
padding-left: 4%;
margin-right: 10%;
}
.photo {
background: green;
width: 45px;
height: 45px;
margin-top: 2%;
border-radius: 10%;
margin-right: 6%;
}
.messageBubleNEWMSG.personNameAndMsg.personName {
color: green !important;
margin-top: 200%;
}
.messageBuble .personNameAndMsg h3 {
color: #c2b4da;
font-family: 'Roboto', sans-serif;
font-weight: 100;
font-size: 15px;
}
.messageBuble .personNameAndMsg p {
color: #514b64;
margin-top: -8%;
/* margin-top: 1%; */
font-family: 'Roboto', sans-serif;
font-weight: 200;
}
.messageBubleNEWMSG .personNameAndMsg h3 {
color: #e1dbed;
font-family: 'Roboto', sans-serif;
font-weight: 200;
font-size: 15px;
}
.messageBubleNEWMSG .personNameAndMsg p {
color: #736f83;
margin-top: -8%;
font-family: 'Roboto', sans-serif;
font-weight: 500;
/* margin-top: 1%; */
}
.messageTime {
margin-left: auto;
color: #6e6d73;
}
<div class='userChatBubbles'>
<div class='allOfMessage'>
<div class='messageBuble'>
<div class='photo'></div>
<div class='personNameAndMsg'>
<h3>User</h3>
<p> When can we hangout?</p>
</div>
<div class='messageTime'>6m</div>
</div>
</div>
<div class='allOfMessage'>
<div class='messageBubleNEWMSG'>
<div class='photo'></div>
<div class='personNameAndMsg'>
<h3>User 2</h3>
<p> When can we hang out?</p>
</div>
<div class='messageTime'>6m</div>
</div>
</div>
<div class='allOfMessage'>
<div class='messageBuble'>
<div class='photo'></div>
<div class='personNameAndMsg'>
<h3>User 3</h3>
<p> When can we hangout?</p>
</div>
<div class='messageTime'>6m</div>
</div>
</div>
</div>

Why cant center the divs within a flexbox model

I am not able to align center the following divs on the full page width:
header
content
footer
But it does not work! Whats needs to be changed within my CSS to get it working?
body {
margin:0;
padding:0;
}
#wrapper {
display: flex;
flex-direction: column;
}
#header {
height: 50px;
}
#hero-wrapper {
background-image: url('https://unsplash.it/1500?random');
background-size: cover;
background-position: center;
width: 100vw;
height: calc(100vh - 50px);
display: flex;
flex-direction: column;
color:#ffffff;
}
#hero {
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
#hero-text{
font-family:'Roboto';
font-weight:900;
font-size:2em;
text-align:center;
}
#hero-footnote {
font-family: 'Cabin', sans-serif;
font-size: 12px;
padding: 5px 5px 10px 5px;
}
#content {
width: 1024px;
background-color:green;
}
#footer {
font-family: 'Cabin', sans-serif;
weight: 400;
background-color: #ffffff;
/* position: fixed; */
bottom: 0;
left: 0;
width: 100%;
font-size: 0.685em;
color: #1a1717;
padding-bottom: 5px;
}
#footer-info {
width: 1024px;
margin: auto;
padding-left: 3px;
padding-right: 3px;
text-align: left;
line-height: 42px;
}
span#footer-social-icons {
}
span#copyright-info {
font-family: 'Cabin', sans-serif;
weight: 400;
padding-left:10px;
}
span#contact-link {
font-family: 'Source Sans Pro', sans-serif;
weight: 200;
padding-left:10px;
}
<link href="https://fonts.googleapis.com/css2?family=Cabin&family=Source+Sans+Pro:wght#200&family=Roboto:wght#400;500;900&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght#400;500;900&display=swap" rel="stylesheet">
<div id="wrapper">
<div id="header">header</div>
<div id="hero-wrapper">
<div id="hero">
<div id="hero-text">
<span id="hero-header">sell the product</span><br />
<span id="hero-sub">On this page for less</span>
</div>
</div>
<div id="hero-footnote">© Copyright Text</div>
</div>
<div id="content">
<!-- Content-Loop -->
<div class="article">
Here come the Article
</div>
</div>
<div id="footer">
<div id="footer-info">
<span id="footer-social-icons"></span> <span id="copyright-info">Made with love by Y.</span> <span id="contact-link">Contact</span>
</div>
</div>
</div>
You can add align-items: center; to #wrapper.
Normally if you would have flex-direction: row; centering things would be justify-content: center; but as column change the axis so does the alignment properties. They kinda "go with the axis".
One thing though, I would strongly suggest that you don't style with id, use classes for that.
body {
margin:0;
padding:0;
}
#wrapper {
display: flex;
flex-direction: column;
align-items: center;
}
#header {
height: 50px;
}
#hero-wrapper {
background-image: url('https://unsplash.it/1500?random');
background-size: cover;
background-position: center;
width: 100vw;
height: calc(100vh - 50px);
display: flex;
flex-direction: column;
color:#ffffff;
}
#hero {
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
#hero-text{
font-family:'Roboto';
font-weight:900;
font-size:2em;
text-align:center;
}
#hero-footnote {
font-family: 'Cabin', sans-serif;
font-size: 12px;
padding: 5px 5px 10px 5px;
}
#content {
width: 1024px;
background-color:green;
}
#footer {
font-family: 'Cabin', sans-serif;
weight: 400;
background-color: #ffffff;
/* position: fixed; */
bottom: 0;
left: 0;
width: 100%;
font-size: 0.685em;
color: #1a1717;
padding-bottom: 5px;
}
#footer-info {
width: 1024px;
margin: auto;
padding-left: 3px;
padding-right: 3px;
text-align: left;
line-height: 42px;
}
span#footer-social-icons {
}
span#copyright-info {
font-family: 'Cabin', sans-serif;
weight: 400;
padding-left:10px;
}
span#contact-link {
font-family: 'Source Sans Pro', sans-serif;
weight: 200;
padding-left:10px;
}
<link href="https://fonts.googleapis.com/css2?family=Cabin&family=Source+Sans+Pro:wght#200&family=Roboto:wght#400;500;900&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght#400;500;900&display=swap" rel="stylesheet">
<div id="wrapper">
<div id="header">header</div>
<div id="hero-wrapper">
<div id="hero">
<div id="hero-text">
<span id="hero-header">sell the product</span><br />
<span id="hero-sub">On this page for less</span>
</div>
</div>
<div id="hero-footnote">© Copyright Text</div>
</div>
<div id="content">
<!-- Content-Loop -->
<div class="article">
Here come the Article
</div>
</div>
<div id="footer">
<div id="footer-info">
<span id="footer-social-icons"></span> <span id="copyright-info">Made with love by Y.</span> <span id="contact-link">Contact</span>
</div>
</div>
</div>
If you just want to center the text, use text-align: center and the parts?
Or if you are looking to do more centered-content, maybe make your #header, #content, and #footer the following:
display: flex;
flex-direction: column;
align-items: center;
Basically, flex boxes within flex boxes.

flexbox - justify content does not work when used with percentage width [duplicate]

This question already has answers here:
In CSS Flexbox, why are there no "justify-items" and "justify-self" properties?
(6 answers)
Closed 3 years ago.
Why is that? I was under the impression you can do so with a percent width?
See the example below:
.amphead__branding-center {
width: 55%;
height: 3.5rem;
margin: 0 auto;
border-radius: 15px;
background-color: green;
}
.amphead__center-logo {
width: 30%;
display: flex;
flex-direction: column;
flex-basis: auto;
align-content: center;
justify-content: center;
font-family: serif;
background-color: #000;
color: #fff;
}
.engineering {
font-family: 'Source Sans Pro', sans-serif;
background-color: $main-amp-color;
color: lighten($grate-color, 2%);
}
<div class="amphead__branding-center">
<div class="amphead__center-logo">
<span>Main header</span>
<span class="engineering">Sub Header</span>
</div>
</div>
Howcome "main header" and "sub header" aren't in the center?
These resources suggest what I'm doing should work
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Flexbox: center horizontally and vertically
Whats the problem?
Nothing to do with percentage lengths.
You want to horizontally center amphead__center-logo, then apply the centering properties to the parent.
Add this to your code:
.amphead__branding-center {
display: flex;
justify-content: center;
}
.amphead__branding-center {
width: 55%;
height: 3.5rem;
margin: 0 auto;
border-radius: 15px;
background-color: green;
/* new */
display: flex;
justify-content: center;
}
.amphead__center-logo {
width: 30%;
display: flex;
flex-direction: column;
flex-basis: auto;
align-content: center;
justify-content: center;
font-family: serif;
background-color: #000;
color: #fff;
}
.engineering {
font-family: 'Source Sans Pro', sans-serif;
background-color: $main-amp-color;
color: lighten($grate-color, 2%);
}
<div class="amphead__branding-center">
<div class="amphead__center-logo">
<span>Main header</span>
<span class="engineering">Sub Header</span>
</div>
</div>
You need to apply display: flex, justify-content, flex-direction and/or align-items to the parent.
Also because you use flex-direction: column you need to use align-items to center horizontally.
.amphead__branding-center {
display: flex;
flex-direction: column;
align-items: center;
width: 55%;
height: 3.5rem;
margin: 0 auto;
border-radius: 15px;
background-color: green;
}
.amphead__center-logo {
width: 30%;
flex-basis: auto;
font-family: serif;
background-color: #000;
color: #fff;
}
.engineering {
font-family: 'Source Sans Pro', sans-serif;
background-color: $main-amp-color;
color: lighten($grate-color, 2%);
}
<div class="amphead__branding-center">
<div class="amphead__center-logo">
<span>Main header</span>
<span class="engineering">Sub Header</span>
</div>
</div>

centering text positioning using flexbox

Trying to do a simple website recreation using flexbox. Here is the final goal (for this step):
Pretty simple. But I am struggling with aligning the text. I am able to get the header to center just fine. It's mainly the paragraph underneath that I am having trouble centering. Is there a way to center that paragraph vertically and horizontally to its outer container? New to flexbox and would like any tips! Here is a link to my codepen and relevant code: https://codepen.io/gkunthara/pen/qjympg
HTML
<div class = "content-container">
<h1 class = "main-header"> Connect with Subscribers Effortlessly </h1>
<p class = "sub-header"> Email Marketing Platform for Bloggers &
Authors. </p>
</div>
CSS
.content-container .main-header{
box-sizing: border-box;
font-weight: 600;
font-size: 45px;
height:75px;
padding-left: 5px;
padding-right: 5px;
color: rgb(51, 51, 51);
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
border-style: solid;
}
.content-container .sub-header {
border-style: solid;
display: flex;
height: 25px;
margin-top: 150px;
}
You just need to do two things.
1. Add
flex-direction: column;
align-items: center;
to your .content-container class.
2. Remove margin-top: 150px from .content-container .sub-header and it should be it.
* {
box-sizing: border-box;
}
.content-container {
width: 100%;
height: 300px;
display: flex;
justify-content: center;
border-style: solid;
margin-top: 15px;
flex-direction: column;
align-items: center;
}
.content-container .main-header {
box-sizing: border-box;
font-weight: 600;
font-size: 30px;
height: 75px;
padding-left: 5px;
padding-right: 5px;
color: rgb(51, 51, 51);
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
border-style: solid;
}
.content-container .sub-header {
border-style: solid;
height: 25px;
}
<div class="content-container">
<h1 class="main-header"> Connect with Subscribers Effortlessly </h1>
<p class="sub-header"> Email Marketing Platform for Bloggers & Authors. </p>
</div>
Here is the fiddle to play with.
Hope this helps.
If you remove the margin-top in your .content-container .sub-header rule and add flex-direction: column; align-items: center; to your .content-container the text will center properly
Updated codepen
Stack snippet
* {
box-sizing: border-box;
}
.header-container {
display: flex;
width: 100%;
height: 100px;
align-items: center;
justify-content: space-between;
padding-left: 50px;
padding-right: 75px;
}
.header-container .logo {
width: 250px;
}
.header-container .logo .sb {
max-width: 100%;
}
.header-container .nav-bar-container {
display: flex;
}
.nav-link {
text-decoration: none;
color: #4B4B4B;
font-weight: bold;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
padding: 15px;
}
.content-container {
width: 100%;
height: 300px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
border-style: solid;
margin-top: 15px;
}
.content-container .main-header {
box-sizing: border-box;
font-weight: 600;
font-size: 45px;
height: 75px;
padding-left: 5px;
padding-right: 5px;
color: rgb(51, 51, 51);
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
border-style: solid;
}
.content-container .sub-header {
border-style: solid;
display: flex;
height: 25px;
}
/* Resize window to see its effect */
#media( max-width: 700px) {
.header-container {
flex-direction: column;
}
}
<div class="header-container">
<a class="logo"> <img class="sb" src="logo.png" alt="logo"> </a>
<nav class="nav-bar-container">
<a class="nav-link" href="#"> Tour </a>
<a class="nav-link" href="#"> Pricing </a>
<a class="nav-link" href="#"> Medium </a>
<a class="nav-link" href="#"> Sign Up </a>
<a class="nav-link" href="#"> Login </a>
</nav>
</div>
<div class="content-container">
<h1 class="main-header"> Connect with Subscribers Effortlessly </h1>
<p class="sub-header"> Email Marketing Platform for Bloggers & Authors. </p>
</div>
If you intended to center the .content-container .sub-header w/o take the .content-container .main-header into account, you need to position the .content-container .main-header absolute
With this, it will work with or w/o the flex-direction: column;, which I added in the first solution.
Note though, that on less wider screen you need to adjust both, or else they will overlap
Updated codepen
Added these properties to your .content-container .main-header
position: absolute;
top: 0;
left: 0;
right: 0;
text-align: center;

Change Width of Custom Button

I want to center a custom button and I can't seem to find a solution.
I can align it but I don't know how to make the border smaller and not take up the whole width of my h1 text
HTML:
#button {
color: #6E4E34;
font-size: 30px;
text-decoration: none;
border: solid 2px #6E4E34;
border-radius: 5px;
padding: 10px;
font-family: "PT Sans", sans-serif;
display: flex;
justify-content: center;
}
<div id="ImageMain">
<div id="TextMain">
<h1>Shop our Whole Selection</h1>
Browse
</div>
</div>
You mean something like this?
set #textMain with
align-items: center;
display: flex;
flex-direction: column;
justify-content: center;
Snippet
#TextMain {
align-items: center;
display: flex;
flex-direction: column;
justify-content: center;
}
#button {
color: #6E4E34;
font-size: 30px;
text-decoration: none;
border: solid 2px #6E4E34;
border-radius: 5px;
padding: 10px;
font-family: "PT Sans", sans-serif;
}
<div id="ImageMain">
<div id="TextMain">
<h1>Shop our Whole Selection</h1>
Browse
</div>
</div>
Try this
#button {
color: #6E4E34;
font-size: 30px;
text-decoration: none;
border: solid 2px #6E4E34;
border-radius: 5px;
padding: 10px;
font-family: "PT Sans", sans-serif;
display: flex;
margin:0 auto;
justify-content: center;
width:100px;
}
Check it out
You have to set the align to center and the margin to auto. Just add the following enclosing div to your button.
<div style="margin:auto; width:200px;" align="center">
Browse
</div>
You just need to wrap your button in a block level element. You could use a <div> so your markup would be;
HTML
<div class="wrapper">
Browse
</div>
CSS
.wrapper #button {
text-align:center;
}