JSFiddle - React, Tailwind, and code Playground
by dshilkret
HTML
<div class="form-container">
<div class="form-header">
<h2>General Information</h2>
</div>
<form class="form-body">
<div class="form-row">
<div class="form-group half">
<label for="taskName">Task/Request Name</label>
<input type="text" id="taskName" name="taskName" placeholder="Enter the task name">
</div>
<div class="form-group half">
<label for="suspenseDate">Suspense Date</label>
<input type="text" id="suspenseDate" name="suspenseDate" placeholder="mm/dd/yyyy" onfocus="(this.type='date')" onblur="(this.type='text')">
</div>
</div>
<!-- Other form groups can go here -->
<div class="form-group">
<button type="submit" class="submit-button">Submit</button>
</div>
</form>
</div>
CSS
.form-container {
max-width: 800px; /* Adjust the width as necessary */
margin: auto;
border: 1px solid #ddd;
border-radius: 8px;
overflow: hidden;
font-family: Arial, sans-serif;
}
.form-header {
background-color: #f5f5f5;
padding: 15px;
text-align: center;
border-bottom: 1px solid #ddd;
}
.form-header h2 {
margin: 0;
color: #333;
font-size: 18px;
}
.form-body {
padding: 20px;
}
.form-row {
display: flex;
justify-content: space-between;
flex-wrap: wrap; /* Ensure wrapping if the content is too wide */
}
.form-group {
margin-bottom: 15px;
flex: 1; /* Flex-grow to fill the space */
}
.form-group.half {
flex-basis: calc(50% - 10px); /* Set the base width and subtract the margin */
margin-right: 20px; /* Add margin between the two elements */
}
.form-group.half:last-child {
margin-right: 0;
}
label {
display: block;
margin-bottom: 5px;
color: #666;
}
input[type="text"],
input[type="date"],
select {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
input[type="date"]::-webkit-calendar-picker-indicator {
opacity: 0.5;
position: absolute;
right: 10px;
}
input[type="text"]:focus,
input[type="date"]:focus,
select:focus {
outline: none;
border-color: #5c92d1;
}
.submit-button {
width: 100%;
padding: 10px 15px;
border: none;
border-radius: 4px;
background-color: #5c92d1;
color: white;
cursor: pointer;
font-size: 16px;
}
.submit-button:hover {
background-color: #3e70a8;
}
/* Responsive adjustments */
@media (max-width: 768px) {
.form-row {
flex-direction: column;
}
.form-group.half {
flex-basis: 100%;
margin-right: 0;
}
}