HTML CSS align boxes of different sizes - html

I have two boxes a text box and a drop down menu box.
The problem is that the drop down box align so far to the right.
What i want is to have the label text to the left. Then comes a defined amount of space. Then all boxes start at a certain position.
As it is right now the boxes all end at the same position.
body {
font-size: 100%;
background-color: black;
}
label {
float: left;
font-size: 1.3em;
padding-right: 0.625em;
}
.box {
color: rgb(255, 255, 255);
clear: both;
text-align: right;
line-height: 1.5625em;
}
.main {
float: left;
}
.menu {
color: rgb(255, 255, 255);
clear: both;
text-align: right;
line-height: 1.5625em;
}
<div class="main">
<div class="box">
<label for="test">test </label>
<input type="text" id="test" placeholder="placeholder" />
<div class="menu">
<label for="peashooter">peas</label>
<select id="peashooter">
<option value="peas">peas</option>
<option value="peas">peas</option>
<option value="peas">peas</option>
<option value="peas">peas</option>
</select>
</div>
</div>
I want the boxes to align to the drawn left line:

You can do it with grid layout.
Check: https://jsfiddle.net/filipasimao/Lca19d7z/
body {
font-size: 1.2rem;
background-color: black;
color: white;
}
.main {
display: grid;
grid-template-columns: 60px auto;
grid-row-gap: 5px;
}
<div class="main">
<label for="foo">foo</label>
<input type="text" id="foo" placeholder="foo placeholder" />
<label for="bar">bar</label>
<select id="bar">
<option value="bar1">bar 1</option>
<option value="bar2">bar 2</option>
<option value="bar3">bar 3</option>
<option value="bar4">bar 4</option>
</select>
</div>

One approach is to make label part fixed with some determined width up-front, e.g. 50 pixels, plus apply text-align:left as Sarthak Jha mentioned. You can also specify width in % and limit it with max-width in pixels, also use overflow hidden or auto etc. In-browser page zoom will not disrupt the alignment.
body
{
font-size:100%;
background-color:black;
}
label
{
float:left;
font-size:1.3em;
padding-right:0.625em;
width:15%;
min-width:45px;
max-width:150px;
}
.box
{
color:rgb(255, 255, 255);
clear:both;
text-align:left;
line-height:1.5625em;
}
.main{
float:left;
}
.menu
{
color:rgb(255, 255, 255);
clear:both;
text-align:left;
line-height:1.5625em;
}
<div class="main">
<div class="box">
<label for="test">test </label>
<input type="text" id="test" placeholder="placeholder" />
<div class="menu">
<label for="peashooter">peas</label>
<select id="peashooter">
<option value="peas">peas</option>
<option value="peas">peas</option>
<option value="peas">peas</option>
<option value="peas">peas</option>
</select>
</div>
</div>

.menu
{
color: rgb(255, 255, 255);
clear:both;
text-align:left;
line-height: 1.5625em; /* The distance between each box */
}
Make it " text-align: left "

You can use float: left on your #peashooter and give your label elements a width so that your inputs align correctly:
body {
font-size: 100%;
background-color: black;
}
label {
float: left;
font-size: 1.3em;
padding-right: 0.625em;
}
.box {
color: rgb(255, 255, 255);
clear: both;
text-align: right;
line-height: 1.5625em;
}
.main {
float: left;
}
.menu {
color: rgb(255, 255, 255);
clear: both;
text-align: right;
line-height: 1.5625em;
}
.main #peashooter {
float: left;
}
.main label {
width: 30px;
}
<div class="main">
<div class="box">
<label for="test">test </label>
<input type="text" id="test" placeholder="placeholder" />
<div class="menu">
<label for="peashooter">peas</label>
<select id="peashooter">
<option value="peas">peas</option>
<option value="peas">peas</option>
<option value="peas">peas</option>
<option value="peas">peas</option>
</select>
</div>
</div>
</div>

Related

How to fit inputs inside fieldset

my <input type=text> are longer then <select> tags. How do I make inputs have the same width as selects?
form fieldset {
width: 50%;
margin: auto;
border: 3px solid grey;
padding: 10px;
}
form fieldset legend {
font-size: 20px;
font-weight: bold;
}
form label {
font-weight: bold;
font-size: 16px;
margin-top: 10px;
}
form input, select {
margin-bottom: 10px;
padding: 5px;
border: 0;
border-bottom: 1px solid grey;
font-size: 16px;
width: 100%;
font-family: 'Poppins';
}
form input[type=submit] {
font-size: 20px;
border: 0;
font-weight: bold;
margin-top: 10px;
}
form input:focus, select:focus {
outline: none;
border-bottom: 2px solid black;
}
form div.submit {
width: 20%;
margin-left: auto;
margin-right: auto;
}
<!DOCTYPE html>
<html lang='cs'>
<head>
<meta charset='UTF-8'>
<title>Title</title>
</head>
<body>
<form method='POST' action='quotation.php?a=insert'>
<fieldset>
<legend>My legend</legend>
<label for='customer'>Customer: </label><br>
<select name='customer' id='customer'>
<option value='NULL'></option>
<option value='1'>Cust. 1</option>
<option value='2'>Cust. 2</option>
<option value='3'>Cust. 3</option>
</select><br>
<label for='contact_person'>Contact person: </label><br>
<select name='contact_person' id='contact_person'>
<option value='NULL'></option>
<option value='1'>CP 1</option>
<option value='2'>CP 2</option>
<option value='3'>CP 3</option>
</select><br>
<label for='project'>Project: </label><br>
<input type='text' name='project' id='project'><br>
<label for='part'>Part: </label><br>
<input type='text' name='part' id='part'><br>
<label for='recieved'>Recieved: </label><br>
<input type='date' name='recieved' id='recieved'><br>
<label for='deadline'>Deadline: </label><br>
<input type='date' name='deadline' id='deadline'><br>
<div class='submit'>
<input type='submit' value='Save'>
</div>
</fieldset>
</form>
</body>
</html>
Thank you for any idea.
I tried to set padding of whole fieldset:
fieldset { padding: 5px }
This is correct with tag but doesn't work with .
Then I tried to set: input {margin: 5px} but this didn't work as well. In the chrome DevTools i see that the margin is ouside of the fieldset area.
Because of padding, the border overflows the box so keep the top and bottom 5px and add 0 for right and left.
form input, select {
margin-bottom: 10px;
padding: 5px 0;
border: 0;
border-bottom: 1px solid grey;
font-size: 16px;
width: 100%;
font-family: 'Poppins';
}
Just update css style.
form input, select{
padding: 5px 0;}
I added this into CSS:
form input, select {
box-sizing: border-box;
}
This resolved my issue.

button is lower than others elements form

I just would like to know why my button tag is lower than select tag ?
This is my HTML :
<div class="wrap-form-planning">
<form class="form_search_order form-planning" name="form_search_client">
<!-- Chauffeur -->
<select type="search" name="chauffeur_name[]" class="select-chauffeur selectpicker" multiple size="2">
<option value="" selected>Nom du chauffeur</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
<!-- Client -->
<select type="search" name="client_name[]" class="select-client" multiple size="2">
<option value="" selected>Nom du client</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
<!-- Semaine -->
<select name="semaine[]" id="semaine" class="select-semaine" multiple size="2">
<option value="" selected>Semaine</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
<button type="submit" class="inp-submit-form-planning"><i class="fa fa-search"></i></button>
</form>
</div>
My CSS :
.wrap-form-planning{
display: block;
background-color: $bleu;
padding: 20px 0;
text-align: center;
}
.form-planning{
width:80%;
max-width: 1080px;
margin: auto;
margin-right: 10px;
select{
font-size: 14px;
margin-right: 10px;
width: (14%-10px);
border-radius: 0;
&.select-chauffeur{
min-width: 150px;
}
&.select-client{
min-width: 120px;
}
&.select-semaine{
min-width: 90px;
margin-right: 0;
}
}
.inp-submit-form-planning{
font-size: 14px;
color: white;
background: $bleu;
border: solid 2px white;
padding: 4px 9px;
&:hover{
color: $bleu;
background: white;
cursor: pointer;
transition: 0.6s;
}
}
}
here is a screen :
They're different sized inline-block elements, so they will aligned baseline by default. You also have a 2px white border on the search icon
You can use form.form_search_order > * { vertical-align: middle; } whatever vertical-align property you want.
But I would use a flex layout. Add display: flex to the form, and use align-items to align them vertically however you want. Also added justify-content: center to horizontally center them since you had text-align: center on the parent originally.
body {
background: blue;
}
.wrap-form-planning {
display: block;
padding: 20px 0;
text-align: center;
}
.form-planning {
width: 80%;
max-width: 1080px;
margin: auto;
margin-right: 10px;
}
.form-planning select {
font-size: 14px;
margin-right: 10px;
width: calc(14% - 10px);
border-radius: 0;
}
.form-planning select.select-chauffeur {
min-width: 150px;
}
.form-planning select.select-client {
min-width: 120px;
}
.form-planning select.select-semaine {
min-width: 90px;
margin-right: 0;
}
.form-planning .inp-submit-form-planning {
font-size: 14px;
color: white;
border: solid 2px white;
padding: 4px 9px;
}
.form-planning .inp-submit-form-planning:hover {
background: white;
cursor: pointer;
transition: 0.6s;
}
form.form_search_order {
display: flex;
align-items: flex-end;
justify-content: center;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="wrap-form-planning">
<form class="form_search_order form-planning" name="form_search_client">
<!-- Chauffeur -->
<select type="search" name="chauffeur_name[]" class="select-chauffeur selectpicker" multiple size="2">
<option value="" selected>Nom du chauffeur</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
<!-- Client -->
<select type="search" name="client_name[]" class="select-client" multiple size="2">
<option value="" selected>Nom du client</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
<!-- Semaine -->
<select name="semaine[]" id="semaine" class="select-semaine" multiple size="2">
<option value="" selected>Semaine</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
<button type="submit" class="inp-submit-form-planning"><i class="fa fa-search"></i></button>
</form>
</div>

body Margin property not working

Here is my code In HTML
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Selection</title>
<link rel="stylesheet" href="style.css">
</head>
<body >
<div id="container" >
<form action="http://localhost:8084/CBGS/Allocate" method="Get">
<h1>College EXAM SECTION</h1>
<div id="sem">Semester:
<select name="sem">
<option value="3" >Sem3</option>
<option value="4">Sem4</option>
<option value="5">Sem5</option>
<option value="6">Sem6</option>
</select>
</div>
<div id="branch">Branch:
<select name="branch">
<option value="IT" >IT</option>
<option value="COMP">COMP</option>
<option value="MECH">MECH</option>
<option value="CIVIL">CIVIL</option>
<option value="EXTC">EXTC</option>
</select>
</div>
<div id="exam">
<input type="radio" name="exam" value="R" />REGULAR<br>
<input type="radio" name="exam" value="K"/>KT
</div>
<div id="numberstudent">
No of student
<input type="number" name="noOfStudent" min="1" max="100">
</div>
< input type ="submit">
</form>
</div>
</body>
</html>
and style .css is
body
{
margin: 0px auto;
width:700px;
//margin:0 auto;
//margin-left:50px;
font-family:Arial, Helvetica, sans-serif;
font-size:100%;
color: white;
line-height:1em;
background-image: url("image/tail-middle.jpg");
background-repeat: repeat-y;
}
#container
{
background:url(image/newsletter-bg.gif) ;
display: block;
border-radius:10px;
// border:10px solid ;//#EE872A;
//background-color: yellow;
width:600px;
margin-left: auto;
margin-right: auto;
margin-top: 10%;
padding: 20px;
}
h1{
//color: black;
margin-left: 20px;
}
#sem , #branch, #exam,#numberstudent {
display: block;
//color: blueviolet;
}
#branch,#sem {
float: left;
}
#exam{
clear: both;
}
#numberstudent{
margin-left: auto;
margin-right: auto;
}
but here margin:0 auto not work,as my image not shift towards center,even i use margin-left it also not working,what wong in my code,any suggestion are most welcome
----------
body {
margin: 0px auto;
width: 700px;
font-family: Arial, Helvetica, sans-serif;
font-size: 100%;
color: white;
line-height: 1em;
background-image: url("image/tail-middle.jpg") #ccc;
background-repeat: repeat-y;
background-position: 50% 0;
}
.wrapper{
width:100%;
background-image:url("http://www.corelangs.com/html/html.png");
background-repeat:no-repeat;
}
#container {
background: url(image/newsletter-bg.gif);
display: block;
border-radius: 10px;
/*border:10px solid ;//#EE872A;
background-color: yellow;*/
width: 600px;
margin-left: auto;
margin-right: auto;
margin-top: 10%;
padding: 20px;
}
h1 {
//color: black;
margin-left: 20px;
}
#sem,
#branch,
#exam,
#numberstudent {
display: block;
//color: blueviolet;
}
#branch,
#sem {
float: left;
}
#exam {
clear: both;
}
#numberstudent {
margin-left: auto;
margin-right: auto;
}
<html>
<head>
</head>
<body>
<div class="wrapper">
<div id="container">
<form action="http://localhost:8084/CBGS/Allocate" method="Get">
<h1>College EXAM SECTION</h1>
<div id="sem">Semester:
<select name="sem">
<option value="3">Sem3</option>
<option value="4">Sem4</option>
<option value="5">Sem5</option>
<option value="6">Sem6</option>
</select>
</div>
<div id="branch">Branch:
<select name="branch">
<option value="IT">IT</option>
<option value="COMP">COMP</option>
<option value="MECH">MECH</option>
<option value="CIVIL">CIVIL</option>
<option value="EXTC">EXTC</option>
</select>
</div>
<div id="exam">
<input type="radio" name="exam" value="R" />REGULAR
<br>
<input type="radio" name="exam" value="K" />KT
</div>
<div id="numberstudent">
No of student
<input type="number" name="noOfStudent" min="1" max="100">
</div>
< input type="submit">
</form>
</div>
</div>
</body>
</html>
Please Try this
Try to add the following in your css:
body{margin: 0px auto !important; width:700px;}
Have you tried using the asterisk(*) selector before the body and setting the margin to 0?
Example:
* {
margin: 0;
}
Try to add text-align: center; in your css. Even if it's not text, this property is needed often.

How to prevent CSS block elements from affecting parent inline-blocks

I am having an issue with elements inside an inline-block parent. The child elements of one are affecting the other. It is tough to explain but it is easy to see in my fiddle, that the div on the right is being pushed down.
I have tried various things, but I am sure there is a simple solution. Any advice is appreciated.
http://jsfiddle.net/62asy/
HTML:
<div id="schedule">
<div class="scheduleChoice">Leagues
<select name="leagueList" id="leagueList" class="scheduleChoiceList">
<option value="0">Select a League</option>
<option value="leagueId_246"> Aassss</option>
<option value="leagueId_245"> aaa</option>
</select>
<select name="teamList" id="teamList" class="scheduleChoiceList">
</select>
<div class="scheduleChoiceSubmit">Submit</div>
</div>
<div class="scheduleChoice">Arena
<select name="arenaList" id="arenaList" class="scheduleChoiceList">
<option value="0">Select an Arena</option>
<option value="arenaId_2"> ffffff</option>
<option value="arenaId_1"> ffffff</option>
</select>
<div class="scheduleChoiceSubmit">Submit</div>
</div>
</div>
CSS:
#schedule {
background-color: rgba(0, 0, 0, 0.44);
overflow: hidden;
text-align: center;
}
.scheduleChoice {
display: inline-block;
width: 25%;
background-color: rgba(190, 216, 255, 0.54);
height: 200px;
padding: 5px;
border-radius: 5px;
margin: 20px 25px;
}
.scheduleChoiceList {
width: 200px;
padding: 5px;
border-radius: 4px;
display: block;
margin: 10px auto;
}
Add vertical align top
.scheduleChoice {
vertical-align: top;
}
Edited fiddle
http://jsfiddle.net/62asy/1/

Sometimes DIVs are making like a ladder

I am developing a Chrome extension.
Sometimes when I'm clicking on the extension icon, divs are making like a "ladder":
I want it to be like this:
How can I ensure the currency fields are aligned properly?
Here is my markup:
<div class="calc">
<div class="in">
<img id="cur-img-in" src="img/AMD.gif"/>
<select name="currency-calc-cur" id="in-select">
<option selected="selected" value="AMD">AMD</option>
<option value="EUR">EUR</option>
<option value="RUR">RUR</option>
<option value="USD">USD</option>
</select>
<input type="text" id="in"/>
</div>
<img id='swap-cur' src="img/swap.png" alt="Swap"/>
<div class="out">
<img id="cur-img-out" src="img/USD.gif"/>
<select name="currency-calc-cur" id="out-select">
<option value="AMD">AMD</option>
<option value="EUR">EUR</option>
<option value="RUR">RUR</option>
<option selected="selected" value="USD">USD</option>
</select>
<input type="text" id="out"/>
</div>
</div>
And style:
.calc {
margin-top: 10px;
margin-left: 20%;
width: 60%;
}
.calc input[type="text"] {
width: 100%;
}
.calc #bank-list {
width: 100%;
}
.calc [name="currency-calc-cur"] {
width: 78%;
}
.calc .in {
width: 40%;
position: relative;
float: left;
}
.calc .out {
width: 40%;
position: relative;
float: right;
}
.calc #swap-cur {
margin: 17px 0 0 16px;
}
And my sources from GitHub if something is missing.
Your image likely needs to be floated as well.
.calc #swap-cur {
float: left;
margin: 17px 0 0 16px;
}