How do I align two divs on the left and right vertically? - html

I have a problem trying to align my dropdown list vertically with my textarea on the left somehow. I do not know why it is clashing together.
EDIT:Thanks for the help, I have made changes to achieve it.
JSP:
.ExeDropdown{
float:left;
margin-left:50px;
}
div.txt1{
float: left;
margin-left:50px;
}
div.txt2{
float:right;
margin-right: 120px;
}
.txt3{
float:right;
margin-right: 120px;
}
#subBtn{
position: absolute;
bottom: 20%;
left:47%;
}
<div class="ExeDropdown">
Select an exercise:
<select name="ProgExe">
<option value="exe1">Exercise 1</option>
<option value="exe2">Exercise 2</option>
</select>
</div>
<div class="txt1" >
<p>Write your source code here:</p>
<textarea id="myTextArea" rows="5" cols="40" name="txtInput" >
</textarea>
</div>
https://i.stack.imgur.com/Vok8d.jpg

Here you go :
HTML:
<div class="ExeDropdown">
Select an exercise:
<select name="ProgExe">
<option value="exe1">Exercise 1</option>
<option value="exe2">Exercise 2</option>
</select>
</div>
<div class="clear"></div>
<div class="txt1" >
<p>Write your source code here:</p>
<textarea id="myTextArea" rows="5" cols="40" name="txtInput" >
</textarea>
</div>
CSS:
.clear{clear:both;}

Take out the float:left; on both of the elements you mentioned (.ExeDropdown, div.txt1).
it should work then

Add a (line-) break before it:
Select an exercise:
<br /> <!-- here -->
<select name="ProgExe">

Related

Display div elements in one line

I have three elements in my div dropdown list, input date and button they are all in on div , i want all of them to be in the same line , not under each other
<div id="cont">
Status :
<select id="dropdown">
<option value="Approved">Approved</option>
<option value="Rejected">Rejected</option>
<option value="Pending">Pending</option>
<option value="Error">Error</option>
</select>
<!-- Date Picker -->
<p>Date:
<input type="text" id="datepicker">
</p>
<button type="submit" id="searchBtn" value="">Search</button>
</div>
Use CSS with display: inline-block
.inline {
display: inline-block;
}
<div id="cont">
Status:
<select id="dropdown" class="inline">
<option value="Approved">Approved</option>
<option value="Rejected">Rejected</option>
<option value="Pending">Pending</option>
<option value="Error">Error</option>
</select>
<!-- Date Picker -->
<p class="inline">Date:
<input type="text" id="datepicker">
</p>
<button type="submit" id="searchBtn" value="" class="inline">Search</button>
</div>
Although the above works, it's better practice to put the specific elements in a span tag. Like so ...
.inline {
display: inline-block;
}
<div id="cont">
<span class="inline">Status:
<select id="dropdown">
<option value="Approved">Approved</option>
<option value="Rejected">Rejected</option>
<option value="Pending">Pending</option>
<option value="Error">Error</option>
</select>
</span>
<!-- Date Picker -->
<span class="inline">
<p>Date: <input type="text" id="datepicker"></p>
</span>
<span class="inline">
<button type="submit" id="searchBtn" value="">Search</button>
</span>
</div>
You can add the display: inline-block property to the divs. This will make them get rendered inline with the content, but they keep their block properties, so you can still set their width and height for example.
Example:
.inline {
display: inline-block;
width: 50px;
height: 20px;
}
#red {
background-color: red;
}
#green {
background-color: green;
}
#blue {
background-color: blue;
}
<div class="inline" id="red"></div>
<div class="inline" id="blue"></div>
<div class="inline" id="green"></div>
My favourite tutorial site about the topic: http://learnlayout.com/inline-block.html
This can be used for every element, which supports the display property. Some elements are even set to this by default, like the span element.
https://jsfiddle.net/v9qxobaf/
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>test</title>
</head>
<style media="screen">
#cont {
margin-left: -20px;
}
.status, .date, .button {
float: left;
padding-left: 20px;
}
</style>
<body>
<div id="cont">
<div class="status">
<label>Status: </label>
<select id="dropdown">
<option value="Approved">Approved</option>
<option value="Rejected">Rejected</option>
<option value="Pending">Pending</option>
<option value="Error">Error</option>
</select>
</div>
<div class="date">
<!-- Date Picker -->
<span> Date: <input type="text" id="datepicker"></span>
</div>
<div class="button">
<button type="submit" id="searchBtn" value="">Search</button>
</div>
</div>
</body>
</html>
wrap each in a div and display: inline-block.

How do I put space between top of all elements inside a div?

Let's assume I have a HTML like this:
<div id='main'>
<select name='foo'>
<option>A</option>
<option>B</option>
</select>
<br>
<select name='baa'>
<option>C</option>
<option>D</option>
</select>
<br>
</div>
I'm looking for a CSS rule to make a space between top of these elements, like I had a margin-top: 10px; on every element in main div. How can I make this? Searching I found this solution:
border-collapse: separate;
border-spacing: 0 1em;
But it didn't work in the way I described.
It looks like using a css universal selector will do the trick:
#main *{ /* see the asterisk in the selector here, that's what you're after*/
margin-top: 10px;
}
<div id='main'>
<select name='foo'>
<option>A</option>
<option>B</option>
</select>
<br>
<select name='baa'>
<option>C</option>
<option>D</option>
</select>
<br>
</div>
Give your select a class, then add a margin to the class.
Like this:
.center {
text-align: center;
color: red;
margin-top: 10px
}
<div id='main'>
<select name='foo' class="center">
<option>A</option>
<option>B</option>
</select>
<br>
<select name='baa' class="center">
<option>C</option>
<option>D</option>
</select>
<br>
</div>

How do I make this search form appear correctly on IE6 - IE8?

I'm working on an app and part of the project requirements is that the entire site be compatible with IE6 - IE8. So far, the rest of the website looks good on older browsers except for this search form I created.
This is what it looks like on modern browsers, and is what it's supposed to look like in general: ,
...but this is what it looks like on IE6: .
Does anyone have some experience with trying to make table-less layouts work on older browsers, or has run into a similar issue in the past? Basically I have containers holding each label / input, and need them to display next to each other in three's per row, with the label and input next to each other ass seen on the first image.
Below is the code regarding these elements.
EDIT: I added a few more things to both the html and css for easier deployment on your own computers.
Thanks for any help you can provide!
HTML
<div class="mid">
<h2>Search and filter by:</h2>
<!-- 1st Row Starts -->
<form action="" method="post" id="main-search-form"> <!-- containing form for search -->
<div id="search-container" align="center">
<div class="search" align="center">
<form>
<label>Keywords</label>
<input type="text" name="keywords" value="" id="keywords" placeholder="enter search terms here...">
</form>
</div>
<div class="search" align="center">
<label>Category</label>
<select>
<option value="" disabled selected>Select Category</option>
<option value="">Category 1</option>
<option value="">Category 2</option>
<option value="">Category 3</option>
<option value="">Category 4</option>
<option value="">Category 5</option>
</select>
</div>
<div class="search" align="center">
<label>Service</label>
<select>
<option value="" disabled selected>Select Service</option>
<option value="food">Food and Nutrition Support</option>
<option value="shelter">Shelter and Care</option>
<option value="protection">Protection</option>
<option value="healthcare">Healthcare</option>
<option value="pyschosocial">Psychosocial Support Services</option>
<option value="education">Formal and informal education</option>
<option value="legal">Legal Services</option>
<option value="other">Other Services</option>
</select>
</div>
</div> <!-- //.search-container -->
<!-- // 1st Row -->
<!-- 2nd Row Starts -->
<div id="search-container" align="center">
<div class="search" align="center">
<label>Age</label>
<select>
<option value="" disabled selected>Select Age</option>
<option value="">Age 1-3</option>
<option value="">Age 4-10</option>
<option value="">Age 11-14</option>
<option value="">Age 15-18</option>
</select>
</div>
<div class="search" align="center">
<label>Gender</label>
<select>
<option value="" disabled selected>Select Gender</option>
<option value="male">Male</option>
<option value="female">Female</option>
</select>
</div>
<div class="search" align="center">
<label>Region</label>
<select>
<option value="" disabled selected>Select Region</option>
<option value="">Category 1</option>
<option value="">Category 2</option>
<option value="">Category 3</option>
<option value="">Category 4</option>
<option value="">Category 5</option>
</select>
</div>
</div><!-- //.search-container -->
<!-- // 2nd Row -->
<!-- 3rd Row Starts Here -->
<div class="search-container" align="center">
<div class="search" align="center">
<form class="checkbox">
<label>Day</label>
<input type="checkbox" name="monday" value="Monday">M
<input type="checkbox" name="tuesday" value="Tuesday">T
<input type="checkbox" name="wednesday" value="Wednesday">W
<input type="checkbox" name="thursday" value="Thursday">R
<input type="checkbox" name="friday" value="Friday">F
<input type="checkbox" name="saturday" value="Saturday" >Sa
<input type="checkbox" name="sunday" value="Tuesday">Su
</form>
</div>
</div>
</form>
</div>
CSS
.mid {background: #258db1; color: #fff; padding: 20px 0 30px 0;}
.mid h2 {color: #fff; text-align: center;}
.mid h2, .mid h3, .mid p, .footnote p {color:#fff;}
/* SEARCH */
#main-search-form {width: 100%;}
.search {min-width: 250px; display: inline; margin:0; position:relative;}
.search select {background: #fff; height: 40px; width: 150px; margin-bottom: 30px; margin-right: 30px; position:relative; display: inline;}
.search option, {padding: 10px; position:relative; display: inline;}
.search, .search label {display: inline;}
.search input#keywords {display: inline; position: relative; min-width: 250px; background: #fff; margin-right: 20px;}
.search .checkbox input {display: inline; position: relative; width: 15px!important; height: 15px!important; margin-left: 10px!important; margin-right: 2px!important;}
.search .checkbox label {display: inline; position: relative; margin-right: 10px;}
#media (max-width: 959px) {
.search {disply: block; clear:both;}
.search input, .search select, .search input#keywords {display:block; margin-bottom: 20px; margin-top: 8px; width: 60%!important; margin-left:30px;}
.search, .search label, .search input#keywords {display: block; clear:both;}
}
Remove align='center' attribute in #search

Bootstrap 3: how to create an inline form with selects and labels?

My labels keep appearing above the selects. I want them all on the same line. Pls see the jsfiddle: http://jsfiddle.net/jjgelinas77/9nL9x/
<div class="well well-sm">
<form name="myForm" role="form" novalidate="novalidate" class="form-inline">
<div class="form-group">
<label>C-Band</label>
<select id="cband" class="form-control">
<option value="C15+">C15+</option>
<option value="C12-14">C12-14</option>
<option value="Other">Other</option>
</select>
</div>
<div class="form-group">
<label>C-Band</label>
<select ng-model="form.cband2" id="cband2" class="form-control">
<option value="C15+">C15+</option>
<option value="C12-14">C12-14</option>
<option value="Other">Other</option>
</select>
</div>
<button class="btn btn-primary">Filter</button>
</form>
</div>
There's a CSS rule in bootstrap that sets the width of .form-control to 100% on small screen sizes. So even when it's floated, it will take the whole width and therefore start on a new line. Good news is you only need a couple lines of CSS to override it:
.form-control {
width:auto;
display:inline-block;
}
Hope this simplifies the problem for anyone still facing the issue! http://jsfiddle.net/c3m77ah6/2/
You have to wrap your label around the select. Like this:
<div class="form-group">
<label>C-Band
<select id="cband" class="form-control">
<option value="C15+">C15+</option>
<option value="C12-14">C12-14</option>
<option value="Other">Other</option>
</select>
</label>
</div>
And then add the following CSS:
.form-group label {
float: left;
text-align: left;
font-weight: normal;
}
.form-group select {
display: inline-block;
width: auto;
vertical-align: middle;
}
Here is your updated fiddle: Updated Fiddle
form-inline class with form-group will do the job like
<div class="form-group form-inline">
<label for="sel1">My InlineSelect: </label>
<select class="form-control" id="rotit">
<option value="1">Value 1</option>
<option value="2">Value 2</option>
<option value="3">Value 3</option>
</select>
</div>
demo : http://jsfiddle.net/9arahevn/2/
This problem is so recorrent that there is a Github project solving it
https://fk.github.io/select2-bootstrap-css/
Place their CSS file right after the CSS from Select2
<link rel="stylesheet" href="css/select2.min.css">
<link rel="stylesheet" href="css/select2-bootstrap.css">
Then you can use the label along with the select
<div class="form-group">
<label for="sName">Select Title</label>
<select class="js-example-basic-single form-control" id="sName">
</select>
</div>
It does work if you use the latest bootstrap:
#import url('http://netdna.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css');
And please DON'T FORGET to make the column with result more than 768px. Form-inline works only if screen with more than 768px. (Just drag the column with a mouse a bit)
The issue was with css for
#media (min-width: 768px)
.form-inline .form-control {
//old bootstrap
display: inline-block;
// new bootstrap
display: inline-block;
width: auto;
vertical-align: middle;
}

How can I align two divs horizontally? [duplicate]

This question already has answers here:
Align <div> elements side by side
(4 answers)
Closed 4 years ago.
I need to align two divs next to each other, so that each contains a title and a list of items, similar to:
<div>
<span>source list</span>
<select size="10">
<option />
<option />
<option />
</select>
</div>
<div>
<span>destination list</span>
<select size="10">
<option />
<option />
<option />
</select>
</div>
It's remarkably easy to do with tables, but I don't want to use tables. How can I achieve this?
Float the divs in a parent container, and style it like so:
.aParent div {
float: left;
clear: none;
}
<div class="aParent">
<div>
<span>source list</span>
<select size="10">
<option />
<option />
<option />
</select>
</div>
<div>
<span>destination list</span>
<select size="10">
<option />
<option />
<option />
</select>
</div>
</div>
Nowadays, we could use some flexbox to align those divs.
.container {
display: flex;
}
<div class="container">
<div>
<span>source list</span>
<select size="10">
<option />
<option />
<option />
</select>
</div>
<div>
<span>destination list</span>
<select size="10">
<option />
<option />
<option />
</select>
</div>
</div>
<div>
<div style="float:left;width:45%;" >
<span>source list</span>
<select size="10">
<option />
<option />
<option />
</select>
</div>
<div style="float:right;width:45%;">
<span>destination list</span>
<select size="10">
<option />
<option />
<option />
</select>
</div>
<div style="clear:both; font-size:1px;"></div>
</div>
Clear must be used so as to prevent the float bug (height warping of outer Div).
style="clear:both; font-size:1px;
You need to float the divs in required direction eg left or right.
Wrap them both in a container like so:
.container{
float:left;
width:100%;
}
.container div{
float:left;
}
<div class='container'>
<div>
<span>source list</span>
<select size="10">
<option />
<option />
<option />
</select>
</div>
<div>
<span>destination list</span>
<select size="10">
<option />
<option />
<option />
</select>
</div>
</div>
Add a class to each of the divs:
.source, .destination {
float: left;
width: 48%;
margin: 0;
padding: 0;
}
.source {
margin-right: 4%;
}
<div class="source">
<span>source list</span>
<select size="10">
<option />
<option />
<option />
</select>
</div>
<div class="destination">
<span>destination list</span>
<select size="10">
<option />
<option />
<option />
</select>
</div>
That's a generic percentages solution - using pixel-based widths is usually much more reliable. You'll probably want to change the various margin/padding sizes too.
You can also optionally wrap the HTML in a container div, and use this CSS:
.container {
overflow: hidden;
}
This will ensure subsequent content does not wrap around the floated elements.
float is obsolete, better use display: flex;:
example :
.parent-div{ display: flex; }
indicate the direction by flex-direction: row/column;.
go down if no space by flex-wrap: wrap/nowrap;
more properties here.
if you have two divs, you can use this to align the divs next to each other in the same row:
#keyword {
float:left;
margin-left:250px;
position:absolute;
}
#bar {
text-align:center;
}
<div id="keyword">
Keywords:
</div>
<div id="bar">
<input type = textbox name ="keywords" value="" onSubmit="search()" maxlength=40>
<input type = button name="go" Value="Go ahead and find" onClick="search()">
</div>
<html>
<head>
<style type="text/css">
#floatingDivs{float:left;}
</style>
</head>
<body>
<div id="floatingDivs">
<span>source list</span>
<select size="10">
<option />
<option />
<option />
</select>
</div>
<div id="floatingDivs">
<span>destination list</span>
<select size="10">
<option />
<option />
<option />
</select>
</div>
</body>
</html>
For your purpose, I'd prefer using position instead of floating:
http://jsfiddle.net/aas7w0tw/1/
Use a parent with relative position:
position: relative;
And children in absolute position:
position: absolute;
In bonus, you can better drive the dimensions of your components.