left aligning a list inside centered table - css

I can't get this list to align left
<table width="100%">
<tr>
<td align="center">
<asp:Panel ID="Panel1" runat="server" BackColor=White Height="604px"
Width="493px" >
<ul align=left style="left:-60px;background:Black">
<li>Coffee</li>
<li>Milk</li>
</ul>
</asp:Panel>
</td>
</tr>
</table>

I agree with Datoon, if it's non tabular data then it's probably worth while to put this in a regular div. The following will align your text to the left, however.
<ul style="background:Black; text-align:left;">
<li>Coffee</li>
<li>Milk</li>
</ul>

Adding the following CSS rule to the parent <div> will get it to align properly:
div {
text-align: left;
}
You can see it in action here.

I know this might sound weird, but why are you using a table instead of a div? Is this specifically data that is tabular in layout?
Usually you would use a div for none tabular data.
So you could do the following:
<div style="float:left">
Your list items here.
</div>
<div style="float:right">
Some other content here.
</div>
Remember to do the following though after:
<div style="clear:both"></div>

Related

Page layout, Divs instead of Tables

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...:)

Unordered list created by listview not showing on hover

I have a navigationbar that's controled completly by css ul and li.
The first unordered list contains listitems which are always displayed (General Site pages).
on hovering over the listitem (Gamma), the sublistitems appear. These sublistitems are themself in an unordered list of car models with the modelname. Hovering one of these items show me a picture of the car in a seperate div.
When I create the list of cars manually all works fine. The car models en their image are shown correctly.
When I create the unordered list dynamically by a listview. The car names are not shown.
If I place the listview out of the navigation ul. The listview works correct.
I assume it has something to do with the moment that the listview creates the unordered list. Can anyone point me in the right direction?
My ASP.net code
<nav>
<ul class="menu">
<li><a class="active" href="Default.aspx">H</a></li>
<li>Gamma
**<asp:ListView ID="lvGamma" runat="server">
<LayoutTemplate>
<ul>
<asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
</ul>
</LayoutTemplate>
<ItemTemplate>
<li><a href='<%# "AixamGamma.aspx?Model=" + Eval("car.NewCarID").ToString %>' class="sublistitem" >
<asp:Label ID="lblModelName" runat="server" Text='<%# Eval("car.ModelName") %>'></asp:Label></a>
<div class="modeldetail">
<div class="redbox">
<div class="whitebox">
<div class="container_12">
<div class="wrapper">
<div class="grid_5">
<h3>
<asp:Label ID="lblModelSlogan" runat="server" Text='<%# Eval("car.Slogan") %>'></asp:Label>
</h3>
</div>
<div class="grid_3">
<div class="wrapper">
<img src='<%# Eval("image.ImageLocationPath") + Eval("image.ImageFileName")%>' alt='<%# Eval("car.ModelName") %>'
class="img-max-h200-w200" />
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</li>
</ItemTemplate>
</asp:ListView>**
*<ul>
<li>City</li>
<li>CityS</li>
<li>Crossline</li>
<li>GTO
<div class="modeldetail">
<div class="redbox">
<div class="whitebox">
<div class="container_12">
<div class="wrapper">
<div class="grid_5">
<h2>
De nieuwe Aixam Gto</h2>
<p>
Rijden zonder rijbewijs in een sportief kleedje</p>
</div>
<!--- image width max 220px --->
<div class="grid_3">
<div class="wrapper">
<img src="images/Sliders/Aixam%20GTO.jpg" alt="Gto" />
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</li>
<li>Crossover</li>
</ul>*
</li>
<li>Tweedehands</li>
<li>Onderhoud/herstelling </li>
<li>Wetgeving</li>
<li>Contact</li>
</ul>
</nav>
the bold part doesn't work except when its placed out the navigation list, the italic part does
thx for the help
I got it working. I've tested the code with the hard coded unordered list AND the listview together in one item. Removing the hard coded list did the trick....

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>

How do I vertical-align text relative to a floated image?

There are a number of questions addressing this issue, but none addressing vertical alignment relative to a floated image or block-level element.
...
<td>
<span style="vertical-align: middle">This should be vertically centered relative to the image</span>
<img src="something" style="float: right" />
</td>
...
This does not produce the desired result, since the image is floating. I have tried a lot of things, including adding a after the tag, making the span display as a block level element, and other ways to position the image (aligned to the right of the containing ) without floating it, but have not had success.
UPDATE:
I have been unable to get any of the proposed solutions working. If this can't be done, so be it, but I'm leaving this open until I can be sure it can't. I've created a jsFiddle with the HTML, in hopes that someone can write CSS which demonstrates a solution.
...
<td>
<table cellpadding="0" cellspacing="0">
<tr>
<td>text here</td>
<td style="text-align: right">image here</td>
</tr>
</table>
</td>
...
The <td> tag is align middle by default
You would need to wrap the span and image in the same <div> and apply the float to the div instead.
...
<td>
<div style="float: right;">
<span style="vertical-align: middle">This should be vertically centered relative to the image</span>
<img src="something" />
</div>
</td>
...
OR
...
<td style="vertical-align: middle;">
<span>This should be vertically centered relative to the image</span>
<img src="something" style="float: right;" />
</td>
...
This can not be done without modifying the given document structure, at least given CSS2.1. I'd still love to see a CSS3 solution, if anyone can provide one.

Aligning in multi-element div

I have this div that is showing the products for an e-commerce site.
I have it well alligned with css and a table inside it, but using tables for content seems to be frowned upon/not the best so I'm trying to do it correctly, hasn't worked out so far. The products div looks like this:
Crude unedited screenshot : http://img255.imageshack.us/img255/6832/printt.png
That is the look I want. I tried nesting 2 divs in the products div, one floating right with the image, title and description, the other one floating right with the table elements.
Thought I had worked it out to a decent look on some pages, but on others (displaying other products) it looks different and messed up. I'm thinking this is due to the fact the links were taking on the width of the whole products div, ending up over the right div.
How do I stop that behavior, I want the links to wrap around the text maybe the problem would go away then. Or are you suggesting something else?
HTML looks like this :
<div id="products">
<img src="fetch.php?id=4" width="129" height="129" alt="PRC200" />
<h3>PRC200</h3>
<table border="0">
<tr>
<td><h4>100,00 RON</h4></td>
</tr>
<tr>
<td class="out">Indisponibil</td>
</tr>
<form action="" method="post">
<tr>
<td><input type="image" src="images/button_basket.jpg" name="submit_cos" width="118" height="25" /></td>
</tr>
</form>
<form action="detalii.php" method="get">
<tr>
<td>
<input type="hidden" name="id_produs" value="4" />
<input type="image" src="images/button_details.jpg" name="submit_detalii" width="118" height="25" />
</td>
</tr>
</form>
</table>
<p>M-am saturat de atatea litere si numere</p>
</div>
Here is a tableless solution. Keep in mind take the tags and place them in an external CSS file. By using a tableless structure you'll see how much more condensed the code is.
<style>
.product { border:1px solid red; padding:10px; }
.productimg { float:left; padding-right:15px; }
.purchasedetails { float:right; padding-left:15px; }
</style>
<div id="products">
<div class="product">
<div class="purchasedetails">
<h4>100,00 RON</h4>
<p>Indisponibil</p>
<input type="image" src="images/button_basket.jpg" name="submit_cos" width="118" height="25" /><br />
<input type="image" src="images/button_details.jpg" name="submit_detalii" width="118" height="25" />
</div>
<div class="productimg"><img src="fetch.php?id=4" width="129" height="129" alt="PRC200" /></div>
<h3>PRC200</h3>
<p class="description">Insert Description Here</p>
<div style="clear:both;"></div>
</div>
</div>
I only have this nexted inside the <div id="products"> because it was listed in your code. The inside products div would essentailly fill whatever content area it is placed in whether it is a <td> or<div>

Resources