Styling list as float next to image - html

How do I achieve this layout from this list:
<ul>
<li id="item1">
<span><img src="..." /></span>
<ul id="description">
<li class="line1">This is the first line</li>
<li class="line2">This is the second line</li>
<li class="line3">This is the third line</li>
</ul>
</li>
</ul>
I tried the float approach but it's not doing it
span {
float:left;
width:14em;
height:14em;
}
#description {
float:right;
width:20em;
margin-left:3em;
}

Here is how I got it with CSS you can edit to your liking: http://jsfiddle.net/theStudent/f69UG/3/
CSS
ul{
list-style:none;
margin: 0;
width: 40em;
}
span {
float:left;
width:14em;
height: 14em;
height:14em;
background: red;
}
#description {
float:right;
width:20em;
min-height: 14em;
margin-left:3em;
color:#000;
}
#description > li{
height: 4.5em;
}
HTML
<ul>
<li id="item1">
<span><img src="..." /></span>
<ul id="description">
<li class="line1">This is the first line</li>
<li class="line2">This is the second line</li>
<li class="line3">This is the third line</li>
</ul>
</li>
</ul>

Don't float the list, just the image(it has same behavior as floating an image in a paragraph, the text will wrap after the image). Example here: http://jsfiddle.net/Lqw53/

In this solution I'm using the <img> tag's attribute of align to align the image to the left, then the rest of the text will flow to the right.
So we have our HTML:
<div>
<img src="http://graph.facebook.com/1126016138/picture?type=large" align="left" />
<ul id="description">
<li class="line1">This is the first line</li>
<li class="line2">This is the second line</li>
<li class="line3">This is the third line</li>
</ul>
</div>
Then our CSS, as bullet points aren't considered by HTML when considering spacing:
#description {
list-style:none;
}
Here is a jsFiddle if you want to have a look: jsFiddle

ul and img are block elements so you need to change their display type to inline-block to make sure they align horizontally
<ul>
<li id="item1">
<span><img src="..." /></span>
<ul id="description">
<li class="line1">This is the first line</li>
<li class="line2">This is the second line</li>
<li class="line3">This is the third line</li>
</ul>
</li>
</ul>
CSS
ul, img{
display: inline-block;
}
img {
float:left;
width:14em;
height:14em;
}
ul{
list-style-type: none;
}
li{
margin-bottom: 75px;
}
#description {
float:right;
margin-left:3em;
margin-top: 5px;
}
JSFiddle

You can check this :
Fidle Link here
ul{
list-style:none;
margin: 0;
padding:0
}
#item1 span {/*Span take width and height as per your image size.*/
float:left;
display:inlne-block;
margin-right:20px;
}
#description {
float:left;
color:#333;
margin-top:10px;
}
#description li{
line-height:20px;
display:block;
padding-bottom:10px;
}
Good Luck...

Related

How do I stop this <li> from collapsing?

Here yellow is <li> which is child of <ul> at the moment <li> or <ul> don't have float:left or display:inline as soon as I apply either float or display on <li> or <ul>
pink <li> which is child of nested <ul> changes it's appearance to this
<ul class="top_nav">
<li>name
<ul class="sub_nav">
<li>name1 icnkdn ndkcnks kkncksn </li>
<li>name2</li>
<li>name3</li>
</ul>
</li>
<li>home</li>
</ul>
.top_nav{
list-style-type:none;
padding:0;
}
.top_nav > li {
padding:1em 2em;
background:yellow;
position:relative;
}
.sub_nav{
position:absolute;
z-index:1;
background:green;
}
.sub_nav li{
display:block;
background:pink;
padding:1em 3em;
}
https://codepen.io/labeeb/pen/zRxoOR
Your .sub_nav has position: absolute; that's why your <li> element is collapsed. Remove this property and everything will be ok.

li goes outside of div

I use this code below to show up right column on my wordpress blog. (List structure is generated by wp_list_categories.)
<div class="rcolumn">
<li class="categories">Categories
<ul>
<li class="cat-item1">
Cat1
</li>
</ul>
<ul>
<li class="cat-item2">
Cat2
</li>
</ul>
</li>
</div>
The thing is, that the contents of this column ignore div and are actually outside of it. Whole li categories goes outside of rcolumn.
.lcolumn {
display:inline;
float:left;
}
.rcolumn {
float:left;
display:inline;
padding:0 5px;
}
.categories {
margin-top:10px;
border:1px solid #aaa;
list-style:none;
}
What am I missing?
.rcolumn {
float:left;
display:inline;
padding:0 5px;
overflow: hidden; <-- try this?
}

Link on the center but icon on the right

I have a problem with position. I want to make the icons on the right align while links are on the center of navigation. But seems like I hit a wall.
This is my HTML
<div id="nav">
<ul>
<li> HOME
</li>
<li> ABOUT
</li>
<li> MUSIC
</li>
<li> GALLERY
</li>
<li> CONTACT
</li>
<li class="navimage"> <img src="abc.jpg" />
</li>
<li class="navimage"> <img src="abc.jpg" />
</li>
<li class="navimage"> <img src="abc.jpg" />
</li>
<li class="navimage"> <img src="abc.jpg" />
</li>
</ul>
</div>
and this is my CSS
#nav {
border-bottom:2px solid #FFF;
margin-bottom:20px;
padding:0;
text-align:center;
}
#nav li {
display:inline;
}
#nav a {
display:inline-block;
padding:10px;
font-family: Arial, Helvetica, sans-serif;
font-weight:bold;
}
#nav a:hover {
color:#DEB887;
}
.navimage img {
width:30px;
height:30px;
border-radius:50%;
-webkit-border-radius:50%;
-moz-border-radius:50%;
-ms-border-radius:50%;
-o-border-radius:50%;
}
.navimage img a {
text-align:right;
}
here is the jsfiddle to check.
http://jsfiddle.net/zN92c/
Replace:
.navimage img a {
text-align:right;
}
With:
.navimage {
float:right;
}
According to your css
.navimage img a
is being aligned right. But the list item itself has no position, Try floating it to the right using:
.navimage { float: right; }
That would alight the list item to the right.

make some menu links float right and other left

I have this HTML code and CSS for a horizontal menu. It displays the links (boxes) from left to right floated to the left of the page.
What is the best way to make one of the links (boxes) display to float to the right of the page?
I have tried using float right with the below CSS copied as navigation-right and changed the HTML as needed but that did not work.
HTML
<div class="navigation-left">
<ul>
<li>Home</li>
<li>SAF</li>
<li>Acudetox</li>
</ul>
</div>
CSS
.navigation-left {
height:auto;
list-style:none;
margin-right:40px;
display:inline;
}
.navigation-left li{
width:200px;
height:25px;
margin:5px;
padding:5px;
background-color:#666666;
border:none;
text-align:center;
display:inline-block;
}
.navigation-left li:hover{
background-color:#f36f25;
color:#FFFFFF;
}
.navigation-left li a{
font-family:Calibri, Arial;
font-size:18px;
font-weight:bold;
color:#ffffff;
text-decoration:none;
}
.navigation-left li.current {
background-color:#F36F25;
}
.navigation-left li.current a {
color:#FFFFFF;
}
http://jsfiddle.net/W2x5y/
Is this Fiddle what you wanted?
<div class="navigation-left" style="float:left">
<ul>
<li>Home</li>
<li>SAF</li>
</ul>
</div>
<div class="navigation-left">
<ul style="float:right; ">
<li>Acudetox</li>
</ul>
</div>
As you might expect, a simple float: right; does the trick.
<div class="navigation-left">
<ul>
<li>Home</li>
<li style="float: right">SAF</li>
<li>Acudetox</li>
</ul>
</div>
http://jsfiddle.net/W2x5y/1/
I think that you'd have to target some of the li tags with a class if you wanted to do that. Plus you need to max the width of the containing ul in order to give it room to float on the right.
http://jsfiddle.net/W2x5y/2/
<div class="navigation-left">
<ul>
<li>Home</li>
<li>SAF</li>
<li class="right">Acudetox</li>
</ul>
</div>
ul {
width: 100%;
}
.right {
float: right;
}
Interesting questions. I'm hoping this helps.
You should anchor the navigation-left and navigation-right to a navigation box itself.
html:
<div class="nav-box">
<div class="nav-left">
<ul>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
</div>
<div class="nav-right">
<ul>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
</div>
</div>
CSS
body .nav-box {
top:0;
width:100%;
height:auto;
background:#eee;
overflow:hidden;
}
.nav-box .nav-left {
display:inline;
left:0;
float:left;
width:auto;
}
.nav-box .nav-right {
display:inline;
right:0;
top:0;
float:right;
width:auto;
}
Working example: http://jsfiddle.net/VA7ya/1/
It seems like the two navs are sufficient different to split them into two elements. Create two elements. Here's a Fiddle: http://jsfiddle.net/q7e3M/1/
<div class="container">
<div class="navigation-left">
<ul>
<li>Home</li>
<li>SAF</li>
</ul>
</div>
<div class="navigation-right">
<ul>
<li>Acudetox</li>
</ul>
</div>
</div>
If you want to keep the same element: http://jsfiddle.net/Afxkt/1/
<ul class="navigation">
<li>Home</li>
<li>SAF</li>
<li class="navigation-right">Acudetox</li>
</ul>
CSS:
.navigation {
display: inline;
list-style: none;
}
.navigation li {
float: left;
}
.navigation-right {
float: right;
}
All at right side
.right_side{ float:right}
<div class="navigation-left right_side">
<ul>
<li>Home</li>
<li>SAF</li>
<li>Acudetox</li>
</ul>
</div>
Last <li> to the right
.navigation-left li:last-child{ float:right}
first <li> to the right
.navigation-left li:first-child{ float:right}
second <li> to the right
.navigation-left li:nth-last-child(2){ float:right}

Dropdown showing differently in Firefox than in other browsers

I have a problem with Firefox I have a drop down menu at the top of my website this is the code for the CSS
#zone-bar {
background:#E5E5E5;
min-height:30px;
z-index:10;
padding:5px 10px 0;
}
#zone-bar ul li {
float:left;
height:18px;
margin-right:10px;
position:relative;
z-index:10;
padding:5px 5px 0;
}
#zone-bar ul li:hover {
background:#C0C0C0;
}
#zone-bar ul li a {
color:#383838;
display:block;
float:left;
font-size:1.1em;
font-weight:700;
height:23px;
padding-right:3px;
position:relative;
right:-5px;
text-decoration:none;
top:-5px;
}
#zone-bar ul li a:hover,#zone-bar ul li a.zoneCur {
background:url(images/right-hover.png) center right no-repeat;
z-index:10;
}
#zone-bar ul li a span {
position:relative;
top:6px;
}
#zone-bar ul li ul {
background:#FFF;
border:1px solid #ccc;
display:none;
left:0;
position:absolute;
top:29px;
width:150px;
padding:10px 0 0;
}
#zone-bar ul li ul li {
float:none;
height:100%;
margin:0;
padding:0;
}
#zone-bar ul li ul li:hover {
background:none;
}
#zone-bar ul li ul li a {
display:block;
float:none;
margin-left:-5px;
width:140px;
padding:5px 0 0 10px;
}
#zone-bar ul li ul li a:hover {
background:#C0C0C0;
}
#zone-bar ul {
display:block;
}
This is my HTML code
<div id="zone-bar">
<ul><li>
<span>My Account <em><img src="images/arrow.png" alt="dropdown"></em></span>
<ul>
<li>My Account</li>
<li>My Channel</li>
<li>My Videos</li>
<li>Favorites</li>
<li>Playlists</li>
<li>Friend Requests (1)</li>
<li>Logout</li>
</ul></li>
<li>
<span>Messages <em><img src="images/arrow.png" alt="dropdown"></em></span>
<ul>
<li>Messages (1)</li>
<li>Compose New Message</li>
<li>Notifications (0)</li>
</ul></li>
<li>
<span>Videos <em><img src="images/arrow.png" alt="dropdown"></em></span>
<ul>
<li>Recent</li>
<li>Viewed</li>
<li>Featured</li>
<li>Top Rated</li>
<li>Commented</li>
</ul></li>
<li>
<span>Channels <em><img src="images/arrow.png" alt="dropdown"></em></span>
<ul>
<li>Recent</li>
<li >Viewed</li>
<li >Featured</li>
<li >Top Rated</li>
<li >Commented</li>
</ul></li>
<li>
<span>Groups <em><img src="images/arrow.png" alt="dropdown"></em></span>
<ul>
<li>Create New Group</li>
<li>All Time</li>
<li>Today</li>
<li>Yesterday</li>
<li>This Week</li>
<li>Last Week</li>
<li>This Month</li>
<li>Last Month</li>
<li>This Year</li>
<li>Last Year</li>
</ul></li>
<li>
<span>Upload <em><img src="images/arrow.png" alt="dropdown"></em></span>
<ul>
<li>Upload New Video</li>
<li>My Videos</li>
</ul></ul>
</div>
you can see a live demo at doctorwhohd.com
The problem im facing is this in normal all browsers except Firefox it looks like this when you hover over the items
In Firefox all versions i get this
Any help would be great! as this is a problem which i cannot seem to fix and im sure there is something im missing.
Your markup is really ugly for starters,
why have extra <span> tags in the top level <li> tags, why wrap your <img> tags with <em> and don't use for styling purposes.
Clean that up first.
Second, you have a lot of absolute and relative position styles that don't appear to be necessary. Have you tried styling your nav without the use of relative and absolute positioning.
The only place I see relative positioning being useful here is for the little arrow images.
Try that out.
You can give each #zone-bar ul li an explicit width (since it is the width of the li that is overrunning its content).
You may want to give each li an ID or class so that you can control their widths individually.