How to align 2 divs inside another div? - css

My requirement is I have two links at left side and if I click on a link, respective page should get displayed on the right side.
how can make this arrangement using tags.
I tried as the below, but its not showing side by side. where as DisplayData gets appeared at the bottom of links. Thanks in advance..
<div id="accountstabs-1">
<div id="links" style="text-align:left">
<li>Manage</li>
<li>Users</li>
</div>
<div id="DisplayData" style="text-align:right">
<table class="data">
<thead>
<tr>
<th>
First Name
</th>
<th>
Last Name
</th>
</tr>
</thead>
</table>
</div>
</div>

CSS:
#accountstabs-1>div {
float : left;
}
http://jsfiddle.net/T4E88/

You need to use floats instead of text-align to position elements. (text-align should only be used for text.)
Check out this JSFiddle example.
I updated your HTML like this:
<div id="accountstabs-1">
<div id="links" >
<li>Manage</li>
<li>Users</li>
</div>
<div id="DisplayData" >
<table class="data">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
</tr>
</thead>
</table>
</div>
<div class="clr"></div>
</div>​
Notice that I removed the two text-align inline styles from the divs, and added the new div near the bottom with class clr.
Then the CSS looks like this:
#links {
width: 50%;
float: left;
}
#DisplayData {
width: 50%;
float: right;
}
/* clearfix */
.clr { clear: both; }
The purpose of the "clearfix" is to make sure that any elements added after your right column get displayed underneath the columns properly.

You should put the styles in a separate CSS file, but the following should work;
<div id="accountstabs-1" style="width:400px">
<div id="links" style="display:block;float:left;width:200px">
<li>Manage</li>
<li>Users</li>
</div>
<div id="DisplayData" style="display:block;float:right;width:200px">
<table class="data">
<thead>
<tr>
<th>
First Name
</th>
<th>
Last Name
</th>
</tr>
</thead>
</table>
</div>
</div>

div is a block element and it take the whole place horizantly,
to place another div in parallel you need to use css property float left .
use style property style="float:left".
<div id="accountstabs-1">
<div id="links" style="text-align:left; float:left">
<li>Manage</li>
<li>Users</li>
</div>
<div id="DisplayData" style="text-align:right">
<table class="data">
<thead>
<tr>
<th>
First Name
</th>
<th>
Last Name
</th>
</tr>
</thead>
</table>
</div>
</div>

Related

Bootstrap 4 using sticky and float on divs

I am using Bootstrap 4 with float-left and float-right classes that keep my 2 divs left and right of each other and works great, but I want the right div to be sticky as well, but this doesnt seem to work. I am using position-sticky on the div using float-right
Float class Reference here: Float URL
Sticky class Reference: Position URL
Essentially my HTML looks like this:
<section class="section">
<div class="float-left col-md-8">
<div class="row sameheight-container">
<div class="col-md-12">
#*Form fields, such as input, select etc.*#
</div>
</div>
</div>
<div class="float-right col-md-4 position-sticky">
<div class="row sameheight-container">
<div class="col-md-12">
<div class="card card-block sameheight-item">
<table>
<thead>
<tr>
<th>Quantity</th>
<th>Price</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
<td>2</td>
<td>3</td>
<td>6</td>
</tr>
<tr>
<td>5</td>
<td>10</td>
<td>50</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
Please note that the first Div has a bunch of form controls, so I have removed that and just put a comment in there.
Is there a way of doing this?
Thanks for any help!

CSS align text so its in straight line

I have split the page in 3 sections
25% width
50% width
25% width
How can i get my menu in straight line after using text-align:right. I don't want to use margin-left cause without using it the web is more responsive to other devices and looks more appealing.
What i expect to get - Imagur Image of expected outcome.
I want menu to start at yellow line.
My current code in JSFiddle - JSFiddle Example
If you're going to be using Bootstrap, you might as well just use the existing grid system that comes with it. In order to left align an element with right aligned text, you can simply float it:
ul {
list-style-type:none;
margin:0;
padding:0;
text-align:right;
float:left;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-xs-3">
<ul>
<li>Home</li>
<li>News</li>
<li>Contact</li>
<li>About</li>
</ul>
</div>
<div class="col-xs-6">
<table>
<thead>
<tr>
<th colspan="2">Firstname</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>john#example.com</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary#example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july#example.com</td>
</tr>
</tbody>
</table>
</div>
<div class="col-xs-3">
test
</div>
</div>
</div>
You simply need to add this css code:
.first ul{
text-align:left;
}
Your code would become:
#import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');
#import url('//netdna.bootstrapcdn.com/bootstrap/latest/css/bootstrap-theme.min.css');
.first{
width:25%;
overflow:hidden;
float:left;
text-align:right;
}
.first ul{
text-align:left;
}
.table{
width:50%;
float:left;
}
.three{
width:25%;
float:right;}
<div class="main">
<div class="first">
<ul>
<li>Home</li>
<li>News</li>
<li>Contact</li>
<li>About</li>
</ul>
</div>
<table class="table">
<thead>
<tr>
<th colspan="2">Firstname</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>john#example.com</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary#example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july#example.com</td>
</tr>
</tbody>
</table>
<div class="three">
<p>
test</p>
</p>
</div>
</div>
I hope it helps.

How to make td full height of row? Angular material

I'm using ng-repeat to create a table with schedule blocks, but some are smaller than tr height, and I need that all of them have the same heigh. In each td I have a modified md-checkbox:
Missing space
I'v created a codepen:
Schedule
<div id="main" ng-app="MyApp" layout>
<div ng-view layout="column" flex></div>
<script type="text/ng-template" id="template.html">
<md-toolbar class="" layout="row">
<center>toolbar</center>
</md-toolbar>
<md-content class="content" >
<table class="vistaTabla" cellspacing="0" cellpadding="0">
<tr ng-repeat="hora in bloques[0]">
<td class="vistaBloque" ng-repeat="bloque in hora">
<md-checkbox class=" text-longshadow md-whiteframe-1dp bloque dotted" >
{{bloque.materia}} {{bloque.nombre}}</td>
</md-checkbox>
</tr>
</table>
</md-content>
</script>
</div>
Solution for your problem is the block that is inside <td>.
<td> elements are always the size of their <tr> parents. The md-checkbox element is the one that is messing with you.
Define rule for element .md-whiteframe-1dp:
.md-whiteframe-1dp {
height: 100%;
}

Using Bootstrap grid system in table

I have a question regarding to the title.
I have looked through other question and tried their bootply to make sure that these are possible (using column grid to set the size of the column). However, my case might be more complicated than that and that's why the grid system doesn't work as I think it should be. Can you give me a hand on telling me what I should do?
Code:
<div class="container-fluid">
<div id="wrapper">
<table class="table table-striped" id="table">
<thead>
<th class="col-xs-1">ID</th>
<th class="col-xs-2">Name</th>
<th class="col-xs-2">Phone</th>
<th class="col-xs-2">Email</th>
<th class="col-xs-2">University</th>
<th class="col-xs-2">Course</th>
<th class="col-xs-1">Visa Catergory</th>
<th class="col-xs-10">Age</th>
</thead>
<tbody id="data">
</tbody>
</table>
</div>
</div>
CSS for wrapper:
#wrapper {
width: 600px;
overflow-x: scroll;
}
The problem was quite simple:
I have col-xs-10 in the column Age, but the size of it doesn't care about what number I put in there and (I think) just try to wrap up the content
I have overflow-x
The column total add up is more than 12
Width of one BS-grid cell is always 8.33% of total width of parent. 22 cells will occupy 183%. By default all cells after 100% of parent width wrap into next line. As soon as you use table, all of its <td> in one row will be aligned horizontally despite of their width. So browser draws this collision as it can, thus last table cell wil be shrinked. I think that bootstrap isn't a table format tool. It's rather a table's look beautifier. So (I think) it's better to use set of <div>-s for table structure rendering.
It seems BS has no classes to format table as you wish.
Anyway for defining table cells dimensions you can use colspan. If total of grid cells in your chunk of code is 22, then you need to define row containing 22 cells as a structure base. Look at snippet (border added for better visualization)
#wrapper {
width: 600px;
overflow-x: scroll;
margin: 0 auto;
}
table td, th, thead {
border: 1px solid orange;
}
.formatter > td {
width: 4.5%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div id="wrapper">
<div style="width: 183%;">
<table class="table table-striped" id="table">
<thead>
<tr>
<th>ID</th>
<th colspan='2'>Name</th>
<th colspan='2'>Phone</th>
<th colspan='2'>Email</th>
<th colspan='2'>University</th>
<th colspan='2'>Course</th>
<th>Visa Catergory</th>
<th colspan='10'>Age</th>
</tr>
</thead>
<tr class="formatter">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tbody id="data">
</tbody>
</table>
</div>
</div>
And here is solution using div-s styled with bootstrap classes:
#wrapper {
width: 600px;
overflow-x: scroll;
margin: 0 auto;
}
div[class^="col-xs-"] {
border: 1px solid orange;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div id="wrapper">
<div style="width: 171%;">
<div class="container-fluid">
<div class="row">
<div class="col-xs-7">
<div class="row">
<div class="col-xs-1">ID</div>
<div class="col-xs-2">Name</div>
<div class="col-xs-2">Phone</div>
<div class="col-xs-2">Email</div>
<div class="col-xs-2">University</div>
<div class="col-xs-2">Course</div>
<div class="col-xs-1">Visa Catergory</div>
</div>
</div>
<div class="col-xs-5">
<div class="row">
<div class="col-xs-12">Age</div>
</div>
</div>
</div>
</div>
</div>
</div>
And here is one more variant of compact render, based on color diference:
#wrapper {
width: 600px;
margin: 0 auto;
}
div[class^="col-xs-"] {
border: 1px solid orange;
box-sizing: border-box;
background: #99b;
}
div.subrow {
background: #cce;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<div id="wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-xs-1">ID</div>
<div class="col-xs-2">Name</div>
<div class="col-xs-2">Phone</div>
<div class="col-xs-2">Email</div>
<div class="col-xs-2">University</div>
<div class="col-xs-2">Course</div>
<div class="col-xs-1">Visa</div>
<div class="col-xs-12 subrow">Age</div>
</div>
</div>
</div>

CSS display:table-cell with div inside table

How to make display:table-cell style works (or look-alike alternative) if divs with style table-row are inside table cells? (see the link)
http://jsfiddle.net/ELKQg/460/
I'd like the container1 div behave like the container2.
code: (if the link were to become unreachable)
html:
<div id="container1" class="container">
<table>
<tr>
<td>
<div class="row">
<div class="cell">aaaa</div>
<div class="cell expand">b</div>
<div class="cell">c</div>
</div>
</td>
</tr>
<tr>
<td>
<div class="row">
<div class="cell">d</div>
<div class="cell expand">eeeee</div>
<div class="cell">f</div>
</div>
</td>
</tr>
</table>
</div>
<div id="container2" class="container">
<div class="row">
<div class="cell">aaaa</div>
<div class="cell expand">b</div>
<div class="cell">c</div>
</div>
<div class="row">
<div class="cell">d</div>
<div class="cell expand">eeeee</div>
<div class="cell">f</div>
</div>
</div>
css:
.container{width: 500px;overflow:hidden; /* instead of clearfix div */}
div { border:1px solid;padding: 1px;}
.row {display:table-row;}
.cell {display:table-cell;}
.expand{overflow:hidden;width:100%;}
The extra <table> containing your <div>s in .container1 needs to have width: 100%
display: table-cell elements don't necessarily need a containing display: table-row as long as the parent is display: table. Set the .row to that (ideally you'd re-name it, seeing as the rule no longer makes sense)
Fixed and forked your demo:
http://jsfiddle.net/barney/ahMg8/
Use display: table for the parent table before using display:table-cell
Use td's instead of divs inside tr:
<div id="container1" class="container">
<table>
<tr>
<td class="cell">aaaa</td>
<td class="cell expand">b</td>
<td class="cell">c</td>
</tr>
<tr>
<td class="cell">d</div>
<td class="cell expand">eeeee</td>
<td class="cell">f</td>
</tr>
</table>
</div>
Working fiddle

Resources