I have a problem. CSS isn't my favorite part of coding and I can't figure this out. I need the following result:
But here is what I have now:
#newOrderControl {
border-style: solid;
border-color: black;
border-width: 1px;
width: min-content;
font-size: 14px;
}
#newOrderInputFields {
display: grid;
grid-template-columns: auto auto auto auto;
column-gap: 40px;
}
#newOrderInputFields .inputField {
display: flex;
align-items: center;
flex-direction: row;
}
#newOrderInputFields label {
width: auto;
}
#newOrderButtons button {
float: right;
border-style: solid;
border-color: black;
border-width: 2px;
color: white;
height: 30px;
width: auto;
padding: 0px 15px;
text-align: center;
text-decoration: none;
font-size: 16px;
border-radius: 10px;
margin: 0px 5px;
}
.btnAll {
background-color: #6DA0ED;
border-style: solid;
border-color: black;
border-width: 1px;
color: white;
border-radius: 5px;
}
#btnTakeProfit {
background-color: #33AB37;
}
#btnPlaceOrder {
background-color: #6DA0ED;
}
.title {
display: block;
text-align: center;
color: #1D0F73;
font-size: 22px;
font-weight: bold;
margin: 5px;
}
<div id="newOrderControl">
<label class="title">New order</label>
<div id="newOrderInputFields">
<div class="inputField">
<label>Action:</label>
<select id="txtOrderAction">
<option value="">-</option>
<option value="Buy">Buy</option>
<option value="Sell">Sell</option>
</select>
</div>
<div class="inputField">
<label>Quantity:</label>
<div>
<input type="text" id="txtOrderQuantity">
<button class="btnAll" onclick="setAllQuantity()">All</button>
</div>
</div>
<div class="inputField">
<label>Target price:</label>
<input type="text" id="txtOrderTargetPrice">
</div>
<div class="inputField">
<label>Target perc:</label>
<input type="text" id="txtOrderTargetPerc">
</div>
<div class="inputField">
<label>Coin:</label>
<select id="txtOrderCoin">
<option value="">-</option>
</select>
</div>
<div class="inputField">
<label>Amount:</label>
<div>
<input type="text" id="txtOrderAmount">
<button class="btnAll" onclick="setAllAmount()">All</button>
</div>
</div>
<div class="inputField">
<label>Limit price:</label>
<input type="text" id="txtOrderLimitPrice">
</div>
<div class="inputField">
<label>Limit perc:</label>
<input type="text" id="txtOrderLimitPerc">
</div>
</div>
<div id="newOrderButtons">
<button id="btnTakeProfit">Take profit</button>
<button id="btnPlaceOrder">Place order</button>
</div>
</div>
With this code I currently have the following problems:
My All button isn't next to the input field
The 2 buttons below are outside the newOrderControl div
The labels are being wrapped to the next line
All inputs and labels need to be aligned below each other like a grid
Now I have tried to change it to a grid, but then I was struggling with the input and button that are next to each other. So I wrapped them in a div, but then they completely disappear.
What do I need to do to get the result?
(1) Removing the wrapper <div> in below code will automatically align the input and buttons by the power of flexbox.
<div>
<input type="text" id="txtOrderQuantity">
<button class="btnAll" onclick="setAllQuantity()">All</button>
</div>
(2) First rule: do not use float for layout.
I've added:
#newOrderControl {
display: flex;
flex-direction: column;
So that buttons can be aligned to the right with
#newOrderInputFields label {
width: auto;
}
(3) Applying flex-shrink: 0; will prevent the <label> from wrapping. I've changed the width of container to width: max-content; and reduced gap to compensate for it.
(4) added justify-content: flex-end; to align them:
#newOrderInputFields .inputField {
display: flex;
flex-direction: row;
justify-content: flex-end;
#newOrderControl {
display: flex;
align-items: center;
flex-direction: column;
border-style: solid;
border-color: black;
border-width: 1px;
width: max-content;
font-size: 14px;
}
#newOrderInputFields {
display: grid;
grid-template-columns: auto auto auto auto;
column-gap: 5px;
}
#newOrderInputFields .inputField {
display: flex;
flex-direction: row;
justify-content: flex-end;
align-items: center;
}
#newOrderInputFields label {
width: auto;
flex-shrink: 0;
}
#newOrderButtons {
align-self: flex-end;
}
#newOrderButtons button {
float: right;
border-style: solid;
border-color: black;
border-width: 2px;
color: white;
height: 30px;
width: auto;
padding: 0px 15px;
text-align: center;
text-decoration: none;
font-size: 16px;
border-radius: 10px;
margin: 0px 5px;
}
.btnAll {
background-color: #6DA0ED;
border-style: solid;
border-color: black;
border-width: 1px;
color: white;
border-radius: 5px;
}
#btnTakeProfit {
background-color: #33AB37;
}
#btnPlaceOrder {
background-color: #6DA0ED;
}
.title {
display: block;
text-align: center;
color: #1D0F73;
font-size: 22px;
font-weight: bold;
margin: 5px;
}
<div id="newOrderControl">
<label class="title">New order</label>
<div id="newOrderInputFields">
<div class="inputField">
<label>Action:</label>
<select id="txtOrderAction">
<option value="">-</option>
<option value="Buy">Buy</option>
<option value="Sell">Sell</option>
</select>
</div>
<div class="inputField">
<label>Quantity:</label>
<input type="text" id="txtOrderQuantity">
<button class="btnAll" onclick="setAllQuantity()">All</button>
</div>
<div class="inputField">
<label>Target price:</label>
<input type="text" id="txtOrderTargetPrice">
</div>
<div class="inputField">
<label>Target perc:</label>
<input type="text" id="txtOrderTargetPerc">
</div>
<div class="inputField">
<label>Coin:</label>
<select id="txtOrderCoin">
<option value="">-</option>
</select>
</div>
<div class="inputField">
<label>Amount:</label>
<input type="text" id="txtOrderAmount">
<button class="btnAll" onclick="setAllAmount()">All</button>
</div>
<div class="inputField">
<label>Limit price:</label>
<input type="text" id="txtOrderLimitPrice">
</div>
<div class="inputField">
<label>Limit perc:</label>
<input type="text" id="txtOrderLimitPerc">
</div>
</div>
<div id="newOrderButtons">
<button id="btnTakeProfit">Take profit</button>
<button id="btnPlaceOrder">Place order</button>
</div>
</div>
Related
when i try to scroll the form the form-row content overlap on the navigation.
i am trying to make a form using bootstrap. but when i am adding a form-row or grid element for horizontal fields, the content or that form-row block overlap on my navigation panel on scrolling.
how can i make my form blocks below my navigation on scrolling.
body{
width:100%;
position: relative;
background-color: aliceblue;
display: flex;
margin: 0;
padding: 0;
}
#menu {
background-color: rgb(1, 9, 54);
width:300px;
height: 100%;
position: fixed;
top: 0;
left: 0;
}
#menu .logo{
display: flex;
align-items: center;
color: aliceblue;
padding: 30px 0 0 30px;
justify-content: flex-start;
}
#menu .logo img {
width: 60px;
margin-right: 15px;
border-radius: 50%;
}
#menu .items {
margin-top: 40px;
}
#menu .items li {
list-style-type: none;
padding: 15px 0;
transition: 0.3s ease;
}
#menu .items li:hover{
background: #254893;
cursor: pointer;
}
#menu .items li:nth-child(1){
border-left: 4px solid white;
}
#menu .items li i{
color: blanchedalmond;
width: 30px;
height: 30px;
line-height: 30px;
text-align: center;
font-size: 16px;
margin: 0 16px 0 25px;
}
#menu .items li:hover i,
#menu .items li:hover a {
color : #f3f4f6;
}
#menu .items li a{
text-decoration: none;
color: rgb(134, 141, 151);
font-weight: 300px;
transition: 0.3s ease;
}
#interface {
width: calc(100% - 300px);
margin-left: 300px;
position: relative;
}
#interface .navigation {
display: flex;
align-items: center;
justify-content: space-between;
background: #fff;
padding: 15px 30px;
border-bottom: 3px solid blue;
position: fixed;
width: calc(100% - 300px);
}
#interface .navigation .search {
display: flex;
justify-content: flex-start;
align-items: center;
padding: 10px 14px;
border: 1px solid #d7dbe6;
border-radius: 4px;
}
#interface .navigation .search input {
border: none;
outline: none;
font-size: 14px;
}
#interface .navigation .search i {
margin-right: 14px;
}
#interface .navigation .profile {
display: flex;
justify-content: flex-start;
align-items: center;
margin-right: 25px;
}
#interface .navigation .profile i {
margin-right: 20px;
font-size: 19px;
font-weight: 400;
}
#interface .navigation .profile img{
width: 30px;
height: 30px;
object-fit: cover;
border-radius: 50%;
}
.i-name {
color: #444a53;
padding: 30px 30px 0 30px;
font-size: 24px;
font-weight: 700;
margin-top: 70px;
}
.values {
padding: 30px 30px 0 30px;
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
}
.values .val-box {
background: #f3f4f6;
width: 235px;
padding: 16px 20px;
border-radius: 5px;
display: flex;
justify-content: flex-start;
align-items: center;
}
.values .val-box i {
font-size: 25px;
width: 60px;
height: 60px;
line-height: 60px;
border-radius: 50%;
text-align: center;
color: #fff;
background-color: #254893;
margin-right: 15px;
}
.values .val-box i:nth-child(1) {
background-color: rgb(3, 114, 114);
}
.values .val-box i:nth-child(2) {
background-color:rgb(80, 231, 181);
}
.values .val-box i:nth-child(3) {
background-color: cadetblue;
}
.values .val-box h3 {
font: 18px;
font-weight: 600px;
}
.values .val-box span {
font: 15px;
color: #444a53;
}
#interface .fbuttons {
margin-left: 25px;
}
and here is the html code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css"/>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://kit.fontawesome.com/f8bc328439.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>
<body>
<section id="menu">
<div class="logo">
<img src="profile-pic.png" alt="" class="">
<h2>Farmer</h2>
</div>
<div class="items">
<li><i class="fas fa-home"></i>Home</li>
<li><i class="fas fa-user"></i>Add/Modify Farmer</li>
<li><i class="fas fa-chart-bar"></i>Check Details</li>
<li><i class="fas fa-tasks"></i>Store</li>
<li><i class="fas fa-infinity"></i>Buyback</li>
<li><i class="fas fa-sign-out-alt"></i>Logout</li>
</div>
</section>
<section id="interface">
<div class="navigation">
<div class="n1">
<div class="search">
<i class="fas fa-search"></i>
<input type="text" placeholder="search">
</div>
</div>
<div class="profile">
<i class="fas fa-bell"></i>
<img src="profile-pic.png" alt="">
</div>
</div>
<h3 class="i-name">Add/modify farmer</h3>
<div class="fbuttons">
<button class="btn btn-danger">REGISTER A NEW FARMER</button>
<button style="margin-left: 10px" class="btn btn-danger" >MODIFY FARMER DETAILS</button>
</div>
<div class="container"style="margin: 10px 0 500px 10px;">
<form>
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" id="">
</div>
<div class="form-row">
<div class="form-group col-md-5">
<label for="aadhar">Aadhar Number</label>
<input type="number" class="form-control" id="">
</div>
<div class="form-group col-md-5">
<label for="mobileno">Mobile number</label>
<input type="number" class="form-control" id="inputPassword4">
</div>
</div>
<div class="form-group">
<label for="inputAddress">Address</label>
<input type="text" class="form-control" id="inputAddress" >
</div>
<div class="form-row">
<div class="form-group col-md-4">
<label for="inputVillage">Village</label>
<input type="text" class="form-control" id="inputVillage">
</div>
<div class="form-group col-md-3">
<label for="inputVillage">Taluka</label>
<input type="text" class="form-control" id="inputVillage">
</div>
<div class="form-group col-md-3">
<label for="inputDistrict">District</label>
<select id="inputDistricts" class="form-control">
<option selected>Choose...</option>
<option></option>
</select>
</div>
<div class="form-group col-md-2">
<label for="inputPincode">Pincode</label>
<input type="number" class="form-control" id="inputPincode">
</div>
</div>
<h4> Farm Details </h4>
<div class="form-group">
<label for="inputAddress">Address</label>
<input type="text" class="form-control" id="inputAddress" >
</div>
<div class="form-row">
<div class="form-group col-md-4">
<label for="inputVillage">Village</label>
<input type="text" class="form-control" id="inputVillage">
</div>
<div class="form-group col-md-3">
<label for="inputVillage">Taluka</label>
<input type="text" class="form-control" id="inputVillage">
</div>
<div class="form-group col-md-3">
<label for="inputDistrict">District</label>
<select id="inputDistricts" class="form-control">
<option selected>Choose...</option>
<option></option>
</select>
</div>
<div class="form-group col-md-2">
<label for="inputPincode">Pincode</label>
<input type="number" class="form-control" id="inputPincode">
</div>
<div class="form-group col-md-2">
<label for="inputPincode">Survey number</label>
<input type="number" class="form-control" id="inputPincode">
</div>
<div class="form-group col-md-2">
<label for="inputPincode">Area</label>
<input type="number" class="form-control" id="inputPincode" placeholder="In acers">
</div>
</div>
<div class="form-group">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="gridCheck">
<label class="form-check-label" for="gridCheck">
Check me out
</label>
</div>
</div>
<button type="submit" class="btn btn-primary">Sign in</button>
</form>
</div>
</section>
</body>
</html>
I believe you're asking the "Sticky Header" question.
https://dev.to/akhilarjun/one-line-sticky-header-using-css-5gp3
It does mean restructuring your form a little bit. The nav section should probably go outside the "interface" section.
An alternate approach is the "holy grail" aproach. Take what they have here: https://css-tricks.com/the-holy-grail-layout-with-css-grid/
and then just use the Aside, Nav, Article sections without the header and footer, and it's essentially what you're asking for.
I am having troubles with centering and aligning the forms inside the divs
I can't get the green to size properly and centre the form inside the green.
BTW the pic is what it looks like on my computer, when you click the code snippet, it looks all jumbled.
<style type="text/css">
#div1 {
background-color: coral;
width: 33.33%;
float: right;
height: 200px;
text-align: center;
}
#div1_Child {
width: 100%;
height: 60%;
border: 0px solid blue;
margin: 0 auto;
text-align: center;
}
#div2 {
background-color: rgb(240, 191, 191);
width: 33.33%;
float: left;
height: 200px;
text-align: center;
}
#div2_Child {
width: 90%;
height: 60%;
border: 0px solid blue;
margin: 0 auto;
text-align: left;
}
#div3 {
background-color: aqua;
width: 33.33%;
margin: 0 auto;
height: 200px;
text-align: center;
}
#div3_Child {
width: 85%;
height: 60%;
border: 0px solid blue;
margin: 0 auto;
text-align: center;
padding: 5px;
}
label {
width: 200px;
display: inline-block;
text-align: right;
}
form {
border-radius: 10px;
background: green;
color: black;
width: 80%;
padding: 2px;
margin: 0 auto;
}
</style>
<div id="div1">Div1 Right
<h1>Lighter Load</h1>
<div id="div1_Child">
<form>
<label for="beams">Beam Thickness</label>
<select name="Beams" id="beam">
<option value="Select">Select</option>
<option value="3.5">3.5</option>
<option value="5.25">5.25</option>
<option value="7">7</option>
</select><br>
<label for="dead">Dead</label>
<input id="dead2" type="text" name="dead" onkeyup="ecCalc()"><br>
<label>Eccentric</label>
<input id="eccCalc" type="text" name="total"><br>
<label>Index</label>
<input type="text" id="ecc">
</form>
</div>
</div>
<div id="div2">Div2 Left
<h1>Post Height</h1>
<div id="div2_Child">
<form class="form">
<label for="column_Height">Column Height:</label>
<select id="column_Height" onchange="search1()";>
<option value="">Select</option>
<option value="90">89</option>
<option value="96">90</option>
<option value="102">96</option>
<option value="120">102</option>
<option value="144">120</option>
<option value="168">144</option>
<option value="192">168</option>
<option value="216">192</option>
<option value="216">216</option>
</select> <br>
<label for="value">Between</label>
<input type="text" id="value" size="4" disabled>
<label for="text">and</label>
<input type="text" id="text" size="4" disabled><br>
<label for="l_oad" class= "label1">Unfactored</label>
<input type="text" id="l_oad" onkeyup="search()" placeholder="Unfactored.." title="Load" size="15">
</form>
</div>
</div>
<div id="div3">Div3 Middle
<h1>Heaver Loads</h1>
<div id="div3_Child">
<form>
<label>Dead</label>
<input id="dead1" type="text" name="dead" onkeyup="total_1()" size="10px"><br>
<label>Live</label>
<input class="input1" id="live1" type="text" name="live" onkeyup="total_1()" size="10"><br>
<label>Total</label>
<input id="total1" type="text" name="total" size="10"><br>
</form>
</div>
</div>
Why won't you use flex box? For more info about flex box look here: link. For all row divs you can still use flexbox example flex-direction: row;. Width of items inside will corresponds to your screen width.
* { box-sizing: border-box; margin: auto; padding: auto; }
.container_main { width: auto; height: 400px; background: red; padding: 10px; display: flex; flex-direction: row; overflow: auto; }
.container_main .item { width: 100%; height: 100%; background: yellow; margin: 0 5px; padding: 5px }
.container_main form { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.container_main form .form_item { width: 100%; height: 32px; display: flex; flex-direction: row; align-items: center; justify-content: center; }
<div class="container_main">
<div class="item">
<form method="post">
<div class="form_item">
<span>something</span>
<input type="text"/>
</div>
<div class="form_item">
<span>something</span>
<input type="text"/>
</div>
<div class="form_item">
<span>something</span>
<input type="text"/>
</div>
</form>
</div>
<div class="item">
<form method="post">
<div class="form_item">
<span>something</span>
<input type="text"/>
</div>
<div class="form_item">
<span>something</span>
<input type="text"/>
</div>
<div class="form_item">
<span>something</span>
<input type="text"/>
</div>
</form>
</div>
<div class="item">
<form method="post">
<div class="form_item">
<span>something</span>
<input type="text"/>
</div>
<div class="form_item">
<span>something</span>
<input type="text"/>
</div>
<div class="form_item">
<span>something</span>
<input type="text"/>
</div>
</form>
</div>
</div>
My teacher demand to modify my CSS and HTML to support mobile view if it is necessary. I have to follow as below:
If the page is viewed on mobile:
o The viewport should be set to zoom-level 100%, and the width should be the
device-width
• If the device screen size is less than 700px wide:
o The width of the page content should be 95% instead of 700px
• If the device screen size is less than 500px wide:
o The yellow circles in the page header should not appear( it is the "MERN" displayed in the right top corner)
I don't know how to code it. Thank you so much
body {
font-family: "Proxima Nova", Arial, Helvetica, sans-serif;
font-size: 18px;
color: #222222;
display: flex;
justify-content: space-around;
align-items: center;
flex-direction: column;
}
header {
border-bottom: 1px solid #ccc;
display: flex;
justify-content: space-between;
align-items: center;
flex-direction: row;
width: 700px;
height: 80px;
}
#coursename {
font-family: Helvetica, sans-serif;
font-size: 32px;
font-weight: bold;
color: #ee3322;
}
header span {
display: flex;
justify-content: space-around;
align-items: center;
flex-direction: row;
}
#MRN {
height: 50px;
display: flex;
justify-content: space-around;
flex-direction: row;
align-items: center;
}
#MRN span {
background-color: #ffee00;
border-radius: 100%;
height: 50px;
width: 50px;
margin: 3px;
text-align: center;
transform: rotate(-30deg);
font-weight: bold;
}
#MRN div {
background-color: #ffee00;
border-radius: 100%;
width: 50px;
height: 50px;
text-align: center;
transform: rotate(-30deg);
padding: 10px;
}
article {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
#quiz-name {
background-image: url(../starter_pack/images/background.jpg);
background-repeat: no-repeat;
background-size: cover;
background-position: middle;
width: 700px;
height: 425px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
h1 {
background-color: rgba(255, 255, 255, 0.9);
font-family: Pangolin, "Trebuchet MS", cursive;
font-size: 60px;
color: black;
padding: 10px;
max-width: 75%;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
}
#author {
font-size: 14px;
text-align: center;
margin-top: 18px;
}
#introduction {
width: 700px;
}
#introduction h2,
#introduction p {
margin: 18px 0 18px 0;
}
#startquiz,
#tryagain {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
border: 1px solid #f1f1f1;
background-color: #f1f1f1;
padding: 18px;
}
button {
border: none;
color: white;
background-color: #2196f3;
padding: 18px;
}
button:hover {
background-color: #0d8bf2;
}
#attempt-quiz,
#review-quiz {
width: 700px;
display: flex;
justify-content: center;
align-items: flex-start;
flex-direction: column;
}
#attempt-quiz p,
#review-quiz p {
margin: 30px 0 30px 0;
}
form {
cursor: pointer;
width: 700px;
margin: 30px 0 30px 0;
}
.option,
.review-answer {
border-top: 1px solid white;
border-bottom: 1px solid white;
display: flex;
justify-content: flex-start;
align-items: center;
flex-direction: row;
width: auto;
padding: 15px;
background-color: #f1f1f1;
position: relative;
}
.option:hover {
background-color: #ddd;
}
label {
margin-left: 15px;
}
.correct {
position: absolute;
right: 0;
margin: 10px;
background-color: rgba(0, 0, 0, 0.2);
padding: 3px;
color: white;
}
.incorrect {
position: absolute;
right: 0;
margin: 10px;
background-color: rgba(0, 0, 0, 0.2);
padding: 3px;
color: white;
}
#submit {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin-top: 18px;
border: 1px solid #f1f1f1;
background-color: #f1f1f1;
padding: 18px;
}
#submit button {
border: none;
color: white;
background-color: #4caf50;
padding: 18px;
}
#submit button:hover {
background-color: #46a049;
}
.hidden {
display: none;
}
#tryagain {
background-color: #f1f1f1;
border: 1px solid #dcdcdc;
}
#tryagain h3 {
font-size: 24px;
font-weight: lighter;
}
.option {
position: relative;
padding: 0;
}
.option input[type="radio"] {
position: absolute;
left: 10px;
top: 15px;
}
.option label {
flex-grow: 1;
padding: 15px 40px;
margin: 0;
}
.option input[type="radio"]:checked+label {
background: #ddd;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>HTML Quiz</title>
<link rel="icon" type="image/png" href="images/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="images/favicon-16x16.png" sizes="16x16" />
<link href="https://fonts.googleapis.com/css?family=Pangolin:400,700|Proxima+Nova" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="style.css" />
<script src="script.js" defer="true"></script>
</head>
<body>
<header>
<p id="coursename"><strong> WPR </strong> </p>
<div id="MRN">
<span>M</span>
<span>E</span>
<span>R</span>
<span>N</span>
</div>
</header>
<article>
<section id="quiz-name">
<h1 id="hello">HTML Quiz</h1> <br>
</section>
<p id="author"> By Minh Duc Nguyen </p>
<section id="introduction">
<h2> The Test </h2>
<p>The test contains 10 questions and there is no time limit.</p>
<p>The test is not official, it's just a nice way to see how much you know, or don't know, about HTML.</p>
<h2>Count Your Score</h2>
<p>
You will get 1 point for each correct answer. At the end of the Quiz, your total score will be displayed. Maximum score is 10 points.
</p>
<div id="startquiz">
<h2>Start the quiz</h2>
<p> Good luck!</p>
<button name="button" type="button">Start the HTML quiz ❯ </button>
</div>
</section>
<section id="attempt-quiz">
<div id="quiz">
<p><strong> Question 1 of 10</strong></p>
<p>Question 1</p>
<form name="ques01" id='ques01'>
<div class="option">
<input type="radio" name="question1" value="option 1">
<label><div >option 1 </div></label><br>
</div>
<div class="option">
<input type="radio" name="question1" value="option 2">
<label>option 2</label><br>
</div>
<div class="option">
<input type="radio" name="question1" value="option 3">
<label>option 3</label><br>
</div>
<div class="option">
<input type="radio" name="question1" value="option 4">
<label>option 4</label><br>
</div>
</form>
<p><strong> Question 2 of 10</strong></p>
<p>Question 2</p>
<form name="ques02" id='ques02'>
<div class="option">
<input type="radio" name="question2" value="option 1">
<label><div >option 1 </div></label><br>
</div>
<div class="option">
<input type="radio" name="question2" value="option 2">
<label>option 2</label><br>
</div>
<div class="option">
<input type="radio" name="question2" value="option 3">
<label>option 3</label><br>
</div>
<div class="option">
<input type="radio" name="question2" value="option 4">
<label>option 4</label><br>
</div>
</form>
<p><strong> Question 3 of 10</strong></p>
<p>Question 3</p>
<form name="ques03" id='ques03'>
<div class="option">
<input type="radio" name="question3" value="option 1">
<label><div >option 1 </div></label><br>
</div>
<div class="option">
<input type="radio" name="question3" value="option 2">
<label>option 2</label><br>
</div>
<div class="option">
<input type="radio" name="question3" value="option 3">
<label>option 3</label><br>
</div>
<div class="option">
<input type="radio" name="question3" value="option 4">
<label>option 4</label><br>
</div>
</form>
<p><strong> Question 4 of 10</strong></p>
<p>Question 4</p>
<form name="ques04" id='ques04'>
<div class="option">
<input type="radio" name="question4" value="option 1">
<label><div >option 1 </div></label><br>
</div>
<div class="option">
<input type="radio" name="question4" value="option 2">
<label>option 2</label><br>
</div>
<div class="option">
<input type="radio" name="question4" value="option 3">
<label>option 3</label><br>
</div>
<div class="option">
<input type="radio" name="question4" value="option 4">
<label>option 4</label><br>
</div>
</form>
<p><strong> Question 5 of 10</strong></p>
<p>Question 5</p>
<form name="ques05" id='ques05'>
<div class="option">
<input type="radio" name="question5" value="option 1">
<label><div >option 1 </div></label><br>
</div>
<div class="option">
<input type="radio" name="question5" value="option 2">
<label>option 2</label><br>
</div>
<div class="option">
<input type="radio" name="question5" value="option 3">
<label>option 3</label><br>
</div>
<div class="option">
<input type="radio" name="question5" value="option 4">
<label>option 4</label><br>
</div>
</form>
<p><strong> Question 6 of 10</strong></p>
<p>Question 6</p>
<form name="ques06" id='ques06'>
<div class="option">
<input type="radio" name="question6" value="option 1">
<label><div >option 1 </div></label><br>
</div>
<div class="option">
<input type="radio" name="question6" value="option 2">
<label>option 2</label><br>
</div>
<div class="option">
<input type="radio" name="question6" value="option 3">
<label>option 3</label><br>
</div>
<div class="option">
<input type="radio" name="question6" value="option 4">
<label>option 4</label><br>
</div>
</form>
<p><strong> Question 7 of 10</strong></p>
<p>Question 7
</p>
<form name="ques07" id='ques07'>
<div class="option">
<input type="radio" name="question7" value="option 1">
<label><div >option 1 </div></label><br>
</div>
<div class="option">
<input type="radio" name="question7" value="option 2">
<label>option 2</label><br>
</div>
<div class="option">
<input type="radio" name="question7" value="option 3">
<label>option 3</label><br>
</div>
<div class="option">
<input type="radio" name="question7" value="option 4">
<label>option 4</label><br>
</div>
</form>
<p><strong> Question 8 of 10</strong></p>
<p>Question 8</p>
<form name="ques08" id='ques08'>
<div class="option">
<input type="radio" name="question8" value="option 1">
<label><div >option 1 </div></label><br>
</div>
<div class="option">
<input type="radio" name="question8" value="option 2">
<label>option 2</label><br>
</div>
<div class="option">
<input type="radio" name="question8" value="option 3">
<label>option 3</label><br>
</div>
<div class="option">
<input type="radio" name="question8" value="option 4">
<label>option 4</label><br>
</div>
</form>
<p><strong> Question 9 of 10</strong></p>
<p>Question 9</p>
<form name="ques09" id='ques09'>
<div class="option">
<input type="radio" name="question9" value="option 1">
<label><div >option 1 </div></label><br>
</div>
<div class="option">
<input type="radio" name="question9" value="option 2">
<label>option 2</label><br>
</div>
<div class="option">
<input type="radio" name="question9" value="option 3">
<label>option 3</label><br>
</div>
<div class="option">
<input type="radio" name="question9" value="option 4">
<label>option 4</label><br>
</div>
</form>
<p><strong> Question 10 of 10</strong></p>
<p>Question 10</p>
<form name="ques10" id='ques10'>
<div class="option">
<input type="radio" name="question10" value="option 1">
<label><div >option 1 </div></label><br>
</div>
<div class="option">
<input type="radio" name="question10" value="option 2">
<label>option 2</label><br>
</div>
<div class="option">
<input type="radio" name="question10" value="option 3">
<label>option 3</label><br>
</div>
<div class="option">
<input type="radio" name="question10" value="option 4">
<label>option 4</label><br>
</div>
</form>
<div id="submit">
<button type="submit" value="submit" onclick="totalscore()">Submit your answer</button>
</div>
</form>
</div>
</section>
</article>
</body>
</html>
You should use CSS media queries. These is the updated CSS file.
body {
font-family: "Proxima Nova", Arial, Helvetica, sans-serif;
font-size: 18px;
color: #222222;
display: flex;
justify-content: space-around;
align-items: center;
flex-direction: column;
width:100%
}
header {
border-bottom: 1px solid #ccc;
display: flex;
justify-content: space-between;
align-items: center;
flex-direction: row;
width: 700px;
height: 80px;
}
#coursename {
font-family: Helvetica, sans-serif;
font-size: 32px;
font-weight: bold;
color: #ee3322;
}
header span {
display: flex;
justify-content: space-around;
align-items: center;
flex-direction: row;
}
#MRN {
height: 50px;
display: flex;
justify-content: space-around;
flex-direction: row;
align-items: center;
}
#MRN span {
background-color: #ffee00;
border-radius: 100%;
height: 50px;
width: 50px;
margin: 3px;
text-align: center;
transform: rotate(-30deg);
font-weight: bold;
}
#media all and (max-width :500px){
#MRN span{
display:none;
}
}
#MRN div {
background-color: #ffee00;
border-radius: 100%;
width: 50px;
height: 50px;
text-align: center;
transform: rotate(-30deg);
padding: 10px;
}
article {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
#quiz-name {
background-image: url(../starter_pack/images/background.jpg);
background-repeat: no-repeat;
background-size: cover;
background-position: middle;
width: 700px;
height: 425px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
h1 {
background-color: rgba(255, 255, 255, 0.9);
font-family: Pangolin, "Trebuchet MS", cursive;
font-size: 60px;
color: black;
padding: 10px;
max-width: 75%;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
}
#author {
font-size: 14px;
text-align: center;
margin-top: 18px;
}
#introduction {
width: 700px;
}
#introduction h2,
#introduction p {
margin: 18px 0 18px 0;
}
#startquiz,
#tryagain {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
border: 1px solid #f1f1f1;
background-color: #f1f1f1;
padding: 18px;
}
button {
border: none;
color: white;
background-color: #2196f3;
padding: 18px;
}
button:hover {
background-color: #0d8bf2;
}
#attempt-quiz,
#review-quiz {
width: 700px;
display: flex;
justify-content: center;
align-items: flex-start;
flex-direction: column;
}
#attempt-quiz p,
#review-quiz p {
margin: 30px 0 30px 0;
}
form {
cursor: pointer;
width: 700px;
margin: 30px 0 30px 0;
}
.option,
.review-answer {
border-top: 1px solid white;
border-bottom: 1px solid white;
display: flex;
justify-content: flex-start;
align-items: center;
flex-direction: row;
width: auto;
padding: 15px;
background-color: #f1f1f1;
position: relative;
}
.option:hover {
background-color: #ddd;
}
label {
margin-left: 15px;
}
.correct {
position: absolute;
right: 0;
margin: 10px;
background-color: rgba(0, 0, 0, 0.2);
padding: 3px;
color: white;
}
.incorrect {
position: absolute;
right: 0;
margin: 10px;
background-color: rgba(0, 0, 0, 0.2);
padding: 3px;
color: white;
}
#submit {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin-top: 18px;
border: 1px solid #f1f1f1;
background-color: #f1f1f1;
padding: 18px;
}
#submit button {
border: none;
color: white;
background-color: #4caf50;
padding: 18px;
}
#submit button:hover {
background-color: #46a049;
}
.hidden {
display: none;
}
#tryagain {
background-color: #f1f1f1;
border: 1px solid #dcdcdc;
}
#tryagain h3 {
font-size: 24px;
font-weight: lighter;
}
.option {
position: relative;
padding: 0;
}
.option input[type="radio"] {
position: absolute;
left: 10px;
top: 15px;
}
.option label {
flex-grow: 1;
padding: 15px 40px;
margin: 0;
}
.option input[type="radio"]:checked+label {
background: #ddd;
}
#media all and (max-width:700px){
header, form, #attempt-quiz, #review-quiz, #url, #introduction, header{
width:95% !important;
font-size:1rem;
}
}
I need to center a survey form in my website, but when I try it, it doesn't work. I don't know what's wrong. Can somebody help me?
Here is my Pen. And here's my CSS code:
*,
*::before,
*::after {
box-sizing: border-box;
}
body {
font-family: 'Poppins', sans-serif;
font-size: 1rem;
font-weight: 400;
line-height: 1.4;
color: var(--color-white);
margin: 0;
}
/* mobile friendly alternative to using background-attachment: fixed */
body::before {
content: '';
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 100%;
z-index: -1;
background: var(--color-darkblue);
background-image: linear-gradient(
115deg,
rgba(58, 58, 158, 0.8),
rgba(136, 136, 206, 0.7)
),
url(https://cdn.freecodecamp.org/testable-projects-fcc/images/survey-form-background.jpeg);
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}
.container {
width: 100%;
margin: 3.125rem auto 0 auto;
}
you can use this on your body
body {
background-color: lightblue;
font-family: Helvetica;
font-size: 16px;
flex: 0 1 auto;
align-self: auto;
width: 100%;
text-align: center;
}
It is not recommended to use body directly and style it. But I made a few tweaks on your code to keep letting you use body directly.
Please check this out for reference when you want to center an element.
https://css-tricks.com/centering-css-complete-guide/
*,
*::before,
*::after {
box-sizing: border-box;
}
.wrapper {
margin: 0 auto; // this centers bloc elements
text-align: center; // This centers inline elements
}
header {
width: 100%;
}
body {
width: 100%; // just let your body take 100% of the page
background-color: lightblue;
font-family: Helvetica;
font-size: 16px;
position: absolute;
flex: 0 1 auto;
align-self: auto;
}
#survey-form {
border: solid 2px;
border-radius: 1%;
padding: 20px;
margin-top: 30px;
background-color: lightpink;
position: relative;
}
.form input {
width: 100%;
height: 30px;
}
.container {
display: flex;
justify-content: flex-start;
flex-direction: column;
//border: solid 2px #fff;
max-width: 700px;
margin: auto;
}
h1 {
color: darkblue;
}
p {
font-weight: bold;
}
form {
text-align: left;
}
#dropdown {
width: 100%;
height: 30px;
}
.checkbox {
display: flex;
flex-direction: column;
}
#submit {
height: 20px;
width: 100%;
background-color: #bbh77f;
color: #000;
padding: 0 20px;
text-align: center;
vertical-align: middle;
}
.input-textarea {
min-height: 120px;
width: 100%;
margin-bottom: 15px;
resize: vertical;
}
<!DOCTYPE html>
<html>
<head>
<meta>
<title>Formularz</title>
</head>
<body>
<header>
<div class='wrapper'>
<h1 id="title">Formularz freeCodeCamp.org</h1>
<p id="description">Dziękujemy za poświęcony czas i ulepszanie naszej platformy</p>
</div>
</header>
<div class="container">
<form id="survey-form">
<div class="form box">
<div>
<label id="name-label" for="name"><p>Imię</p></label>
<input id="name" type="text" required placeholder="Wpisz swoje imię" />
</div>
<div>
<label id="email-label" for="mail"><p>E-mail</p></label>
<input id="name" type="email" required placeholder="Wpisz swój e-mail" />
</div>
<div>
<label id="number-label" for="number"><p>Wiek</p></label>
<input type="number" min="10" max="99" placeholder="10">
</div>
</div>
<div class="form-group">
<p id="dropdown-label">Która opcja najlepiej Cię opisuje?</p>
<select id="dropdown">
<option disabled selected value>Wybierz swoją rolę</option>
<option value="student">Student</option>
<option value="full-time-job">Pełen etat</option>
<option value="full-time-learner">Uczeń</option>
<option value="prefer-not-to-say">Nie chcę mówić</option>
<option value="other">Inne</option>
</select>
</div>
<div class="form-radio">
<p id="radio-label">Czy poleciłbyś freeCodeCamp znajomemu?</p>
<div>
<input type="radio" id="tak" name="polecenie" value="tak" checked>
<label for="tak">Tak</label>
</div>
<div>
<input type="radio" id="nie" name="polecenie" value="nie">
<label for="nie">Nie</label>
</div>
<div>
<input type="radio" id="nie-wiem" name="polecenie" value="nie-wiem">
<label for="nie-wiem">Nie wiem</label>
</div>
</div>
<div class="form-group">
<p id="dropdown-label">Jaka część freeCodeCamp jest Twoją ulubioną?</p>
<select id="dropdown">
<option disabled selected value>Wybierz opcję</option>
<option value="challenges">Challenges</option>
<option value="projects">Projects</option>
<option value="community">Community</option>
<option value="open-source">Open source</option>
</select>
</div>
<div class="form-group checkbox">
<p>Co chcesz ulepszyć?</p>
<div>
<input type="checkbox">
<label>Front-end Projects</label>
</div>
<div>
<input type="checkbox">
<label>Back-end Projects</label>
</div>
<div>
<input type="checkbox" checked>
<label>Data Visualization</label>
</div>
<div>
<input type="checkbox">
<label>Challenges</label>
</div>
<div>
<input type="checkbox">
<label>Open Source Community</label>
</div>
<div>
<input type="checkbox">
<label>Gitter help rooms</label>
</div>
<div>
<input type="checkbox">
<label>Videos</label></div>
<div>
<input type="checkbox">
<label>City Meetups</label></div>
<div>
<input type="checkbox">
<label>Wiki</label>
</div>
<div>
<input type="checkbox">
<label>Forum</label>
</div>
<div>
<input type="checkbox">
<label>Additional Courses</label>
</div>
</div>
<div class="form-group">
<p>Masz sugestie lub podpowiedzi? </p>
<div class="textarea container input-textarea">
<textarea rows="8" placeholder="Wprowadź swoją opinię tutaj"></textarea>
</div>
<button id="submit">Wyślij</button>
</div>
</div>
</form>
</div>
</div>
</body>
</html>
I am aiming to make text boxes that adapt to the size of the browser window. I'm using css flex properties. The textboxes in the code below do not adapt with the screen size, and I'm not sure exactly why. I believe it might be because I have an outer div that's interacting with the css properties for the actual textboxes.
One other thing that I'm not sure how to do, is to align the button to the right edge of the text boxes, so that the button does not go past the textboxes. Because the textboxes are not dynamically reshaping their width I'm not sure how to proceed with the button.
.search_btn {
width: 150px;
padding: 10px;
background-color: black;
color: white;
border: 0;
}
.search_btn:hover {
box-shadow: 1px 1px 1px grey;
/*background-color: darkblue;*/
}
input {
justify-content: flex-left;
padding: 5px;
position: absolute;
margin-left: 200px;
}
.txt_box {
display: flex;
width: 80%;
}
.search_section {
/*padding: 5px;*/
padding-top: 10px;
padding-bottom: 10px;
}
.search_options {
padding-bottom: 10px;
}
.row {
display: flex;
flex-direction: row;
align-items: left;
justify-content: left;
padding-top: 10px;
padding-bottom: 10px;
}
<form action="/action_page.php">
<div class="search_section">
<div class="search_options">
<h3 class="tit_label" for="fname">SHAPES</h3>
<div class="row">
<label class="left_label" for="fname">average square:</label>
<!-- <div id="wrapper" -->
<input class="txt_box" type="text" id="fname" name="fname" />
</div>
<div class="row">
<label class="left_label" for="lname">average circle:</label>
<input class="txt_box" type="text" id="lname" name="lname" />
</div>
</div>
<div class="form-buttons">
<input class="search_btn" type="submit" value="calculate" />
</div>
</div>
</form>
You need to remove position: absolute from input to make it flex-item. Since you have made absolute positioned then it comes out of the normal flow, then you don't need to use display: flex on input.
No need to use the below style, since txt_box will be a flex item then it will adjust its width accordingly
.txt_box { // Not Required
display: flex;
width: 80%;
}
There is no such property justify-content: flex-left;. There is justify-content: flex-start; instead
.search_btn {
width: 150px;
padding: 10px;
background-color: black;
color: white;
border: 0;
}
.search_btn:hover {
box-shadow: 1px 1px 1px grey;
}
input {
padding: 5px;
}
.search_section {
padding-top: 10px;
padding-bottom: 10px;
}
.search_options {
padding-bottom: 10px;
}
.row {
display: flex;
padding-top: 10px;
padding-bottom: 10px;
}
.left_label {
flex-basis: 20%;
}
.txt_box {
margin: 0;
flex-basis: 80%;
}
<form action="/action_page.php">
<div class="search_section">
<div class="search_options">
<h3 class="tit_label" for="fname">SHAPES</h3>
<div class="row">
<label class="left_label" for="fname">average square:</label>
<input class="txt_box" type="text" id="fname" name="fname" />
</div>
<div class="row">
<label class="left_label" for="lname">average circle:</label>
<input class="txt_box" type="text" id="lname" name="lname" />
</div>
</div>
<div class="form-buttons">
<input class="search_btn" type="submit" value="calculate" />
</div>
</div>
</form>