Flex Layout not responding properly in reactJs - html

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? 😊

Related

Flexbox form width does not change

I am trying to get a form's inputs to fill the container width but since I am using two flexboxes, it doesn't seem to allow me to set the width of the input boxes. Is there a way around this? I've tried using flex-shrink but got the same result.
What is the best way to set a form's width to fill its container using flexbox?
.sd-form-group {
display: flex;
flex-flow: column nowrap;
justify-content: center;
align-items: flex-start;
}
.sd-form-wrap {
display: flex;
}
.sd-form-group input[type=text],
.sd-form-group textarea {
width: 100%;
}
<form>
<div class="sd-form-group">
<div class="sd-form-wrap">
<div class="form-name form-first-name">
<label>First Name</label>
<br>
<input type="text">
</div>
<div class="form-name form-last-name">
<label>Last Name</label>
<br>
<input type="text">
</div>
</div>
<div class="form-email">
<label>Email</label>
<br>
<input type="text">
</div>
<div class="form-message">
<label>Message</label>
<br>
<textarea placeholder="Enter your comments, questions and feedback here." rows="4"></textarea>
</div>
<div class="form-checkbox">
<input type="checkbox">
<label>
Communications box
</label>
</div>
<input type="submit" value="Submit">
</div>
</form>
On the container, instead of flex-flow: column nowrap use row wrap.
On the items, force each one to occupy the full width of the row.
.sd-form-group {
display: flex;
/* flex-flow: column nowrap; */
flex-wrap: wrap; /* new */
justify-content: center;
/* align-items: flex-start; */ /* does nothing */
}
.sd-form-group > div {
flex: 0 0 100%; /* new */
}
.sd-form-wrap {
display: flex;
}
.sd-form-group input[type=text],
.sd-form-group textarea {
width: 100%;
}
<form>
<div class="sd-form-group">
<div class="sd-form-wrap">
<div class="form-name form-first-name">
<label>First Name</label>
<br>
<input type="text">
</div>
<div class="form-name form-last-name">
<label>Last Name</label>
<br>
<input type="text">
</div>
</div>
<div class="form-email">
<label>Email</label>
<br>
<input type="text">
</div>
<div class="form-message">
<label>Message</label>
<br>
<textarea placeholder="Enter your comments, questions and feedback here." rows="4"></textarea>
</div>
<div class="form-checkbox">
<input type="checkbox">
<label>
Communications box
</label>
</div>
<input type="submit" value="Submit">
</div>
</form>

CSS media query and flex direction

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;
}

Border Disappears on Zoom Out/in In all Browser

I am working on a project with different browsers.
I am having a table with borders and when I zoom out my page border disappears.
This happens in all browsers like IE, EDGE, and Chrome Browser.
Is it the DOM structure problem?
It needs to supports with zoom level 75% to 125%. To be specific set zoom to 67% in Chrome and see the change
Please provide the possible solution to this question.
.mEditor {
display: flex;
border-bottom: 1px solid #d7d7d7;
}
.m-label {
width: 30%;
display: flex;
background-color: #f2f2f2;
}
.m-editor-noc {
flex: 1;
display: flex;
background-color: #FFFFFF;
border-left: 1px solid #d7d7d7;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.mfEditor {
display: flex;
flex: 1 0 auto;
}
.mEditor-li {
vertical-align: middle;
border-left: 1px solid #d7d7d7;
height: 18px;
display: inline-block;
margin-top: 3px;
}
.mEditor .tEditor {
border: none;
flex: 1;
padding-right: 6px;
}
<div class="m-group">
<div id="id251" class="mEditor">
<div class="m-label">
<label for="id223" title="Address">Address</label>
</div>
<div class="m-editor-noc">
<div id="id252" class="mfEditor">
<input type="text" class="tEditor" value="Address" name="" id="id223" maxlength="255" tabindex="0">
</div>
<div class="editor-links"></div>
</div>
</div>
<div id="id254" class="mEditor">
<div class="m-label">
<label for="id224" title="Address 2">Address 2</label>
</div>
<div class="m-editor-noc">
<div id="id255" class="mfEditor">
<input type="text" class="tEditor" value="16" name="" id="id224" maxlength="30" tabindex="0">
</div>
<div class="editor-links"></div>
</div>
</div>
<div id="id257" class="mEditor">
<div class="m-label">
<label for="id225" title="Postcode">Postcode</label>
</div>
<div class="m-editor-noc">
<div id="id258" class="mfEditor">
<input type="text" class="tEditor" value="Post Code" name="" id="id225" maxlength="10" tabindex="0">
</div>
<div class="editor-links"></div>
</div>
</div>
<div id="id25a" class="mEditor ">
<div class="m-label">
<label for="id20f" title="City">City</label>
</div>
<div class="m-editor-noc">
<div id="id25b" class="mfEditor">
<input type="text" class="tEditor" value="City" name="" id="id20f" autocomplete="off" maxlength="50" tabindex="0">
</div>
<div class="editor-links">
</div>
</div>
</div>
<div id="id25d" class="mEditor">
<div class="m-label">
<label for="id228" title="District">District</label>
</div>
<div class="m-editor-noc">
<div id="id25e" class="mfEditor">
<input type="text" class="tEditor" value="" name="" id="id228" maxlength="100" tabindex="0">
</div>
<div class="editor-links"></div>
</div>
</div>
<div id="id260" class="mEditor ">
<div class="m-label">
<label for="id210" title="Country">Country</label>
</div>
<div class="m-editor-noc">
<div id="id261" class="mfEditor">
<input type="text" class="tEditor" value="Country" name="" id="id210" autocomplete="off" maxlength="50" tabindex="0">
</div>
<div class="editor-links">
</div>
</div>
</div>
</div>
If by "We supporting all browser and Zoom level 75% - 125%" you mean you want a border to have the same size in actual pixels regardless of zoom level, you're out of luck. It's not technically possible.
You should only develop for zoom level of 100%.
There is no reliable cross-browser method to know the zoom level, which means this information is not available inside your Window object, so you can't use it to adjust values of properties on your elements.
As a fallback, you could just make the border thicker, so it will be visible even when zoomed. Now it's not displayed because it probably gets a sub-pixel size and estimated by the browser into non-renderable.
Do note everything you that's rendered at zoom levels other than 100% is entirely at the whim of how each browser internally chooses to estimate and render, which you:
have no control on
could change without notice.
In other words, your initial statement should have a minor footnote:
* Within reasonable limits. Rendering while zoomed is browser dependent.
I encountered a similar issue with border disappearing. This answer was extremely helpful to me. Draw borders by pseudo-elements. The solution for your case could be like:
.mEditor {
display: flex;
/*border-bottom: 1px solid #d7d7d7; <- REMOVE */
position: relative; /* <- ADD */
}
.mEditor::after{ /* <- ADD */
content: "";
position: absolute;
top:0;
bottom:0;
right:0;
left:0;
border-bottom: 1px solid #d7d7d7;
}
.m-label {
width: 30%;
display: flex;
background-color: #f2f2f2;
}
.m-editor-noc {
flex: 1;
display: flex;
background-color: #FFFFFF;
/*border-left: 1px solid #d7d7d7; <- REMOVE */
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
position: relative; /* <- ADD */
}
.m-editor-noc::after{ /* <- ADD */
content: "";
position: absolute;
top:0;
bottom:0;
right:0;
left:0;
border-left: 1px solid #d7d7d7;
}
.mfEditor {
display: flex;
flex: 1 0 auto;
}
.mEditor-li {
vertical-align: middle;
border-left: 1px solid #d7d7d7;
height: 18px;
display: inline-block;
margin-top: 3px;
}
.mEditor .tEditor {
border: none;
flex: 1;
padding-right: 6px;
}
<div class="m-group">
<div id="id251" class="mEditor">
<div class="m-label">
<label for="id223" title="Address">Address</label>
</div>
<div class="m-editor-noc">
<div id="id252" class="mfEditor">
<input type="text" class="tEditor" value="Address" name="" id="id223" maxlength="255" tabindex="0">
</div>
<div class="editor-links"></div>
</div>
</div>
<div id="id254" class="mEditor">
<div class="m-label">
<label for="id224" title="Address 2">Address 2</label>
</div>
<div class="m-editor-noc">
<div id="id255" class="mfEditor">
<input type="text" class="tEditor" value="16" name="" id="id224" maxlength="30" tabindex="0">
</div>
<div class="editor-links"></div>
</div>
</div>
<div id="id257" class="mEditor">
<div class="m-label">
<label for="id225" title="Postcode">Postcode</label>
</div>
<div class="m-editor-noc">
<div id="id258" class="mfEditor">
<input type="text" class="tEditor" value="Post Code" name="" id="id225" maxlength="10" tabindex="0">
</div>
<div class="editor-links"></div>
</div>
</div>
<div id="id25a" class="mEditor ">
<div class="m-label">
<label for="id20f" title="City">City</label>
</div>
<div class="m-editor-noc">
<div id="id25b" class="mfEditor">
<input type="text" class="tEditor" value="City" name="" id="id20f" autocomplete="off" maxlength="50" tabindex="0">
</div>
<div class="editor-links">
</div>
</div>
</div>
<div id="id25d" class="mEditor">
<div class="m-label">
<label for="id228" title="District">District</label>
</div>
<div class="m-editor-noc">
<div id="id25e" class="mfEditor">
<input type="text" class="tEditor" value="" name="" id="id228" maxlength="100" tabindex="0">
</div>
<div class="editor-links"></div>
</div>
</div>
<div id="id260" class="mEditor ">
<div class="m-label">
<label for="id210" title="Country">Country</label>
</div>
<div class="m-editor-noc">
<div id="id261" class="mfEditor">
<input type="text" class="tEditor" value="Country" name="" id="id210" autocomplete="off" maxlength="50" tabindex="0">
</div>
<div class="editor-links">
</div>
</div>
</div>
</div>

Why div are not aligned horizontally

I am trying to align 2 divs horizontally inside one div.
Here is codepen link Check Here. When I add margin-top to left div it is not moving up.
What am I doing wrong?
<footer id="contact">
<div class="reservation" style="display: block;border:1px solid red; ">
<div class="reserve-address-div" style="display: inline-block;width:45%;border:1px solid red;margin-top:-40px;">
<h4>51 Area, Barmuda Triangle, Mars</h4>
<h4>0165466546</h4>
<h4>vivek.tarun17#gmail.com</h4>
</div>
<div class="reserve-booking-div" style="display: inline-block; width:45%;border:1px solid red; ">
<form>
<input type="text" name="name" placeholder="Name" /><br>
<input type="email" name="email" placeholder="Email"/><br>
<input type="text" name="subject" placeholder="Subject"/><br>
<textarea placeholder="message" rows="5"></textarea><br>
<input type="button" value="Submit">
</form>
</div>
</div>
</footer>
Please try to use vertical-align: top something like this:
<div class="reservation">
<div class="reserve-address-div" style="display: inline-block; ... vertical-align:top">
...
</div>
<div class="reserve-booking-div" style="display: inline-block; ... vertical-align:top">
...
vertical-align property is useful.
You can put inline-blocks along with the top of parent element, e.g., div.
The reason .reserve-address-div is being pushed down is because the default vertical-align value is set to baseline. As another poster mentioned, setting the vertical-align property to top for .reserve-address-div will remove the space above that div.
You can read more about the issue here.
An alternate solution would be to use flexbox on the .reservation container, as I've demonstrated in the snippet below.
Hope this helps!
.reservation {
border: 1px solid red;
display: flex;
align-content: center;
justify-content: center;
width: 100%;
}
.reserve-address-div {
display: inline-block;
width: 45%;
border: 1px solid red;
}
.reserve-booking-div {
display: inline-block;
width: 45%;
border: 1px solid red;
}
<footer id="contact">
<div class="reservation">
<div class="reserve-address-div">
<h4>51 Area, Barmuda Triangle, Mars</h4>
<h4>0165466546</h4>
<h4>vivek.tarun17#gmail.com</h4>
</div>
<div class="reserve-booking-div">
<form>
<input type="text" name="name" placeholder="Name" /><br>
<input type="email" name="email" placeholder="Email" /><br>
<input type="text" name="subject" placeholder="Subject" /><br>
<textarea placeholder="message" rows="5"></textarea><br>
<input type="button" value="Submit">
</form>
</div>
</div>
</footer>
How about the Flexbox solution:
.reservation {
display: flex;
padding: 2.5px;
border: 1px solid red;
}
.reserve-address-div, .reserve-booking-div {
flex: 1;
margin: 2.5px;
padding: 5px;
border: 1px solid red;
}
<footer id="contact">
<div class="reservation">
<div class="reserve-address-div">
<h4>51 Area, Barmuda Triangle, Mars</h4>
<h4>0165466546</h4>
<h4>vivek.tarun17#gmail.com</h4>
</div>
<div class="reserve-booking-div">
<form>
<input type="text" name="name" placeholder="Name"><br>
<input type="email" name="email" placeholder="Email"><br>
<input type="text" name="subject" placeholder="Subject"><br>
<textarea placeholder="message" rows="5"></textarea><br>
<input type="button" value="Submit">
</form>
</div>
</div>
</footer>
Adjust margins and padding to your needs.

Making the textarea to take up full width in css table layout

I'm having trouble making a form using tables. I'm trying to make the <textarea> comment box row take up the full width. The problem is unknown to me, as I don't know why it won't work.
.full_width {
width: 100%
}
.table {
display: table; width: 100%;
}
.table_row {
display: table-row; width: 100%;
}
.table_cell {
display: table-cell
}
.label {
display: block
}
.two_cell
{
width: 48%;
}
#company_cell
{
padding-left: 4%;
}
.table_cell {
padding-bottom: 18px
}
<form class="table" method="post">
<div class="table_row">
<div class="table_row full_width">
<div class="table_cell">
<span>Name</span>
<input name="name" class="full_width" type="text" value=""/>
</div>
<div class="table_cell">
<span>Company</span>
<input name="company" class="full_width" type="text" value=""/>
</div>
</div>
</div>
<div class="table_row">
<div class="table_row full_width">
<div class="table_row">
<span>Comment</span>
</div>
<div class="table_row full_width">
<textarea name="comment" class="full_width" value="SEND"></textarea>
</div>
</div>
</div>
</form>
Here is the fiddle I'm playing around with https://jsfiddle.net/bpo7tujp/
The nature of your nested markup isn't wholly valid- in addition the logic conflicts somewhat.
Solution 1: table-caption
What you are effectively after is a CSS version of colspan, you can achieve this by changing your HTML to that below, and implementing table-caption
.full_width {
width: 100%
}
.table {
display: table;
width: 100%;
}
.table_row {
display: table-row;
width: 100%;
}
.table_cell {
display: table-cell
}
.label {
display: block
}
.two_cell {
width: 48%;
}
#company_cell {
padding-left: 4%;
}
.table_cell {
padding-bottom: 18px
}
.table_caption {
display: table-caption;
caption-side: bottom;
}
<form class="table" method="post">
<div class="table_row">
<div class="table_cell">
<span>Name</span>
<input name="name" class="full_width" type="text" value="" />
</div>
<div class="table_cell">
<span>Company</span>
<input name="company" class="full_width" type="text" value="" />
</div>
</div>
<div class="table_caption">
<span>Comment</span>
<br />
<textarea name="comment" class="full_width" value="SEND"></textarea>
</div>
</form>
Solution 2 (advised): No tables
With that said, you would be far better not using tables for layouting, as evidenced by how simple it is to create the same:
.column {
float: left;
width: 50%;
}
input,
textarea {
width: 100%;
}
<div class="columns">
<div class="column">
<span>Name</span>
<input name="name" class="full_width" type="text" value="" />
</div>
<div class="column">
<span>Company</span>
<input name="company" class="full_width" type="text" value="" />
</div>
</div>
<span>Comment</span>
<textarea name="comment" class="full_width" value="SEND"></textarea>