Page layout, Divs instead of Tables - css

I know I am doing it all wrong. At the moment, I used Tables to format my screen. Bad, I know. I am looking at learning Twitter Bootstrap, but for a test site, I am just trying to move away from Tables and try use DIVs for layout.
At the moment, I am trying to make a page header that shows a title on the left, and a login box on the right.
<div>
<table style="width: 100%;">
<tr style="vertical-align: top">
<td style="text-align: left">
<h1>Basic Finance</h1>
</td>
<td style="text-align: right">#Html.Partial("_Login", new LoginModel())</td>
</tr>
</table>
<hr />
#RenderBody()
</div>
How can I use DIVs to do this? Are DIVs the right idea? I see Twitter Bootstrap uses <SPAN> - but I am days away from getting to grips with it.

So, I went a completely separate route form everybody else. First, here is my example of what I think you want but let me know if this is not correct.
DEMO
Now, let me break it down a bit for you. I first started by taking what you said with a login and having some type of header along with a login table by or on the same line. This was done via the HTML code below:
<div id="wrapper">
<h1 style="float:left;"> Example Text </h1>
<form action="" method="post">
<ul id="regis_ul">
<li id="regis_li">
<label><span> Username: </span>
<span><input type = 'text' name ='username' id ='username' value = ></span>
</label>
</li>
<li id="regis_li">
<label> <span> Password: </span>
<span><input type = 'password' name ='password' id ='password' value ='' ></span>
</label>
</li>
<input type='submit' name='submit' value='Register'>
</form>
</div>
Which is then accompanied by some CSS code:
#regis_ul {
display:table;
}
#regis_li {
display:table-row-group;
}
span {
display: table-cell;
}
label {
display: table-row;
}
form{
float: right;
}
The above code is what produced the JsFiddle output. Something to read into is the display method "table" that will tell you more about why this CSS trick actually works. This can be found in the Almanac.
Another thing that is good to read up on is why exactly a list may be better than a table which.. a great argument with pros and cons is found in this stack question here.
Finally, I encourage you to play with any of the JsFiddle's on this page, you may end up finding a perfect combination that really suites what you are looking for, giving you that unique feel :) If you have any questions about my Demo, just comment below and I will try my best to answer it for you :)

You can use divs and it's a good idea if you want to switch, you can use display properties according to your needs
<div style="width: 100%;">
<div style="vertical-align: top">
<div style="text-align: left;display:inline-block;">
<h1>Basic Finance</h1>
</div>
<div style="text-align: right;display:inline-block;">#Html.Partial("_Login", new LoginModel())</div>
</div>
</div>
And twitter-bootstrap have some classes like pull-left and pull-right have a look at it, i recommend you to use divs instead of tables!
Fiddle Demo

Try this layout
<div class="navbar">
<div class="navbar-inner">
<a class="brand" href="#">Basic Finance</a>
<div class="pull-right">
#Html.Partial("_Login", new LoginModel())
</div>
</div>
</div>

You can use
display:table; for <table>
display:table-row; for <tr>
display:table-cell; for <td>
in div format
here is a demo (it has css table vs html table-compare and check for your understanding)
CSS to play with
body{
height:100%;
}
#main{
height:100%;
width:100%;
}
.table{
display:table;
width: 100%;
}
.tr{
display:table-row;
}
.td{
display:table-cell;
}

With just plain divs you can use the float property to get them next to each other
<div>
<div class="table">
<div class="left">
<h1>Basic Finance</h1>
</div>
<div class="right">
#Html.Partial("_Login", new LoginModel())
</div>
</div>
#RenderBody()
</div>
Then you can style it the way you like with CSS, for instance:
.left{float: left;width: 50%;;height:100%;text-align:left;}
.right{height:100%; text-align:right;padding-top: 30px;}
.table{height: 75px;}
Output of this code:
http://jsfiddle.net/7Qv8r/1/
Cheers

You can try this
Check Fiddle here
<div>
<div style="width: 100%;">
<div style="float: left">
<h1>
Basic Finance</h1>
</div>
<div style="float: right; padding-top: 30px;">
#Html.Partial("_Login", new LoginModel())</div>
</div>
<div style="clear: both">
</div>
<hr />
#RenderBody()
</div>
Good Luck n Happy New Year...:)

Related

How can a scrollbar be triggered /using overflow property in an angular app (by ng-repeating through elements)?

I have a sidebar in my angular app and I am trying to make one div insight the sidebar scoll through the items and the content in the following div keep the same position (no scrolling). I have been looking at so many similar posts and tried everything but it just wont work. The problem is that either can you scroll through everything in the sidebar or not at all or that the bottom stayed (without moving) but then i the scrollbar was there for EACH item (and not for all items).
I used ng-repeat to put items on scope of the sidebar - is it perhaps different with angular that with reg. html?
Thanks!!
Ps. Im using gulp and the sidbar is a directive which I didnt include here. If anything is of importance, please let me know and I include it.
<li>
<a ng-click="openNav()"><i id="cart-icon" class="medium material-icons icon-design">shopping_cart</i></a>
<div id="mySidenav" class="sidenav closebtn" click-anywhere-but-here="closeNav()" ng-click="closeNav()">
<div class="sidebarBox">
<h2 class="sideBarHeader">Cart </h2>
<div class="sidebarContainer" ng-repeat="item in cart">
<img src="{{item.imageUrl}}" style="width:90px;height:100px;">
<div class="sidebarContent">
<p class="sidebarTitle">{{item.title}} </p>
<p class="sidebarSubtitle">Quality: {{item.quantity}}</p>
<p class="sidebarSubtitle">Price: ${{item.price}}</p>
</div>
<p class="sidebarLine"></p>
</div>
</div>
<br>
<div class="sidebarNoScroll">
<p style="color:black;font-size:22px;">Total</p>
<p class="sidebarTotal">${{ total() }}</p>
<button class="sidebarButtonContinueShopping" id='continue-shopping-button' ng-click="closeNav()">Continue Shopping</button>
<button class="sidebarButtonViewCart" ui-sref='cart' ng-click="closeNav()">View Cart</button>
</div>
</div>
</li>
css.
.sidebarContainer {
overflow:scroll;
height:224px;
}
.sidebarNoScroll {
overflow: hidden;
}
Wrap the container.
<div class="sidebarContainer">
<div ng-repeat="item in cart">
</div>
</div>

Floating two elements to the right in a flexible container

I'm trying to float two elements (buttons) to the right of a flexible container.
One of the buttons is also flexible, as the text within it changes depending on who's logged into the system.
Any ideas how this can be achieved? Help is much appreciated! I've already tried float rights (the order of the buttons is wrong when I do that) and display: inline-block (doesn't work).
Edit:
Code I've tried (that doesn't work). This is psuedo version, as I'm currently overhauling a pre-existing system -
<div style="width: 100%">
<div style="float:right; text-align: right;">
<input type="submit" style="display: inline-block"></button>
<button style="display: inline-block"></button>
</div>
</div>
It works perfectly..please check your project code completely,
<div style="width: 100%">
<div style="float:right; text-align: right;">
<input type="submit" style="display: inline-block"/>
<button style="display: inline-block">flexible</button>
</div>
</div>
works perfectly here..
FIDDLE DEMO

Image is overlaping on text

Code:
First div is containing image and image is overlapping on the contents of second div.
<div>
<img src="happy.jpg" style="height:50px;width:50px;border-radius:50%;float:left" /> alex is desperately looking for college and there are many more like here
</div>
<div id="progressbar">
<label id="ProgressText">
alex is still unhappy, step <label id="RemainingSteps">2</label> to go
</label>
<div id="progressFilled">
</div>
</div>
I want that image should not overlap the contents of second div. how can i do this?
You need to set overflow to hidden.
CSS
.wrap{
overflow: hidden;
}
HTML
<div class="wrap">
<img src="happy.jpg" style="height:50px;width:50px;border-radius:50%;float:left" />
alex is desperately looking for college and there are many more like here
</div>
<div id="progressbar">
<label id="ProgressText">
alex is still unhappy, step <label id="RemainingSteps">2</label> to go
</label>
<div id="progressFilled">
</div>
</div>
Use the following code.
<div class="clearfix">
<img src="happy.jpg" style="height:50px;width:50px;border-radius:50%;float:left" /> alex is desperately looking for college and there are many more like here
</div>
<div id="progressbar">
<label id="ProgressText">
alex is still unhappy, step <label id="RemainingSteps">2</label> to go
</label>
<div id="progressFilled">
</div>
</div>
Add this to CSS
.clearfix:after {
content: "";
display: table;
clear: both;
}

How to align css class using bootstrap

im trying to align several divs with each other, for some reason its not working. Im using a simple bootstrap template...My code snippet is below and My JS fiddle is http://jsfiddle.net/sean3200/yU3TA/ Thanks!!
I basically want my html to look like align such as:
Album1: Name1
Album2: Name2
<div id="wellbox" class="well pull-right">
<div><h3>Album Sales & Net worth</h3></div>
<hr>
<p id="album0">Album1:</p>
<div><p id="albumdata0" class="album-class">Name1</p></div>
<p id="album1">Album2:</p>
<div><p id="albumdata1" class="album-class"></p>Name2</div>
<p id="album2">Album3:</p>
<div><p id="albumdata2" class="album-class">Name3</p></div>
<p id="album3">Album3:</p>
<div><p id="albumdata3" class="album-class"></p></div>
</div>
I would probably restructure as so:
<div id="wellbox" class="well pull-right">
<div><h3>Album Sales & Net worth</h3></div>
<hr>
<div class'albumContainer'>
<p id="album0">Album1:</p>
<div><p id="albumdata0" class="album-class">Name1</p></div>
</div>
</div>
and then I would add the following style:
.albumContainer{
clear: both;
}
.albumContainer a, .albumContainer div{
display: inline-block;
}

Render items side by side

I am trying to display a page that contains a header with 3 list items, a sidebar with links on the left and the actual body. I would like the sidebar and the body to be rendered side by side under the header. However, they are rendered one after another on the page.
Any suggestions on how this can be done?
I've used the following code and style to achieve this, but it doesn't seem to be working.
<div>
<h1 class="control-label admin-header" style="vertical-align:top;padding-left:20px">Administration</h1>
<ul class="nav nav-pills admin-header" style="float:right">
<li class="active admin-header">test</li>
<li class="admin-header">xyz</li>
<li class="admin-header">abc</li>
</ul>
</div>
<div>
<div class="span3 admin-header">
<div class="well sidebar-nav admin-header">#RenderSection("Sidebar", false)</div>
</div>
<div class="content span12 admin-header">#RenderBody()
</div>
</div>
.admin-header
{
display: inline;
}​
Fiddle
Not sure whether I understood, but for side by side display, you can use
<table>
<tr>
<td class="active admin-header">test</td>
<td class="admin-header">xyz</td>
<td class="admin-header">abc</td>
</tr>
</table>

Resources