css positioning in One column fixed width layout - css

I have the css layout: One column fixed width layout, from maxdesign.com
the following is the navigation div:
<div id="navigation">
<ul>
<li><asp:LinkButton ID="lkbDataEntry" runat="server">Data Entry</asp:LinkButton></li>
<li><asp:LinkButton ID="lkbReports" runat="server">Reports</asp:LinkButton></li>
</ul>
</div>
Now, I want to place an asp:label with the current user logged in, in the same navigation div by doing this:
<div id="navigation">
<ul>
<li><asp:LinkButton ID="lkbDataEntry" runat="server">Data Entry</asp:LinkButton></li>
<li><asp:LinkButton ID="lkbReports" runat="server">Reports</asp:LinkButton></li>
</ul>
<div id="username">
<asp:Label ID="lblUsername" runat="server" Text="User name"></asp:Label>
</div>
</div>
with the css code:
#navigation
{
float: left;
width: 960px;
background: #1f2d3a;
}
#navigation ul
{
margin: 0;
padding: 0;
}
#navigation ul li
{
list-style-type: none;
display: inline;
}
#navigation li a
{
display: block;
float: left;
padding: 1px 5px;
color:#fff;
font-size: 14px;
/*font-weight: bold;*/
border-right: 1px solid#fff;
}
#navigation li a:hover { background:#0c749b; }
#username
{
float: right;
padding-right: 5px;
color:#fff;
}
But the label is always shown below the line of menu items, at the right but below them.
Can someone help me?

Why not place the label in a right floated li, inside #navigation? Your CSS can stay the same, since #username is floated right already.
<div id="navigation">
<ul>
<li><asp:LinkButton ID="lkbDataEntry" runat="server">Data Entry</asp:LinkButton></li>
<li><asp:LinkButton ID="lkbReports" runat="server">Reports</asp:LinkButton></li>
<li id="username"><asp:Label ID="lblUsername" runat="server" Text="User name"></asp:Label></li>
</ul>
</div>

you need to float the ul. right now the ul is a block element, meaning anything after it will show up on the next line, thus the username is below it. if you assign a float:left, it should allow elements to appear in the empty space to the right of the list.

Related

Side by side different lists html5

I need to put three different lists side by side: an unordered list, an ordered list, and a description list
I have tried a ton of different things but so far no float inline or inline block is working, unless i am doing it wrong and someone would like to explain the correct way to use these. The way I tried it was
#schedule {
}
#schedule ul {
list-style-type: none;
display: inline-block;
}
#schedule ol {
list-style-type: none;
display: inline-block;
}
#schedule dl {
list-style-type: none;
display: inline-block;
}
as the css for
<aside id="schedule">
<h2>Favourite Teachers</h2>
<ul>
<li>Steve Sutherland</li>
<li>Steve Sutherland</li>
<li>Steve Sutherland</li>
</ul>
<h2>Favourite Classes</h2>
<ol>
<li>Web Programming</li>
<li>Tim's</li>
<li>The Den</li>
</ol>
<h2>Favourite lessons</h2>
<dl>
<dt>First Webpage</dt>
<dd>Got me hooked</dd>
<dt>Images and videos</dt>
<dd>Endless joke possibilites</dd>
</dl>
</aside>
Wrap them in div and float the div's.
<div class="first">
<ul>...</ul>
</div>
<div class="second">
<ol>...</ol>
</div>
<div class="third">
<dl>...</dl>
</div>
In CSS :
.first, .second, .third{
float: left;
margin-right: 50px;
}
Fiddle : http://jsfiddle.net/cmmabu8n/

Floating <li> with different heights

Is there any way how to make all list items of the same height? I searched this website and found this solution but it doesn't work for me if I add float:left. I need float:left for line breaks after each 4 images.
ul.Gallery{display:table-row;}
ul.Gallery li{float:left;list-style:none;margin:0 5px 5px 0;
display:table-cell;background:red;}
<ul class="Gallery">
<li><img src="image1.jpg"><p>description1</p></li>
<li><img src="image2.jpg"><p>description2</p></li>
<li><img src="image3.jpg"><p>description3</p></li>
<li><img src="image4.jpg"><p>description4 description4 description4 description4 description4 description4</p></li>
<li><img src="image5.jpg"><p>description5</p></li>
</ul>
This is what I need:
and this is what I get if some images don't have any description or description length is different.:
I can not set width or min-heigth for <li> elements because not all the images have description and description length may be very different.
I don't want to use javascript for this purpose.
Try this (edited code a bit):
ul.Gallery{display:block; padding:0; margin:0;}
ul.Gallery li{
padding:0;
background:red;
display:inline-block;
vertical-align: top;
width:23%;
margin:0 1% 5px 0;}
img {max-width: 100%; height: auto;}
http://jsfiddle.net/uR9YV/
Remove float:left and add height:100%
ul.Gallery li{
list-style:none;
margin:0 5px 5px 0;
background:red;
display:table-cell;
vertical-align: top;
height: 100%;
}
DEMO
Change float:left for display:table-cell an the li/cells will all have the same height.
Note however, that you may have to restrict the width of the li as the text will cause different widths depending on it's length.
JSfiddle Demo
CSS
ul, li {
list-style: none;
}
ul {
display: table;
}
li {
display:table-cell;
border:1px solid grey;
padding:5px;
width:20%;
}
li img {
display: block;
margin:0 auto;
}
li p {
text-align: center;
}
Here is one of realizing this layout using rather different mark-up.
The feature of this layout is that the li elements all have the same height which
means that the red backgorund has the same height with a row.
If it were not for the red background color, this problem would be a lot easier to
solve.
The HTML would look like this:
<div class="GalleryWrap">
<ul class="Gallery">
<li>
<img src="http://placekitten.com/150/100" />
<p>The cat in the hat.</p>
</li>
<li>
<img src="http://placekitten.com/150/100" />
<p>The cat in the hat.</p>
</li>
<li>
<img src="http://placekitten.com/150/100" />
<p>The cat in the hat is wearing a fur coat.</p>
</li>
<li>
<img src="http://placekitten.com/150/100" />
<p>The cat in the hat.</p>
</li>
</ul>
<ul class="Gallery">
<li>
<img src="http://placekitten.com/300/200" />
<p>The cat in the hat.</p>
</li>
<li>
<img src="http://placekitten.com/150/100" />
<p>The cat in the hat.</p>
</li>
<li>
<img src="http://placekitten.com/150/100" />
<p>The cat in the hat is wearing a fur coat.</p>
</li>
<li>
<img src="http://placekitten.com/150/100" />
<p>The cat in the hat.</p>
</li>
</ul>
</div>
and the CSS:
.GalleryWrap {
display: table;
width: auto;
margin: 0 auto;
border-collapse: collapse;
}
ul.Gallery {
display: table-row;
}
ul.Gallery li {
display: table-cell;
vertical-align: top;
width: 25%;
background-color: red;
border: 5px solid white;
}
ul.Gallery li img {
width: 100%;
}
ul.Gallery li p {
margin: 5px;
}
Create a the CSS table .GalleryWrap, and use display: table-row for ul.Gallery.
Within each ul.Gallery, put in the four images, and repeat for each group of four.
I added a white border to control the spacing between cells, but you can also use
cell spacing and cell padding.
In practice, the mark-up could be generated automatically using a scripting language
like PHP or the features of the template system used to build the pages of the website.
Demo: http://jsfiddle.net/audetwebdesign/DBZdf/
Note: This layout may be easier to build using flex, but flex is still rather new and supported only by the latest browsers.

Style is cascading strangely

I have an inline stylesheet that is cascading really strangely.
I have a menu made with a <ul> and I want to make it so that when a user is on a page, the background color of the current page link on the <li> is green. I did this by creating an ID with background-color: #288E3A;, but despite placing it after the ID for the menu, I cannot make the current <li> turn green. The only way I can get it to work is to use !important, but I cannot bring myself to use that solution. -shudder-
I have a feeling this is probably something really simple I am missing. Can someone explain where I went wrong?
#menu ul {
padding: 15px;
list-style-type: none;
}
#menu ul li {
background-color: #363636;
margin: 0px 0px 15px;
line-height: 50px;
padding: 0px 5px 0px 5px;
}
#current_page ul li {
background: #288E3A /*!important*/;
}
<div id="menu">
<p>MAIN MENU</p>
<div id="button_container">
<ul>
<li id="current_page">HOME</li>
<li>CAR LOANS</li>
<li>AUTO LOAN REFINANCING</li>
<li>AUTO CALCULATORS</li>
<li>TOOLS AND RESOURCES</li>
</ul>
</div>
</div>
<div id="content_container">
<img src="img/cf_mobile_website-4.jpg" />
</div>
your css is incorrectly specifying the element, what you want is this :
#menu ul li#current_page{
background:#288E3A;
}
Better yet you could use css to specify the first child so you wont need to add a custom id:
#menu ul li:first-child{
background:#288E3A;
}

Navigation bar center position

I am currently working with a bottom navigation bar for a test site. The problem is that the navigation bar does not center properly. I have added the .left attribute to keep each block list beside each other. How can I get this bottom navigation bar to center automatically(no matter the amount of lists added)? Example
CSS related to bottom navigation
<style>
.bottomnavControls {
padding-top:10px;
padding-bottom:10px;
padding-right:0;
text-decoration:none;
list-style:none;
}
#footer {
position: absolute;
width: 100%;
bottom: 0;
background: #7a7a7a;
border-bottom: 15px solid #000;
}
.left {
float: left;
}
.right {
float: right;
}
</style>
HTML
<div id="footer">
<div class="bottomNav">
<ul class="bottomnavControls left">
<li style="padding-bottom:5px;"><b>Home</b></li>
<li>Login</li>
</ul>
<ul class="bottomnavControls left">
<li style="padding-bottom:5px;"><b>Category</b></li>
<li>Games</li>
</ul>
<ul class="bottomnavControls left">
<li style="padding-bottom:5px;"><b>About</b></li>
<li>Who We Are</li>
</ul>
<ul class="bottomnavControls left">
<li style="padding-bottom:5px;"><b>Links</b></li>
<li>Google</li>
</ul>
<ul class="bottomnavControls left">
<li style="padding-bottom:5px;"><b>Other Stuff</b></li>
<li>Stuff</li>
</ul>
</div>
</div>
My current Bottom navigation:
My desired outcome:
Instead of float, you should use display: inline-block here. This way, you can easily center them by putting text-align: center on the container.
.bottomNav { text-align: center; }
.bottomnavControls { display: inline-block; }
and remove left class.
Note: display: inline-block works fine in modern browsers, but it needs a hack in IE7.

Why do I need `position: absolute` in making side-by-side 2x2 square?

I use this method here in the below example.
<!-- vim: set nowrap:-->
<html>
<style type="text/css">
#titleImg{ <!--No use in the code but it makes -->
<!--things to work for some odd reason?!-->
position:absolute; <!--If I remove this, FAILURE --not 2x2.-->
<!--It becomes one-after-another after rem.-->
<!--Why?-->
}
li{
width:190px;
height:190px;
display: block;
float: left;
margin: 5px;
}
</style>
<body>
<center>
<ul style="width:400px; height:400px; text-align:center;">
<li>
<img id="titleImg"
src="../Pictures/Logos/logo.png"
style="width:100%;height:100%">
</li>
<li> </li>
<li> </li>
</ul>
</center>
</body>
You don't I think. Here's an updated jsFiddle example of what I believe you are trying to accomplish. Note: never use <center></center> tags - they are not good practice. Instead set the parent to display: block and its margin to 0 auto.
Here is the new live example
And the code:
HTML
<ul>
<li> <img src="http://www.woodlands-junior.kent.sch.uk/customs/images/uk.jpg"></li>
<li> <img src="http://www.crwflags.com/fotw/images/u/us.gif"> </li>
<li> <img src="http://www.enchantedlearning.com/school/Canada/flagbig.GIF"> </li>
</ul>
​
CSS
ul {
display: block;
margin: 0 auto;
}
li {
width:190px;
height:190px;
display: block;
float: left;
margin: 5px;
overflow: hidden;
}​

Resources