CSS media query and flex direction - html

I am following Traversy course on Udemy, i am less than a month in HTML CSS, so kind of a newbie. So in a section of the course he makes us do a website and in the last episodes he explains how to make it responsive for devices.
This is the problematic section on the html:
<!-- Section: Contact -->
<section id="contact">
<div class="contact-form bg-primary p-2">
<h2 class="m-heading">Contact Us</h2>
<p>Please use the form below to contact us</p>
<form action="">
<div class="form-group">
<label for="name">Name</label>
<input type="text" name="name" id="name" placeholder="Enter Name">
</div>
<div class="form-group">
<label for="email">E-mail</label>
<input type="email" name="email" id="email" placeholder="Enter E-mail">
</div>
<div class="form-group">
<label for="phone">Phone Number</label>
<input type="text" name="phone" id="phone" placeholder="Enter Phone Number">
</div>
<div class="form-group">
<label for="message">Message</label>
<textarea name="message" id="message" placeholder="Enter Message"></textarea>
</div>
<input type="sumbit" value="Send" class="btn btn-dark">
</form>
</div>
<div class="map"></div>
</section>
And this is what we did on the main css file:
/* Section: Contact */
#contact {
display: flex;
}
#contact .map, #contact .contact-form {
flex: 1;
}
#contact .contact-form .form-group {
margin: 0.75rem;
}
#contact .contact-form label {
display: block;
}
#contact .contact-form input,
#contact .contact-form textarea {
width: 100%;
padding: 0.5rem;
}
We had to make the map just go under the contact form on the mobile css sheet, but, put simply it worked only when he did it on his computer. on mine the map disappears XD:
#contact {
flex-direction: column;
}
#contact .map {
height: 200px;
}
I tried to workaround:
#contact {
flex-wrap: wrap;
}
#contact .contact-form {
display: block;
}
#contact .map {
display: block;
}
But the same thing happened. Suppose I'm not yet good enough to understand what is happening, let alone fix it myself XD

Just add:
#contact {
display: block;
flex-direction: column;
}

Related

Flex Layout not responding properly in reactJs

Currently what Im trying to achieve is this:
But I tried this using flex attribute but the layout is messed up. Here is my code for the same.
<div className="contact-container" style={{flexDirection:"row",backgroundColor:"#ECECEC"}}>
<div style={{padding:"30px"}}>
<div style={{flexDirection:"column"}}>
<p style={{color:"#0E2043",backgroundColor:"#ECECEC", fontSize:"22px",fontWeight:"700", textAlign:"justify"}}>If you are looking to enjoy exactly these benefits, Passport Legacy is here to assist you with your second citizenship. </p>
<p style={{color:"#0E2043", paddingTop:"30px",backgroundColor:"#ECECEC", textAlign:"justify"}}>If you would like more information about any of the qualifying programs, or our services, please do not hesitate to contact us.</p>
</div>
</div>
<div style={{padding:"30px"}}>
<div>
<div style={{padding:"5px"}}>
<input style={{padding:"5px", width:"100%"}} type="text" placeholder="Name"/>
</div>
<div style={{width:"100%",display:"flex", flexWrap:"wrap", justifyContent:"space-between"}}>
<div style={{padding:"5px"}}>
<input style={{padding:"5px",width:"100%"}} type="text" placeholder="email"/>
</div>
<div style={{padding:"5px"}}>
<input style={{padding:"5px",width:"100%"}} type="text" placeholder="phone"/>
</div>
</div>
<div style={{padding:"5px"}}>
<input style={{padding:"5px", width:"100%"}} type="text" placeholder="Subject"/>
</div>
<div style={{padding:"5px"}}>
<textarea style={{padding:"5px", width:"100%"}} rows="4" placeholder="Message"/>
</div>
</div>
</div>
</div>
Ive added a sandbox too, Please feel free to make changes.
https://codesandbox.io/s/divine-dawn-l27wy?file=/src/App.tsx:71-1766
Here is your code with a little changes, I made it responsive too for width less than 400px.
const App=()=>{
return(
<div className="contact-container" style={{backgroundColor:"#ECECEC"}}>
<div style={{padding:"30px"}}>
<div style={{flexDirection:"column"}}>
<p style={{color:"#0E2043",backgroundColor:"#ECECEC", fontSize:"22px",fontWeight:"700", textAlign:"justify"}}>If you are looking to enjoy exactly these benefits, Passport Legacy is here to assist you with your second citizenship. </p>
<p style={{color:"#0E2043", paddingTop:"30px",backgroundColor:"#ECECEC", textAlign:"justify"}}>If you would like more information about any of the qualifying programs, or our services, please do not hesitate to contact us.</p>
</div>
</div>
<div style={{padding:"30px"}}>
<div>
<div style={{padding:"5px"}}>
<input style={{padding:"5px", width:"100%"}} type="text" placeholder="Name"/>
</div>
<div style={{width:"100%",display:"flex", flexWrap:"wrap", justifyContent:"space-between"}}>
<div style={{padding:"5px"}}>
<input style={{padding:"5px",width:"100%"}} type="text" placeholder="email"/>
</div>
<div style={{padding:"5px"}}>
<input style={{padding:"5px",width:"100%"}} type="text" placeholder="phone"/>
</div>
</div>
<div style={{padding:"5px"}}>
<input style={{padding:"5px", width:"100%"}} type="text" placeholder="Subject"/>
</div>
<div style={{padding:"5px"}}>
<textarea style={{padding:"5px", width:"100%"}} rows="4" placeholder="Message"/>
</div>
</div>
</div>
</div>
)}
ReactDOM.render(
<App />,
document.getElementById("react")
);
.contact-container {
display: flex;
flex-direction: row;
}
.contact-container > div {
width:50%;
}
#media (max-width: 400px) {
.contact-container {
flex-direction: column;
}
.contact-container > div {
width:100%;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<div id="react"></div>
All you have to do is specify the "width" for the "div" on the left.
<div style={{padding:"30px", width:"50%"}}>
First of all it is not a ReactJS issue. It is just you are not configuring the flexbox propertly.
* {
margin: 0;
padding: 0;
outline: 0;
box-sizing: border-box;
}
body {
height: 100vh;
display: grid;
place-items: center;
}
.container {
width: 90%;
display: flex;
max-width: 500px;
flex-direction: column;
border: 1px solid red;
}
.container input,
.container textarea {
width: 100%;
padding: 0.75rem;
border: 1px solid #e5e5e5;
}
.container input {
margin-top: 1rem;
}
.container .flex {
display: flex;
justify-content: space-between;
}
.container .flex input:nth-child(2) {
margin-left: 1rem;
}
.container textarea {
display: block;
margin-top: 1rem;
}
<div class="container">
<form>
<input type="text" placeholder="Name" />
<div class="flex">
<input type="text" placeholder="Email">
<input type="text" placeholder="Phone">
</div>
<input type="text" placeholder="Subject">
<textarea id="" cols="20" rows="10"></textarea>
</form>
</div>
Let me know if this works? 😊

Label sticking next to another label

I am having a simple registration form, but one of the label fields sticks next to another label field.
Currently it looks like this:
Email should be under the Username, not next to it. Other form elements align nicely, but not these two.
label {
float: left;
}
input {
float: right;
}
<div class="form-wrapper">
<div>
<div>
<label for="user-name">Username:</label>
<input type="text" id="user-name" name="user-name" required>
</div>
<div>
<label for="user-email">Email:</label>
<input type="email" id="user-email" name="user-email" required>
</div>
</div>
</div>
Why don't you just use flex, clean and less code.
.form-wrapper {
width: 400px;
border: 1px solid blue;
}
.username,
.useremail {
display: flex;
margin: 10px;
width: 350px;
justify-content: space-between;
font-weight: bold;
}
<div class="form-wrapper">
<div>
<div class="username">
<label for="user-name">Username:</label>
<input type="text" id="user-name" name="user-name" required>
</div>
<div class="useremail">
<label for="user-email">Email:</label>
<input type="email" id="user-email" name="user-email" required>
</div>
</div>
</div>
If you are going with float you have to know about using clear property for it's next elements. So a best way to handle is, to create a after pseudo-element on the parent and clear:both.
In the below code have added 'field' class for each container and styled it with :after.
.field::after{
content: '';
display: block;
height: 0;
clear: both;
visibility: hidden;
}
label {
float: left;
}
input {
float: right;
}
<div class="form-wrapper">
<div>
<div class="field">
<label for="user-name">Username:</label>
<input type="text" id="user-name" name="user-name" required>
</div>
<div class="field">
<label for="user-email">Email:</label>
<input type="email" id="user-email" name="user-email" required>
</div>
</div>
</div>
Labels and input fields are stacked from the left and the right, resp., due to the css float properties. Note that the label/input pairs render on individual lines when removing the css, though without proper vertical alignment.
The CSS display: table property and friends can be employed to rectify this. Basically they cause the renderer to apply table layouting to elements other than tableand descendants.
.d-t {
display: table;
}
.d-tr {
display: table-row;
}
.d-tr > label, .d-tr > input {
display: table-cell;
}
<div class="form-wrapper">
<div class="d-t">
<div class="d-tr">
<label for="user-name">Username:</label>
<input type="text" id="user-name" name="user-name" required>
</div>
<div class="d-tr">
<label for="user-email">Email:</label>
<input type="email" id="user-email" name="user-email" required>
</div>
</div>
</div>

How can I get the input label to fade when I focus or select the input & can I also get the label to be inside the input?

I am trying to do 2 things here:
1) I want the label to change to a lighter shade of grey when the input is selected. However, I can't get all the labels to change color.
2) I want to put the label inside the input. However, I am more concerned about the first than the second, as by implementing the second one would cancel out the first one I believe. But it would be nice to know how to position a label inside an input.
I am using the CSS input:focus ~ label method however, this just selects the labels AFTER the input and I have the label before the input therefore the first label is not working for the fade.
How can I get all the labels to change color when an input is selected? I know I need to move the label after the input however, if I do that the label will show up underneath the input which is not where it is supposed to go.
I have tried position: absolute on the label but it just bunches them together, so I am not sure how to move them individually.
Here is the link to my codepen, I have two contact forms, one separated with divs the other is not.
https://codepen.io/RJorns/pen/MdmoRp
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css">
<div class="contact-wrapper">
<div class="contact-title"><h1>Contact</h1></div>
<form class="contact-form ui equal width form">
<div class="form-wrapper">
<label class="form-label">Name</label>
<input class="form-input" id="name" type="text" placeholder="Name" required>
</div>
<div class="form-wrapper">
<label class="form-label">Email</label>
<input class="form-input" id="email" type="text" placeholder="Email" required>
</div>
<label class="form-label">Message</label>
<div class="field">
<textarea rows="4" id="message" type="text" required></textarea>
</div>
<button id="submit" class="ui grey button">Submit</button>
</form>
</div>
<div class="contact-wrapper">
<div class="contact-title"><h1>Contact</h1></div>
<form class="contact-form ui equal width form">
<label class="form-label">Name</label>
<input class="form-input" id="name" type="text" placeholder="Name" required>
<label class="form-label">Email</label>
<input class="form-input" id="email" type="text" placeholder="Email" required>
<label class="form-label">Message</label>
<div class="field">
<textarea rows="4" id="message" type="text" required></textarea>
</div>
<button id="submit" class="ui grey button">Submit</button>
</form>
</div>
* {
padding: 0;
margin: 0;
box-sizing: border-box;
-webkit-font-smoothing: antialiased;
text-align: center;
}
/* Contact */
.contact-wrapper {
margin: 0 auto;
max-width: 75%;
}
.contact-title {
margin-bottom: 2em;
}
.contact-form {
display: flex;
flex-wrap: wrap;
flex-direction: column;
justify-content: center;
align-content: center;
}
input {
box-shadow: inset 0px 0px 13px -1px rgba(77, 77, 77, 1);
}
.form-label {
display: flex;
color: #515151;
}
input:focus ~ label {
color: #a0a0a0;
}
button {
margin-top: 5em;
}
I want the all the labels to show a lighter grey when it is focused.
I want to use CSS only but if I have to use JS that is fine.
I just moved the label after the input for label section from css and used the column reverse to move the label on top. Also added the transition on input focus. I hope this will work. Comment for more info.
* {
padding: 0;
margin: 0;
box-sizing: border-box;
-webkit-font-smoothing: antialiased;
text-align: center;
}
/* Contact */
.contact-wrapper {
margin: 0 auto;
max-width: 75%;
}
.contact-title {
margin-bottom: 2em;
}
.contact-form {
display: flex;
flex-wrap: wrap;
flex-direction: column;
justify-content: center;
align-content: center;
}
input {
box-shadow: inset 0px 0px 13px -1px rgba(77, 77, 77, 1);
}
.form-label {
display: flex;
color: #515151;
transition: all 0.4s ease-in;
}
input:focus ~ label {
color: #a0a0a0;
transition: all 0.4s ease-in;
}
.form-wrapper {
display: flex;
flex-direction: column-reverse;
}
button {
margin-top: 5em;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css">
<div class="contact-wrapper">
<div class="contact-title">
<h1>Contact</h1></div>
<form class="contact-form ui equal width form">
<div class="form-wrapper">
<input class="form-input" id="name" type="text" placeholder="Name" autocomplete="off" required>
<label class="form-label">Name</label>
</div>
<div class="form-wrapper">
<input class="form-input" id="email" type="text" placeholder="Email" autocomplete="off" required>
<label class="form-label">Email</label>
</div>
<label class="form-label">Message</label>
<div class="field">
<textarea rows="4" id="message" type="text" required></textarea>
</div>
<button id="submit" class="ui grey button">Submit</button>
</form>
</div>
<div class="contact-wrapper">
<div class="contact-title">
<h1>Contact</h1></div>
<form class="contact-form ui equal width form">
<div class="form-wrapper">
<input class="form-input" id="name" type="text" placeholder="Name" autocomplete="off" required>
<label class="form-label">Name</label>
</div>
<div class="form-wrapper">
<input class="form-input" id="email" type="text" placeholder="Email" autocomplete="off" required>
<label class="form-label">Email</label>
</div>
<label class="form-label">Message</label>
<div class="field">
<textarea rows="4" id="message" type="text" required></textarea>
</div>
<button id="submit" class="ui grey button">Submit</button>
</form>
</div>

How do I place two text fields side by side?

I am creating a form for a landing page, so I want to keep the text input field side by side so I don't make the form very long.I trying to do something like this :
But it seems really difficult right now, this is what my form current looks like:
.teaser-right {
float: right;
width: 45%;
margin: 3% 0 0 0
}
#calltoaction-form {
background: #f2f2f2;
padding-bottom: 10px;
width: 800px;
position: right;
bottom: 0
}
<div id="calltoaction-form" class="teaser-form">
<div class="form-title">
<h3>sample form</h3>
</div>
<form id="contact_form" action="_contact-us.php" method="post">
<div class="form-header">
<h4>Personal details</h4>
</div>
<div class="form-section">
<input id="name" name="name" type="text" placeholder="Your name">
</div>
<div class="form-section">
<input id="email" name="email" type="text" placeholder="Your email">
</div>
Add this to your CSS:
.form-section{
display:inline-block;
}
To put 2 input fields beside each other you can use of float. if you float the elements you need to make sure you use the clearfix hack on the parent div. Otherwise the parent div won't have a height.
Another option is to use display: inline-block If you use display inline-block you need to reset the font-size on the parent to 0. The elements that where you use display: inline-block need to get the font-size: 12px; for example. With display inline-block you can get a slight height difference.
Example:
float: left;
https://jsfiddle.net/ymma61hu/3/
Clearfix hack:
https://css-tricks.com/snippets/css/clear-fix/
Example 2:
display: inline-block;
https://jsfiddle.net/vh49gtzL/
Hi just put input elements inside same div see fiddle. https://jsfiddle.net/v5omym1a/
<div id="calltoaction-form" class="teaser-form">
<div class="form-title">
<h3>sample form</h3>
</div>
<form id="contact_form" action="_contact-us.php" method="post">
<div class="form-header">
<h4>Personal details</h4>
</div>
<div class="form-section">
<input id="name" name="name" type="text" placeholder="Your name">
<input id="email" name="email" type="text" placeholder="Your email">
</div>
I cleaned up your markup a bit. You don't need to wrap your <h3> and <h4> in div-s - those are block level elements as well and can be perfectly styled.
#calltoaction-form {
background: #f2f2f2;
padding-bottom: 10px;
width: 800px;
position: right;
bottom: 0;
overflow: hidden;
}
.form-section {
float: left;
width: 50%;
}
label {
display: block;
margin-bottom: .25em;
}
<div id="calltoaction-form" class="teaser-form">
<h3 class="form-title">sample form</h3>
<form id="contact_form" action="_contact-us.php" method="post">
<h4 class="form-header">Personal details</h4>
<div class="form-section">
<label for="name">Name</label>
<input id="name" name="name" type="text" placeholder="Your name">
</div>
<div class="form-section">
<label for="email">Email</label>
<input id="email" name="email" type="text" placeholder="Your email">
</div>
</form>
</div>
.form-section {
float: left;
margin: 1%;
width: 48.5%;
}
.form-section input {
width: 100%;
}
.form-section:first-child {
margin-left: 0;
}
.form-section:last-child {
margin-right: 0;
}
#calltoaction-form {
background: #f2f2f2;
padding-bottom: 10px;
width: 100%;
position: right;
bottom: 0
}
<div id="calltoaction-form" class="teaser-form">
<div class="form-title">
<h3>sample form</h3>
</div>
<form id="contact_form" action="_contact-us.php" method="post">
<div class="form-header">
<h4>Personal details</h4>
</div>
<div class="form-container">
<div class="form-section">
<input id="name" name="name" type="text" placeholder="Your name">
</div>
<div class="form-section">
<input id="email" name="email" type="text" placeholder="Your email">
</div>
</div>

Finding it hard to align login interface

I am really finding it hard to center the interface, so every element is aligned. I have 'Email', 'Password' and the 'Login button'. I was trying to use absolute positioning but when I move the input field it covers the word 'Email', or 'Password' and I want the user to see those words. The functionality is working, working with rails.
Here is my code for HTML and CSS:
h1 {
text-align: center;
margin-top: 350px;
font-size: 45px;
}
.field {
text-align: center;
}
#field {
text-align: center;
padding: 25px;
}
input {
height: 35px;
width: 200px;
display: inline;
}
.actions {
text-align: center;
}
h1 {
font-family: 'Lobster', cursive;
}
<nav>
<ul>
<li>
campus
</li>
<li>
classrooms
</li>
<li>
courses
</li>
<li>
users
</li>
</ul>
</nav>
Sign Up or
Log In
<h1>Log in</h1>
<form accept-charset="UTF-8" action="/sessions" method="post">
<div style="margin:0;padding:0;display:inline">
<input name="utf8" type="hidden" value="✓">
<input name="authenticity_token" type="hidden" value="ALrA11a6G5GZof0r/AMm82stLUUzaI+UTPEoB79yXrc=">
</div>
<div class="field">
<label for="email">Email</label>
<input id="email" name="email" type="text">
</div>
<div id="field">
<label for="password">Password</label>
<input id="password" name="password" type="password">
</div>
<div class="actions">
<input name="commit" type="submit" value="Log in">
</div>
</form>
I changed id on the second field to a class. It will make your code easier to maintain.
html:
<form accept-charset="UTF-8" action="/sessions" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"><input name="authenticity_token" type="hidden" value="ALrA11a6G5GZof0r/AMm82stLUUzaI+UTPEoB79yXrc="></div>
<div class="field">
<label for="email">Email</label>
<input id="email" name="email" type="text">
</div>
<div class="field">
<label for="password">Password</label>
<input id="password" name="password" type="password">
</div>
<div class="actions"><input name="commit" type="submit" value="Log in"></div>
css:
h1 {
text-align: center;
margin-top: 50px;
font-size: 45px;
font-family: 'Lobster', cursive;
}
input {
height: 35px;
width: 200px;
display: inline;
}
.field {
padding-bottom: 25px;
width: 300px;
margin: 0 auto;
}
.field label {
display: inline-block;
min-width: 70px;
text-align: left;
}
.actions {
text-align: center;
margin: 0 auto;
width: 300px;
}
And here is a jsfiddle showing it in action: http://jsfiddle.net/t9w757hj/