The whole thing is a misunderstanding on my part please ignore!
I have tried to research this problem but the only solution that came up were for react native. My problem basically is that the CSS behaves differently in reactjs environment then in a regular one. Here is what I mean:
class TodoApp extends React.Component {
constructor(props) {
super(props)
this.state = {
items: [
{ text: "Learn JavaScript", done: false },
{ text: "Learn React", done: false },
{ text: "Play around in JSFiddle", done: true },
{ text: "Build something awesome", done: true }
]
}
}
render() {
return (
<form>
<div id="cart">
{/* Cart Header */}
<div id="cart-header">
<div id="edit-icon" className="header-icon">
<p>EDIT</p>
</div>
<div className="header-line"></div>
<div id="payment-icon" className="header-icon">
<p>PAYMENT</p>
</div>
<div className="header-line"></div>
<div id="confirm-icon" className="header-icon">
<p>COMFIRM</p>
</div>
</div>
{/* Cart Body */}
{/* Personal information */}
<div id="cart-body-left" className="cart-body">
<h2>Personal information</h2>
<fieldset id="info-fieldset">
<div id="name" className="input-div-container">
<div id="first-name" className="input-div">
<input type="text" placeholder="First Name"/>
<label className="input-label">First Name</label>
</div>
<div id="last-name" className="input-div">
<input type="text" placeholder="Last Name" />
<label className="input-label">Last Name</label>
</div>
</div>
<div id="email" className="input-div">
<input type="email" placeholder="Email" />
<label className="input-label">Email</label>
</div>
<div id="number" className="input-div">
<input type="text" placeholder="Number" />
<label className="input-label">Number</label>
</div>
<div id="address-apt" className="input-div-container">
<div id="address" className="input-div">
<input type="text" placeholder="Address" />
<label className="input-label">Adress</label>
</div>
<div id="apt" className="input-div">
<input type="text" placeholder="Apt, Unit, etc" />
<label className="input-label">Apt, Unit, etc</label>
</div>
</div>
<div id="zip-city-state" className="input-div-container">
<div id="zip" className="input-div">
<input type="text" placeholder="Zip" />
<label className="input-label">Zip</label>
</div>
<div id="city" className="input-div">
<input type="text" placeholder="City" />
<label className="input-label">City</label>
</div>
<div id="state" className="input-div">
<select id="state-select">
<option value="AL">AL</option>
<option value="AK">AK</option>
<option value="AS">AS</option>
<option value="AZ">AZ</option>
<option value="AR">AR</option>
<option value="CA">CA</option>
<option value="CO">CO</option>
<option value="CT">CT</option>
<option value="DE">DE</option>
<option value="DC">DC</option>
<option value="FM">FM</option>
<option value="FL">FL</option>
<option value="GA">GA</option>
<option value="GU">GU</option>
<option value="HI">HI</option>
<option value="ID">ID</option>
<option value="IL">IL</option>
<option value="IN">IN</option>
<option value="IA">IA</option>
<option value="KS">KS</option>
<option value="KY">KY</option>
<option value="LA">LA</option>
<option value="ME">ME</option>
<option value="MH">MH</option>
<option value="MD">MD</option>
<option value="MA">MA</option>
<option value="MI">MI</option>
<option value="MN">MN</option>
<option value="MS">MS</option>
<option value="MO">MO</option>
<option value="MT">MT</option>
<option value="NE">NE</option>
<option value="NV">NV</option>
<option value="NH">NH</option>
<option value="NJ">NJ</option>
<option value="NM">NM</option>
<option value="NY">NY</option>
<option value="NC">NC</option>
<option value="ND">ND</option>
<option value="MP">MP</option>
<option value="OH">OH</option>
<option value="OK">OK</option>
<option value="OR">OR</option>
<option value="PW">PW</option>
<option value="PA">PA</option>
<option value="PR">PR</option>
<option value="RI">RI</option>
<option value="SC">SC</option>
<option value="SD">SD</option>
<option value="TN">TN</option>
<option value="TX">TX</option>
<option value="UT">UT</option>
<option value="VT">VT</option>
<option value="VI">VI</option>
<option value="VA">VA</option>
<option value="WA">WA</option>
<option value="WV">WV</option>
<option value="WI">WI</option>
<option value="WY">WY</option>
</select>
</div>
</div>
</fieldset>
</div>
{/* Credit Card Information */}
<div id="cart-body-right" className="cart-body">
<h2>Credit Card Information</h2>
<fieldset id="cc-fieldset">
<div id="cc-number" className="input-div">
<input type="number" placeholder="Credit Card Number" />
</div>
<div id="cc-valid" className="input-div-container">
<div id="cc-expiration" className="input-div">
<input type="text" placeholder="MM/YY" />
</div>
<div id="cc-cvv" className="input-div">
<input type="text" placeholder="CVV" />
</div>
<div id="cvv-help" className="input-div">
<img height="18px" width="18px" src="store/img/question-mark.png" />
</div>
</div>
</fieldset>
<div id="cart-stats">
<div className="stats">
<span>cart total:</span>
<span>something</span>
</div>
<div className="stats">
<span>cart total:</span>
<span>something</span>
</div>
<div className="stats">
<span>cart total:</span>
<span>something</span>
</div>
</div>
<div id="terms-conditions">
<div className="checkbox">
<input type="checkbox" id="tc-checkbox" value="0" />
<label htmlFor="tc-checkbox">Bla bla bla </label>
</div>
</div>
</div>
{/* Cart Footer */}
<div className="cart-footer" id="cart-footer-left">
<div id="coupon">
<div id="coupon-input">
<input type="text"/>
</div>
<div id="coupon-button">
<button>hello</button>
</div>
</div>
</div>
<div className="cart-footer" id="cart-footer-right">
</div>
</div>
</form>
)
}
}
ReactDOM.render(<TodoApp />, document.querySelector("#app"))
:root {
--gold: #e5cb51;
--silver: #666666;
--light-silver: #ddd;
}
::placeholder {
color: var(--silver);
}
h2 {
text-align: center;
color: white;
color: var(--light-silver);
font-family: Montserrat,"Helvetica Neue",Helvetica,Arial,sans-serif;
}
body {
background-color: black;
}
p {
font-family: Raleway;
}
#cart {
margin: auto;
margin-top: 100px;
width: 800px;
display: grid;
grid-template-areas:
"h h" /* Header */
"bl br" /* Body left right */
"fl fr"; /* Footer left right */
}
#cart-header {
background-color: black;
border: 1.5px solid var(--gold);
border-bottom: 0px;
border-top-left-radius: 1em;
border-top-right-radius: 1em;
grid-area: h;
display: flex;
justify-content: center;
padding: 1em 0;
}
#cart-body-left {
grid-area: bl;
}
#cart-body-right {
grid-area: br;
border-left-width: 0;
}
#cart-footer-left {
grid-area: fl;
border-bottom-left-radius: 1em;
}
#cart-footer-right {
grid-area: fr;
border-bottom-right-radius: 1em;
}
.cart-body {
width: 400px;
height: 400px;
border: 1.5px solid var(--gold);
background-color: black;
}
.cart-footer {
height: 50px;
width: 400px;
background-color: var(--gold);
}
#email {
box-sizing: border-box;
padding-bottom: 1em;
}
#number {
box-sizing: border-box;
}
#state > select{
height: 100%;
border: 1.5px var(--silver) solid;
border-radius: 3px;
}
#cc-paypal-option {
padding-left: 50%;
margin: 1em;
border: 1px solid white;
border-bottom-left-radius: .5em;
border-bottom-right-radius: .5em;
padding-bottom: 1em;
}
#cc-paypal-option > button {
height: 31px;
}
#cart-stats {
margin: 1em;
border: 1.5px var(--gold) solid;
border-radius: .5em;
}
#cart-stats > div:nth-child(2) {
border-top: 1px var(--gold) solid;
border-bottom: 1px var(--gold) solid;
padding: .5em 0;
margin: .5em 0;
}
#coupon {
height: 40px;
width: 300px;
margin: 5px 50px;
background-color: black;
display: flex;
}
#coupon > div {
width: 200px;
position: relative;
}
#coupon-input input {
position: absolute;
height: 100%;
right: 0;
width: 0;
opacity: 1;
transition: all .2s ease-in;
}
#coupon-button button {
height: 100%;
}
#cart-footer-left:hover input[type="text"] {
width: 100px;
opacity: 1;
transition: all .2s ease-out;
}
.header-line {
width: 75px;
height: 0px;
border: 1px solid var(--gold);
margin: auto 0;
background-color: var(--gold);
}
.header-icon {
height: 2em;
width: 120px;
border: 1.5px solid var(--gold);
border-radius: 4px;
margin: .5em 0px;
padding-top: .1em;
}
.active-icon {}
.header-icon:hover {
background-color: var(--gold);
}
.header-icon:hover > p{
color: black;
}
.header-icon > p {
text-align: center;
color: var(--light-silver);
font-weight: bold;
font-family: Montserrat,"Helvetica Neue",Helvetica,Arial,sans-serif;
font-size: 1.2em;
letter-spacing: 2px;
line-height: 1.45;
}
.input-label {
visibility: visible;
position: absolute;
display: block;
color: white;
top: 0;
font-size: 1em;
opacity: 1;
transform: translateY(-1.5em);
transition: all 0.2s ease-out;
margin-left: 10px;
display: inline;
}
input:placeholder-shown + label {
opacity: 0;
visibility: hidden;
text-align: center;
transform: translateY(.5em);
}
.input-div-container {
display: flex;
}
.input-div {
position: relative;
padding: 1em;
/* height: 33px; */
}
/* #first-name,
#last-name {
width: 198.5px;
} */
.input-div > input {
width: 100%;
padding: 5px 10px;
border-radius: 3px;
border: 1.5px var(--silver) solid;
display: block;
}
.input-div > input:focus, #state > select:focus {
outline: none;
border: solid var(--gold) 1.5px;
box-shadow: 0 0 5px var(--gold);
}
.stats {
margin: .5em;
display: flex;
justify-content: center;
}
.stats > span {
padding: 0 1em;
color: var(--light-silver);
}
.checkbox {
position: relative;
margin: 1em;
margin-top: 1.3em;
}
.checkbox input[type="checkbox"] {
position: absolute;
top: 0;
left: 0;
width: 0;
height: 0;
opacity: 0;
pointer-events: none;
}
.checkbox label::before {
display: block;
position: absolute;
top: 0;
left: 0;
width: 28px;
height: 28px;
background-color: white;
content: '';
}
.checkbox input[type="checkbox"]:checked + label::before {
background-color: var(--gold);
color: white;
}
.checkbox input[type="checkbox"]:checked + label::after {
display: block;
position: absolute;
top: 1px;
left: 8.5px;
width: 10px;
height: 20px;
/* background: black; */
border: solid black;
border-width: 0 3px 3px 0;
transform: rotate(45deg);
content: '';
}
#media screen and (max-width: 900px) {
#cart {
width: 400px;
display: grid;
grid-template-areas:
"h"
"bl"
"fl"
"br"
"fr";
}
#cart-header {
width: 400px;
}
.header-icon {
width: 75px;
}
.header-icon p {
font-size: .7em;
letter-spacing: 2px;
line-height: 2.5;
}
#cart-body-right {
border-left-width: 1.5px;
}
#cart-footer-left {
border-radius: 0px;
}
#cart-footer-right {
border-bottom-left-radius: 1em;
border-bottom-right-radius: 1em;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id="app"></div>
Here is how it looks like when I render it without react
How it looks like after I paste my code into jsx
I hope I have provided enough code and if not I can add on to it
I'm not sure this is a react specific issue. I pasted your code into JSFiddle and did not run into the same issues you are having. Positioned elements will only default to root if there are no other positioned ancestors. Might be worth looking through your HTML to see if there is a positioned parent or ancestor messing with your positioning.
Related
I want to create an input that contains a button that has an arrow down so the user can click on it to open a list or close it. I can't put the button inside the input, what do i miss here?
.input-wrapper {
position: relative;
}
.combobox-input {
font-size: 16px;
font-weight: normal;
color: #4d4d4d;
background: #ffffff;
border: 1px solid #828995;
height: 30px;
padding: 4px 10px;
}
.combobox-arrow {
display: inline-block;
padding: 6px;
border: none;
background-color: white;
background-image: url(...);
width: 25px;
height: 25px;
}
<div className="input-wrapper">
<input className="combobox-input"/>
<button className="combobox-arrow" ></button>
</div>
Try this and see if it suits your need:
(you can modify the snippet code as per your need)
document.getElementById('caret').addEventListener('click', function() {
// your code here if you want to add some logic
});
button#caret {
border: none;
background: none;
position: absolute;
top: 0px;
right: 0px;
}
.input-wrap {
position: relative;
display: inline;
}
<label>List of places<br/>
<div class="datalist-wrap">
<div class="input-wrap">
<input id="placesText" type="text" name="places" list="places"/>
<button id="caret"> ▼</button>
</div>
<datalist id="places">
<label>Select from the list:
<select name="places" id="select">
<option value="A"></option>
<option value="B"></option>
<option value="C"></option>
</select>
</label>
</datalist>
</div>
</label>
I have a problem. I created the following page:
#newOrderControl {
display: flex;
align-items: center;
flex-direction: column;
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: 20px;
padding-bottom: 20px;
}
#newOrderInputFields .inputField {
display: flex;
flex-direction: row;
justify-content: flex-end;
align-items: center;
}
#newOrderInputFields label {
flex-shrink: 0;
}
#newOrderButtons {
align-self: flex-end;
padding-bottom: 20px;
}
#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>
<option value="">SPTF</option>
<option value="">TLS</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>
Now with this code I have a few problems:
The 2 selects (action and coin) don't have an equal width, so they are not aligned perfectly
When I resize my page everything goes trough each other
I thought I could fix it by setting width: min-content; in #newOrderControl, but that crops everything trough each other:
So I tried setting it to auto, but then it uses the entire page:
How can I keep the positions while resizing the page and give the #newOrderControl the width it needs to place everything, without using the entire page?
Did this solve the issue? I removed a couple of things. The biggest issues were width: min-content and display: flex on #newOrderControl, and using margin instead of padding. Margin doesn't work well with grid and flex.
I also removed the float, and all display properties on children of #newOrderInputFields, because it didn't seem like they did anything.
Whenever you have problem with CSS, try removing as much code as possible and start again.
As mentioned in the comments. Don't use float in design, unless it's an element that text should flow around.
I didn't focus on fixing the different input field widths. I would probably solve that by using a min-width, as you stated, or use Material Design's suggestion for text fields.
#newOrderControl {
/* display: flex; */
display: inline-flex; /* ADDED */
align-items: center;
flex-direction: column;
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: 20px;
padding-bottom: 20px;
}
/* #newOrderInputFields .inputField {
display: flex;
flex-direction: row;
justify-content: flex-end;
align-items: center;
}*/
/* #newOrderInputFields label {
flex-shrink: 0;
}*/
#newOrderButtons {
align-self: flex-end;
padding-bottom: 20px;
}
#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; */
padding: 0px 5px; /* ADDED */
}
.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; */
padding: 5px; /* ADDED */
}
<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>
<option value="">SPTF</option>
<option value="">TLS</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>
If you're not opposed to using flex and grid together here's another option for you
EDIT to add mobile:
#newOrderControl {
display: flex;
align-items: center;
flex-direction: column;
border-style: solid;
border-color: black;
border-width: 1px;
width: min-content;
font-size: 14px;
padding: 0px 10px 10px 10px;
}
#newOrderInputFields {
display: grid;
grid-template-rows: 2em 2em;
grid-template-columns: 9em 18em 16em 16em;
padding-bottom: 1em;
padding-top: 1em;
}
input {
width: 10em;
}
select {
width: 5em;
}
#txtOrderAmount {
margin-left: 2px;
}
#txtOrderLimitPrice {
margin-left: 4px;
}
#txtOrderLimitPerc {
margin-left: 4px;
}
#txtOrderCoin {
margin-left: 10px;
}
#newOrderButtons {
align-self: 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;
}
#media screen and (max-width: 1000px) {
#newOrderControl {
width: min-content + 10;
}
input {
width: 5em;
}
#newOrderInputFields {
grid-template-rows: 2em 2em 2em 2em;
grid-template-columns: 13.5em 13.5em;
}
#txtOrderAmount {
margin-left: 19px;
}
#txtOrderLimitPrice {
margin-left: 2px;
}
#txtOrderLimitPerc {
margin-left: 7px;
}
#txtOrderCoin {
margin-left: 37px;
}
#txtOrderTargetPrice {
margin-left: 5px;
}
#txtOrderAction {
margin-left: 27px;
}
#txtOrderQuantity {
margin-left: 17px;
}
#txtOrderTargetPrice {
margin-left: 0px;
}
#txtOrderTargetPerc {
margin-left: 4px;
}
#Action_Quantity {
grid-area: 2 / 1 / span 1 / span 1;
}
#Action_TrgtPrice {
grid-area: 3 / 1 / span 1 / span 1;
}
#Action_TrgtPerc {
grid-area: 4 / 1 / span 1 / span 1;
}
#newOrderButtons {
display: flex;
width: 100%;
height: auto;
justify-content: space-evenly;
}
}
<div id="newOrderControl">
<label class="title">New order</label>
<div id="newOrderInputFields">
<div class="inputField">
<label class="inputLabel">Action:</label>
<select id="txtOrderAction">
<option value="">-</option>
<option value="Buy">Buy</option>
<option value="Sell">Sell</option>
</select>
</div>
<div class="inputField" id="Action_Quantity">
<label class="inputLabel">Quantity:</label>
<input type="text" id="txtOrderQuantity">
<button class="btnAll" onclick="setAllQuantity()">All</button>
</div>
<div class="inputField" id="Action_TrgtPrice">
<label class="inputLabel">Target price:</label>
<input type="text" id="txtOrderTargetPrice">
</div>
<div class="inputField" id="Action_TrgtPerc">
<label class="inputLabel">Target perc:</label>
<input type="text" id="txtOrderTargetPerc">
</div>
<div class="inputField">
<label>Coin:</label>
<select id="txtOrderCoin">
<option value="">-</option>
<option value="">SPTF</option>
<option value="">TLS</option>
</select>
</div>
<div class="inputField">
<label class="inputLabel">Amount:</label>
<input type="text" id="txtOrderAmount">
<button class="btnAll" onclick="setAllAmount()">All</button>
</div>
<div class="inputField">
<label class="inputLabel">Limit price:</label>
<input type="text" id="txtOrderLimitPrice">
</div>
<div class="inputField">
<label class="inputLabel">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>
Can you tell me how to the change color of first option in selection to grey? (Like above)
Also, how to make a clickable icon to show all options? Because it doesn’t work correctly.
<div class="form__group form__group-selection">
<label for="location" class="form__label"><i class="fas fa-map-marker-alt"></i></label>
<select name="location" id="location" class="form__select">
<option class="form__select-option" value="selected" selected>Select one option</option>
<option class="form__select-option" value="polska">Polska</option>
<option class="form__select-option" value="lotwa">Łotwa </option>
<option class="form__select-option" value="estonia">Estonia</option>
<option class="form__select-option" value="anglia">Anglia</option>
<option class="form__select-option" value="czopki">Czopki</option>
</select>
</div>
Link: https://codepen.io/direct96/pen/zJbpPZ - Codepen
I've update jsFiddle.
Notice that I've also changed the HTML part, because I think you want to use the "disabled" attribute (and because of that, you'll have to add the "selected" attribute also).
<script type="text/javascript">
function changeMe(sel)
{
sel.style.color = "#000";
}
</script>
$header-text-color: #efefef;
$form-bgn-color: #f6f6f6;
$form-text-color: #c5c5c5;
$color-input-focus: #6ba81a;
#mixin inputFonts {
padding: 0.5rem 2rem;
background-color: $form-bgn-color;
border: 0px;
font-family: inherit;
font-size: 1.4rem;
}
html {
font-size: 65.2%;
}
*,
*::before,
*::after {
box-sizing: inherit;
margin: 0;
padding: 0;
}
body {
box-sizing: border-box;
font-family: "Lato", sans-serif;
font-size: 1.6rem;
}
.container {
height: 100%;
background-image: linear-gradient(
to top,
#c5eff3 15%,
#f59f4d 70%,
#bc2029 100%
);
}
.form {
&__header {
padding: 2rem;
text-align: center;
color: $header-text-color;
letter-spacing: 0.1rem;
text-shadow: 1px 2px 3px black;
}
&__box {
background-color: $form-bgn-color;
padding: 30px;
width: 70%;
margin: 0 auto;
position: relative;
&::after {
content: "";
position: absolute;
left: -1rem;
right: -1rem;
top: -1rem;
bottom: -1rem;
border: 1rem solid rgba(#000000, 0.2);
}
}
&__group {
border: $form-text-color 1px solid;
border-radius: 3px;
position: relative;
z-index: 1;
width: 100%;
display: flex;
&:not(:last-child) {
margin-bottom: 2rem;
}
&-selection {
&::before {
font-family: "Font Awesome 5 Free";
font-weight: 900;
content: "\f0d7";
font-size: 2.5rem;
color: $form-text-color;
position: absolute;
top: 50%;
right: 2%;
transform: translateY(-50%);
}
}
}
&__label {
i {
font-size: 2rem;
color: $form-text-color;
padding: 1rem 1.5rem;
position: relative;
&::after {
content: "";
position: absolute;
top: 15%;
right: -1px;
height: 75%;
border-right: solid 1px $form-text-color;
}
}
}
&__input-text {
width: 100%;
#include inputFonts();
transition: all 0.3s ease-out;
&::placeholder {
color: $form-text-color;
}
&:focus {
outline: none;
border: $color-input-focus 2px solid;
z-index: 1;
}
}
&__select {
-webkit-appearance: none;
width: 100%;
#include inputFonts();
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU"
crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Lato:400,700,900" rel="stylesheet">
<title>Forms</title>
</head>
<body>
<div class="container">
<div class="form">
<h1 class="form__header">
Register Form
</h1>
<form action="" class="form__box">
<div class="form__group">
<label for="username" class="form__label"><i class="fas fa-user-alt"></i></label>
<input type="text" id="username" placeholder="Username" class="form__input-text" required>
</div>
<div class="form__group">
<label for="password" class="form__label"><i class="fas fa-lock"></i></label>
<input type="password" id="password" placeholder="Password" class="form__input-text" required>
</div>
<div class="form__group">
<label for="password-repeat" class="form__label"><i class="fas fa-lock"></i></label>
<input type="password" id="password-repeat" placeholder="Confirm Password" class="form__input-text" required>
</div>
<div class="form__group">
<label for="email" class="form__label"><i class="fas fa-envelope"></i></label>
<input type="email" id="email" placeholder="Email" class="form__input-text" required>
</div>
<div class="form__group form__group-selection" onchange="changeMe(this)">
<label for="location" class="form__label"><i class="fas fa-map-marker-alt"></i></label>
<select name="location" id="location" class="form__select">
<option selected disabled class="form__select-option" value="selected" selected>Select one option</option>
<option class="form__select-option" value="polska">Polska</option>
<option class="form__select-option" value="lotwa">Łotwa </option>
<option class="form__select-option" value="estonia">Estonia</option>
<option class="form__select-option" value="anglia">Anglia</option>
<option class="form__select-option" value="czopki">Czopki</option>
</select>
</div>
</form>
</div>
<div style="height: 5000px;"></div>
</div>
</body>
</html>
To make the "Select one option" look grey, you just have to add the "disabled" attribute to the option. I'm not sure about what you mean by "a clickable icon to show all options", but there's no "clean" way to do that, it could be done with some js, but i'm not sure it would work with all browsers.
html {
font-size: 65.2%;
}
*,
*::before,
*::after {
box-sizing: inherit;
margin: 0;
padding: 0;
}
body {
box-sizing: border-box;
font-family: "Lato", sans-serif;
font-size: 1.6rem;
}
.container {
height: 100%;
background-image: linear-gradient(to top, #c5eff3 15%, #f59f4d 70%, #bc2029 100%);
}
.form__header {
padding: 2rem;
text-align: center;
color: #efefef;
letter-spacing: 0.1rem;
text-shadow: 1px 2px 3px black;
}
.form__box {
background-color: #f6f6f6;
padding: 30px;
width: 70%;
margin: 0 auto;
position: relative;
}
.form__box::after {
content: "";
position: absolute;
left: -1rem;
right: -1rem;
top: -1rem;
bottom: -1rem;
border: 1rem solid rgba(0, 0, 0, 0.2);
}
.form__group {
border: #c5c5c5 1px solid;
border-radius: 3px;
position: relative;
z-index: 1;
width: 100%;
display: flex;
}
.form__group:not(:last-child) {
margin-bottom: 2rem;
}
.form__group-selection::before {
font-family: "Font Awesome 5 Free";
font-weight: 900;
content: "\f0d7";
font-size: 2.5rem;
color: #c5c5c5;
position: absolute;
top: 50%;
right: 2%;
transform: translateY(-50%);
}
.form__label i {
font-size: 2rem;
color: #c5c5c5;
padding: 1rem 1.5rem;
position: relative;
}
.form__label i::after {
content: "";
position: absolute;
top: 15%;
right: -1px;
height: 75%;
border-right: solid 1px #c5c5c5;
}
.form__input-text {
width: 100%;
padding: 0.5rem 2rem;
background-color: #f6f6f6;
border: 0px;
font-family: inherit;
font-size: 1.4rem;
transition: all 0.3s ease-out;
}
.form__input-text::placeholder {
color: #c5c5c5;
}
.form__input-text:focus {
outline: none;
border: #6ba81a 2px solid;
z-index: 1;
}
.form__select {
-webkit-appearance: none;
width: 100%;
padding: 0.5rem 2rem;
background-color: #f6f6f6;
border: 0px;
font-family: inherit;
font-size: 1.4rem;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU"
crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Lato:400,700,900" rel="stylesheet">
<title>Forms</title>
</head>
<body>
<div class="container">
<div class="form">
<h1 class="form__header">
Register Form
</h1>
<form action="" class="form__box">
<div class="form__group">
<label for="username" class="form__label"><i class="fas fa-user-alt"></i></label>
<input type="text" id="username" placeholder="Username" class="form__input-text" required>
</div>
<div class="form__group">
<label for="password" class="form__label"><i class="fas fa-lock"></i></label>
<input type="password" id="password" placeholder="Password" class="form__input-text" required>
</div>
<div class="form__group">
<label for="password-repeat" class="form__label"><i class="fas fa-lock"></i></label>
<input type="password" id="password-repeat" placeholder="Confirm Password" class="form__input-text" required>
</div>
<div class="form__group">
<label for="email" class="form__label"><i class="fas fa-envelope"></i></label>
<input type="email" id="email" placeholder="Email" class="form__input-text" required>
</div>
<div class="form__group form__group-selection">
<label for="location" class="form__label"><i class="fas fa-map-marker-alt"></i></label>
<select name="location" id="location" class="form__select">
<option class="form__select-option" value="selected" selected disabled>Select one option</option>
<option class="form__select-option" value="polska">Polska</option>
<option class="form__select-option" value="lotwa">Łotwa </option>
<option class="form__select-option" value="estonia">Estonia</option>
<option class="form__select-option" value="anglia">Anglia</option>
<option class="form__select-option" value="czopki">Czopki</option>
</select>
</div>
</form>
</div>
<div style="height: 5000px;"></div>
</div>
</body>
</html>
I have section that has few elements inside. They are all on the same line/row. I used div elements combined with CSS to put all elements next to each other. I'm not sure if this is the best practice to layout the elements and I'm open to suggestions. My problem is message box that is triggered if user didn't meet search criteria. Field box is set to display:none. After user clicks on the Search if message shows up everything shifts to the left. I'm wondering if message can expand to the right side of the screen instead of pushing elements to the left? Also I'm wondering how that would affect smaller screen and what would be the best option in that case?
$('#searchBtn').on('click',searchFun);
function searchFun(){
var menuVal = $.trim($('#menu').val()),
searchFldVal = $.trim($('#searchFld').val());
if(!searchFldVal){
$('#searchMsg').addClass("error").show().text('This field is required.').delay(4000).fadeOut('slow').queue(function(){
$(this).removeClass("error").dequeue();
});
}else if(searchFldVal.length < 3){
$('#searchMsg').addClass("error").show().text('You must enter at least 3 characters to search on.').delay(4000).fadeOut('slow').queue(function(){
$(this).removeClass("error").dequeue();
});
}else{
console.log('Search record.');
}
}
section.mainBox{
width: 100%;
padding-top: 0;
background-color: white;
border: 2px solid #000099;
}
div#Container {
padding-top: 8px;
padding-bottom: 8px;
text-align: center;
background-color: #B0C4DE;
border-bottom: 2px solid #000099;
}
div.nextTo {
display: inline-block;
margin-left: 5px;
}
span.msgMainBox {
display:none;
margin: 2px 5px;
padding:2px 25px 2px 35px;
}
span.error {
border: 1px solid;
margin: 5px;
padding:5px 10px 5px 40px;
background-repeat: no-repeat;
background-position: 10px center;
border-radius: 3px;
display: block;
}
span.error {
color: #D8000C;
background-color: #FFBABA;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section class="mainBox">
<div id="Container">
<div class="nextTo">
<select name="menu" id="menu">
<option value="1">Name</option>
<option value="2">DOB</option>
<option value="3">City</option>
</select>
</div>
<div class="nextTo">
<input type="text" name="searchFld" id="searchFld" size="24" maxlength="24" value="" title="Maximum size of the field is 24 characters." placeholder="Example: Marco Polo" />
</div>
<div class="nextTo">
<input type="button" name="searchBtn" id="searchBtn" value="Search"/>
</div>
<div class="nextTo">
<input type="button" name="lockBtn" id="lockBtn" value="Unlock" style="display:none" />
</div>
<div class="nextTo">
<span id="searchMsg" class="msgMainBox"></span>
</div>
</div>
</section>
You can make the element absolute position to avoid having the push effect. And for small screen it will go to the bottom:
$('#searchBtn').on('click', searchFun);
function searchFun() {
var menuVal = $.trim($('#menu').val()),
searchFldVal = $.trim($('#searchFld').val());
if (!searchFldVal) {
$('#searchMsg').addClass("error").show().text('This field is required.').delay(4000).fadeOut('slow').queue(function() {
$(this).removeClass("error").dequeue();
});
} else if (searchFldVal.length < 3) {
$('#searchMsg').addClass("error").show().text('You must enter at least 3 characters to search on.').delay(4000).fadeOut('slow').queue(function() {
$(this).removeClass("error").dequeue();
});
} else {
console.log('Search record.');
}
}
section.mainBox {
width: 100%;
padding-top: 0;
background-color: white;
border: 2px solid #000099;
}
div#Container {
padding-top: 8px;
padding-bottom: 8px;
text-align: center;
background-color: #B0C4DE;
border-bottom: 2px solid #000099;
}
div.nextTo {
display: inline-block;
margin-left: 5px;
}
div.nextTo:last-child {
position: absolute;
top: 6px;
}
span.msgMainBox {
display: none;
margin: 2px 5px;
padding: 2px 25px 2px 35px;
}
span.error {
border: 1px solid;
margin: 5px;
padding: 5px 10px 5px 40px;
background-repeat: no-repeat;
background-position: 10px center;
border-radius: 3px;
display: block;
}
span.error {
color: #D8000C;
background-color: #FFBABA;
}
#media all and (max-width:800px) {
div.nextTo:last-child {
position: static;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section class="mainBox">
<div id="Container">
<div class="nextTo">
<select name="menu" id="menu">
<option value="1">Name</option>
<option value="2">DOB</option>
<option value="3">City</option>
</select>
</div>
<div class="nextTo">
<input type="text" name="searchFld" id="searchFld" size="24" maxlength="24" value="" title="Maximum size of the field is 24 characters." placeholder="Example: Marco Polo">
</div>
<div class="nextTo">
<input type="button" name="searchBtn" id="searchBtn" value="Search">
</div>
<div class="nextTo">
<input type="button" name="lockBtn" id="lockBtn" value="Unlock" style="display:none">
</div>
<div class="nextTo">
<span id="searchMsg" class="msgMainBox"></span>
</div>
</div>
</section>
You can do it with the positioning, some modifications to margins and padding and #media queries which, when screen width gets too narrow, display the error message below and horizontally centered:
$('#searchBtn').on('click',searchFun);
function searchFun(){
var menuVal = $.trim($('#menu').val()),
searchFldVal = $.trim($('#searchFld').val());
if(!searchFldVal){
$('#searchMsg').addClass("error").show().text('This field is required.').delay(4000).fadeOut('slow').queue(function(){
$(this).removeClass("error").dequeue();
});
}else if(searchFldVal.length < 3){
$('#searchMsg').addClass("error").show().text('You must enter at least 3 characters to search on.').delay(4000).fadeOut('slow').queue(function(){
$(this).removeClass("error").dequeue();
});
}else{
console.log('Search record.');
}
}
section.mainBox{
width: 100%;
padding-top: 0;
background-color: white;
border: 2px solid #000099;
}
div#Container {
position: relative; /* added */
padding-top: 8px;
padding-bottom: 8px;
text-align: center;
background-color: #B0C4DE;
border-bottom: 2px solid #000099;
}
div.nextTo {
display: inline-block;
margin-left: 5px;
}
span.msgMainBox {
display: none;
margin: 2px 5px;
padding: 2px 25px 2px 35px;
}
span.error {
border: 1px solid;
/* added */
position: absolute;
top: 50%;
right: 0;
transform: translateY(-50%); /* vertically centered */
margin: 0 5px; /* modified */
padding: 0 5px; /* modified */
/***/
background-repeat: no-repeat;
background-position: 10px center;
border-radius: 3px;
display: block;
}
span.error {
color: #D8000C;
background-color: #FFBABA;
}
/* added */
#media screen and (max-width: 630px) { /* adjust to your needs */
span.error {
top: calc(100% + 5px); /* + 5px "margin-top" */
left: 50%;
transform: translateX(-50%); /* horizontally centered */
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section class="mainBox">
<div id="Container">
<div class="nextTo">
<select name="menu" id="menu">
<option value="1">Name</option>
<option value="2">DOB</option>
<option value="3">City</option>
</select>
</div>
<div class="nextTo">
<input type="text" name="searchFld" id="searchFld" size="24" maxlength="24" value="" title="Maximum size of the field is 24 characters." placeholder="Example: Marco Polo" />
</div>
<div class="nextTo">
<input type="button" name="searchBtn" id="searchBtn" value="Search"/>
</div>
<div class="nextTo">
<input type="button" name="lockBtn" id="lockBtn" value="Unlock" style="display:none" />
</div>
<div class="nextTo">
<span id="searchMsg" class="msgMainBox"></span>
</div>
</div>
</section>
I am not able to understand how I can get the label from top of the input field to the left. The label text is on top of the input field. How can I get it to the left of the input field for the contact information part? Any help would be appreciated. Thanks a lot.
This is my code:
#p1 {
text-align: center;
background-color: black;
color: white;
padding: 20px;
}
#h31 {
text-align: center;
}
#p2 {
text-align: center;
}
input[type="text"] {
border: 2px solid grey;
border-radius: 4px;
padding: 6px;
width: 90%;
background-color: #d3d3d3;
display: block;
margin: 8px 0;
}
input[type="text"]:focus {
border: 2px solid blue;
}
input[type="email"]:focus {
border: 2px solid blue;
}
::placeholder {
text-align: right;
}
input[type="submit"] {
background-color: #3cbc8d;
color: white;
border-radius: 4px;
padding: 16px 32px;
width: 100%;
}
input[type="email"] {
border: 2px solid grey;
padding: 6px;
width: 90%;
background-color: #d3d3d3;
display: block;
margin: 8px 0;
}
#p3 {
text-align: center;
}
#submitdiv {
text-align: center;
}
#textareadiv {
text-align: center;
}
textarea {
width: 100%;
}
hr {
width: 100%;
}
select {
background-color: #d3d3d3;
padding: 6px;
width: 90%;
display: block;
margin: 8px 0;
}
input[id="zipcode"] {
width: 40%;
}
body {
font-family: 'Merriweather', serif;
}
fieldset {
border: none;
}
#media screen and (min-width: 768px) {
.formcenter {
text-align: center;
display: block;
}
form {
text-align: left;
margin-left: auto;
margin-right: auto;
display: inline-block;
}
select {
width: 90%;
padding: 6px;
border-radius: 4px;
}
#p1 {
width: 100%;
}
hr {
width: 100%;
}
}
<link href="https://fonts.googleapis.com/css?family=Merriweather" rel="stylesheet">
<p id="p1">THE CODE REVIEW</p><br><br>
<div class="formcenter">
<form method="post" action="project3.html">
<h3 id="h31">Sign up for our newsletter</h3>
<p id="p2">Get the latest news on how your code is doing right in your inbox</p>
<hr>
<hr>
<fieldset>
<legend>
<h3 id="h32">Contact Information</h3>
</legend>
<label for="inputfield">Full Name</label>
<input type="text" name="fullname" placeholder="Required" id="inputfield">
<label for="inputfield1">Email Address</label>
<input type="email" name="emailaddress" placeholder="Required" id="inputfield1">
<label for="inputfield2">Phone Number</label>
<input type="text" name="phonenumber" id="inputfield2">
<label for="inputfield3">Street Address</label>
<input type="text" name="streetaddress" id="inputfield3">
<label for="inputfield4">City</label>
<input type="text" name="city" id="inputfield4">
<label for="stateselect">State</label>
<select name="state" id="stateselect">
<option>Choose State</option>
<option value="mah">Maharashtra</option>
<option value="guj">Gujarat</option>
<option value="pun">Punjab</option>
</select>
<label for="zipcode">Zip Code</label>
<input type="text" name="zipcode" id="zipcode">
</fieldset>
<hr>
<fieldset>
<legend>
<h3>Newsletter</h3>
</legend><br>
<label>Select the newsletters you would like to receive</label><br><br>
<input type="checkbox" name="htmlnews"><label>HTML News</label><br><br>
<input type="checkbox" name="css"><label>CSS News</label><br><br>
<input type="checkbox" name="javascript"><label>Javascript News</label><br><br>
<label>Newsletter format</label><br><br>
<input type="radio" name="newsletter" value="html"><label>HTML</label><br><br>
<input type="radio" name="newsletter" value="plaintext"><label>Plain Text</label><br><br>
<label>Other topics you'd like to hear about</label><br><br>
<div id="textareadiv">
<textarea rows="5" cols="30"></textarea><br><br>
</div>
<div id="submitdiv">
<input type="submit" value="Sign Up"><br><br>
</div>
</fieldset>
<p id="p3"><i>Copyright The Code Review</i></p>
</form>
</div>
You can reset width and display on inputs and/or use float.
It can be a reset at any time or within the mediaquerie.
You can also filter within which fieldset you need this reset to be effective.(example below)
.formcenter fieldset:first-of-type label,
.formcenter fieldset:first-of-type input{
float: left;
line-height: 1.2em;
padding: 6px;
margin: 8px 0;
width: 50%;
}
.formcenter fieldset:first-of-type label {
clear: left;
width: 35%;
}
input[type="checkbox"],
input[type="radio"]{
margin-right:1em;
}
fieldset ~ fieldset br + label {
margin:1em;
color:gray
}
#p1 {
text-align: center;
background-color: black;
color: white;
padding: 20px;
}
#h31 {
text-align: center;
}
#p2 {
text-align: center;
}
input[type="text"] {
border: 2px solid grey;
border-radius: 4px;
padding: 6px;
width: 90%;
background-color: #d3d3d3;
display: block;
margin: 8px 0;
}
input[type="text"]:focus {
border: 2px solid blue;
}
input[type="email"]:focus {
border: 2px solid blue;
}
::placeholder {
text-align: right;
}
input[type="submit"] {
background-color: #3cbc8d;
color: white;
border-radius: 4px;
padding: 16px 32px;
width: 100%;
}
input[type="email"] {
border: 2px solid grey;
padding: 6px;
width: 90%;
background-color: #d3d3d3;
display: block;
margin: 8px 0;
}
#p3 {
text-align: center;
}
#submitdiv {
text-align: center;
}
#textareadiv {
text-align: center;
}
textarea {
width: 100%;
}
hr {
width: 100%;
}
select {
background-color: #d3d3d3;
padding: 6px;
width: 90%;
display: block;
margin: 8px 0;
}
input[id="zipcode"] {
width: 40%;
}
body {
font-family: 'Merriweather', serif;
}
fieldset {
border: none;
}
#media screen and (min-width: 768px) {
.formcenter {
text-align: center;
display: block;
}
form {
text-align: left;
margin-left: auto;
margin-right: auto;
display: inline-block;
}
select {
width: 90%;
padding: 6px;
border-radius: 4px;
}
#p1 {
width: 100%;
}
hr {
width: 100%;
}
.formcenter fieldset:first-of-type label,
.formcenter fieldset:first-of-type input{
float: left;
line-height: 1.2em;
padding: 6px;
margin: 8px 0;
width: 50%;
}
.formcenter fieldset:first-of-type label {
clear: left;
width: 35%;
}
input[type="checkbox"],
input[type="radio"]{
margin-right:1em;
}
fieldset ~ fieldset br + label {
margin:1em;
color:gray
}
}
<link href="https://fonts.googleapis.com/css?family=Merriweather" rel="stylesheet">
<p id="p1">THE CODE REVIEW</p><br><br>
<div class="formcenter">
<form method="post" action="project3.html">
<h3 id="h31">Sign up for our newsletter</h3>
<p id="p2">Get the latest news on how your code is doing right in your inbox</p>
<hr>
<hr>
<fieldset>
<legend>
<h3 id="h32">Contact Information</h3>
</legend>
<label for="inputfield">Full Name</label>
<input type="text" name="fullname" placeholder="Required" id="inputfield">
<label for="inputfield1">Email Address</label>
<input type="email" name="emailaddress" placeholder="Required" id="inputfield1">
<label for="inputfield2">Phone Number</label>
<input type="text" name="phonenumber" id="inputfield2">
<label for="inputfield3">Street Address</label>
<input type="text" name="streetaddress" id="inputfield3">
<label for="inputfield4">City</label>
<input type="text" name="city" id="inputfield4">
<label for="stateselect">State</label>
<select name="state" id="stateselect">
<option>Choose State</option>
<option value="mah">Maharashtra</option>
<option value="guj">Gujarat</option>
<option value="pun">Punjab</option>
</select>
<label for="zipcode">Zip Code</label>
<input type="text" name="zipcode" id="zipcode">
</fieldset>
<hr>
<fieldset>
<legend>
<h3>Newsletter</h3>
</legend><br>
<label>Select the newsletters you would like to receive</label><br><br>
<input type="checkbox" name="htmlnews"><label>HTML News</label><br><br>
<input type="checkbox" name="css"><label>CSS News</label><br><br>
<input type="checkbox" name="javascript"><label>Javascript News</label><br><br>
<label>Newsletter format</label><br><br>
<input type="radio" name="newsletter" value="html"><label>HTML</label><br><br>
<input type="radio" name="newsletter" value="plaintext"><label>Plain Text</label><br><br>
<label>Other topics you'd like to hear about</label><br><br>
<div id="textareadiv">
<textarea rows="5" cols="30"></textarea><br><br>
</div>
<div id="submitdiv">
<input type="submit" value="Sign Up"><br><br>
</div>
</fieldset>
<p id="p3"><i>Copyright The Code Review</i></p>
</form>
</div>
You can use display:flex with a container for each lines
.line
{
display:flex;
align-items:center;
}
.line label
{
min-width:200px;
}
input
{
flex:1;
margin:10px;
}
#p1 {
text-align: center;
background-color: black;
color: white;
padding: 20px;
}
#h31 {
text-align: center;
}
#p2 {
text-align: center;
}
input[type="text"] {
border: 2px solid grey;
border-radius: 4px;
padding: 6px;
width: 90%;
background-color: #d3d3d3;
display: block;
margin: 8px 0;
}
input[type="text"]:focus {
border: 2px solid blue;
}
input[type="email"]:focus {
border: 2px solid blue;
}
::placeholder {
text-align: right;
}
input[type="submit"] {
background-color: #3cbc8d;
color: white;
border-radius: 4px;
padding: 16px 32px;
width: 100%;
}
input[type="email"] {
border: 2px solid grey;
padding: 6px;
width: 90%;
background-color: #d3d3d3;
display: block;
margin: 8px 0;
}
#p3 {
text-align: center;
}
#submitdiv {
text-align: center;
}
#textareadiv {
text-align: center;
}
textarea {
width: 100%;
}
hr {
width: 100%;
}
select {
background-color: #d3d3d3;
padding: 6px;
width: 90%;
display: block;
margin: 8px 0;
}
input[id="zipcode"] {
width: 40%;
}
body {
font-family: 'Merriweather', serif;
}
fieldset {
border: none;
}
#media screen and (min-width: 768px) {
.formcenter {
text-align: center;
display: block;
}
form {
text-align: left;
margin-left: auto;
margin-right: auto;
display: inline-block;
}
select {
width: 90%;
padding: 6px;
border-radius: 4px;
}
#p1 {
width: 100%;
}
hr {
width: 100%;
}
}
<link href="https://fonts.googleapis.com/css?family=Merriweather" rel="stylesheet">
<p id="p1">THE CODE REVIEW</p><br><br>
<div class="formcenter">
<form method="post" action="project3.html">
<h3 id="h31">Sign up for our newsletter</h3>
<p id="p2">Get the latest news on how your code is doing right in your inbox</p>
<hr>
<hr>
<fieldset>
<legend>
<h3 id="h32">Contact Information</h3>
</legend>
<div class="line">
<label for="inputfield">Full Name :</label>
<input type="text" name="fullname" placeholder="Required" id="inputfield">
</div>
<div class="line">
<label for="inputfield1">Email Address :</label>
<input type="email" name="emailaddress" placeholder="Required" id="inputfield1">
</div>
<div class="line">
<label for="inputfield2">Phone Number :</label>
<input type="text" name="phonenumber" id="inputfield2">
</div>
<div class="line">
<label for="inputfield3">Street Address :</label>
<input type="text" name="streetaddress" id="inputfield3">
</div>
<div class="line">
<label for="inputfield4">City :</label>
<input type="text" name="city" id="inputfield4">
</div>
<div class="line">
<label for="stateselect">State :</label>
<select name="state" id="stateselect">
<option>Choose State</option>
<option value="mah">Maharashtra</option>
<option value="guj">Gujarat</option>
<option value="pun">Punjab</option>
</select>
</div>
<div class="line">
<label for="zipcode">Zip Code :</label>
<input type="text" name="zipcode" id="zipcode">
</div>
</fieldset>
<hr>
<fieldset>
<legend>
<h3>Newsletter</h3>
</legend><br>
<label>Select the newsletters you would like to receive</label><br><br>
<input type="checkbox" name="htmlnews"><label>HTML News</label><br><br>
<input type="checkbox" name="css"><label>CSS News</label><br><br>
<input type="checkbox" name="javascript"><label>Javascript News</label><br><br>
<label>Newsletter format</label><br><br>
<input type="radio" name="newsletter" value="html"><label>HTML</label><br><br>
<input type="radio" name="newsletter" value="plaintext"><label>Plain Text</label><br><br>
<label>Other topics you'd like to hear about</label><br><br>
<div id="textareadiv">
<textarea rows="5" cols="30"></textarea><br><br>
</div>
<div id="submitdiv">
<input type="submit" value="Sign Up"><br><br>
</div>
</fieldset>
<p id="p3"><i>Copyright The Code Review</i></p>
</form>
</div>
Swap your labels and inputs to get desired result:
#p1 {
text-align: center;
background-color: black;
color: white;
padding: 20px;
}
#h31 {
text-align: center;
}
#p2 {
text-align: center;
}
input[type="text"] {
border: 2px solid grey;
border-radius: 4px;
padding: 6px;
width: 90%;
background-color: #d3d3d3;
display: block;
margin: 8px 0;
}
input[type="text"]:focus {
border: 2px solid blue;
}
input[type="email"]:focus {
border: 2px solid blue;
}
::placeholder {
text-align: right;
}
input[type="submit"] {
background-color: #3cbc8d;
color: white;
border-radius: 4px;
padding: 16px 32px;
width: 100%;
}
input[type="email"] {
border: 2px solid grey;
padding: 6px;
width: 90%;
background-color: #d3d3d3;
display: block;
margin: 8px 0;
}
#p3 {
text-align: center;
}
#submitdiv {
text-align: center;
}
#textareadiv {
text-align: center;
}
textarea {
width: 100%;
}
hr {
width: 100%;
}
select {
background-color: #d3d3d3;
padding: 6px;
width: 90%;
display: block;
margin: 8px 0;
}
input[id="zipcode"] {
width: 40%;
}
body {
font-family: 'Merriweather', serif;
}
fieldset {
border: none;
}
#media screen and (min-width: 768px) {
.formcenter {
text-align: center;
display: block;
}
form {
text-align: left;
margin-left: auto;
margin-right: auto;
display: inline-block;
}
select {
width: 90%;
padding: 6px;
border-radius: 4px;
}
#p1 {
width: 100%;
}
hr {
width: 100%;
}
}
<link href="https://fonts.googleapis.com/css?family=Merriweather" rel="stylesheet">
<p id="p1">THE CODE REVIEW</p><br><br>
<div class="formcenter">
<form method="post" action="project3.html">
<h3 id="h31">Sign up for our newsletter</h3>
<p id="p2">Get the latest news on how your code is doing right in your inbox</p>
<hr>
<hr>
<fieldset>
<legend>
<h3 id="h32">Contact Information</h3>
</legend>
<label for="inputfield">Full Name</label>
<input type="text" name="fullname" placeholder="Required" id="inputfield">
<label for="inputfield1">Email Address</label>
<input type="email" name="emailaddress" placeholder="Required" id="inputfield1">
<label for="inputfield2">Phone Number</label>
<input type="text" name="phonenumber" id="inputfield2">
<label for="inputfield3">Street Address</label>
<input type="text" name="streetaddress" id="inputfield3">
<label for="inputfield4">City</label>
<input type="text" name="city" id="inputfield4">
<label for="stateselect">State</label>
<select name="state" id="stateselect">
<option>Choose State</option>
<option value="mah">Maharashtra</option>
<option value="guj">Gujarat</option>
<option value="pun">Punjab</option>
</select>
<label for="zipcode">Zip Code</label>
<input type="text" name="zipcode" id="zipcode">
</fieldset>
<hr>
<fieldset>
<legend>
<h3>Newsletter</h3>
</legend><br>
<label>Select the newsletters you would like to receive</label><br><br>
<label>HTML News</label><input type="checkbox" name="htmlnews"><br><br>
<label>CSS News</label><input type="checkbox" name="css"><br><br>
<label>Javascript News</label><input type="checkbox" name="javascript"><br><br>
<label>Newsletter format</label><br><br>
<label>HTML</label><input type="radio" name="newsletter" value="html"><br><br>
<label>Plain Text</label><input type="radio" name="newsletter" value="plaintext"><br><br>
<label>Other topics you'd like to hear about</label><br><br>
<div id="textareadiv">
<textarea rows="5" cols="30"></textarea><br><br>
</div>
<div id="submitdiv">
<input type="submit" value="Sign Up"><br><br>
</div>
</fieldset>
<p id="p3"><i>Copyright The Code Review</i></p>
</form>
</div>
You can do this fairly easily:
Full Name: <input type="text" name="fullname" placeholder="Required" id="inputfield">
This will just make the text appear to the left side of the input itself.
I used this method for a newsletter input I was doing:
Name: <input id="nameInput" type="text" name="name" required><br>