I'm trying to position two elements within an li list next to eachother on the right side to get the result:
Some text.................A...B Unfortunatelly the ordering drives me crazy.
Here's the html code:
<ul class="list">
<li>some text
<small class="a">A</small>
<small class="b">B</small>
</li>
</ul>
With the following CSS code I was able to get the small-elements on the right side next to each other, but the result is that i see on the right side B next to A!
.list li{
background-color:#282828;
color:#ffffff;
font-size:20px;
text-transform:uppercase;
padding-left:5px;
}
.list small.a {
display:inline;
float:right;
}
.list small.b {
display:inline;
float:right;
}
So, I aim to have:
some tex.....................A...B
but for instance it looks like:
some text....................B...A
See example here --> http://jsfiddle.net/LKVdE/
Thanks upfront for any tip!
Here is the solution: http://jsfiddle.net/surendraVsingh/LKVdE/1/
CSS
.list small.a {
background-color: #000000;
display: inline;
}
.list small.b {
background-color: #ff0000;
display: inline;
}
.list li span{
display: inline-block;
float: right;
}
HTML
<ul class="list">
<li>Brennwert kJ / kcal
<span>
<small class="a">1109kJ / 261kcal</small>
<small class="b">455kJ / 107kcal</small>
</span>
</li>
</ul>
A and B should be put in a right floating container:
.list small.a {
display:inline;
}
.list small.b {
display:inline;
}
.floatright {
float:right;
}
And
<li>some text
<div class="floatright">
<small class="a">A</small>
<small class="b">B</small>
</div>
</li>
Why does this happen, because first style is applied to a which moves it to to the right, whatever next appears in the markup must now follow a from the right that's why you see BA instead of AB
Markup changes: Include the text inside a span and add float:left to it
<ul class="list">
<li><span class="text">some text</span>
<small class="a">A</small>
<small class="b">B</small>
</li>
</ul>
Css changes, remove float:right from a and b and add float:left to text
.text{float:left;}
.list small.a {
display:inline;
}
.list small.b {
display:inline;
}
Working fiddle: http://jsfiddle.net/LKVdE/8/
Related
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/
When hovering over Choose Location the div adv_cities should be displayed and i can navigate the adv_cities menu. What i've tried isn't working.
<div class="header_top_location"> <ul id="city_nav" class="city_nav menu">
<li class="mega">Choose Location
<div class="adv_cities" id="adv_cities" style="display:none">
<ul><li>London</li>
<li>Bristol</li>
<li>Manchester</li>
<li>Kent</li>
</ul>
</div>
</li>
</ul>
</div>
The CSS
.header_top_location .mega > a:hover + .adv_cities, .header_top_location .adv_cities:hover .adv_cities{
display:block !important;
}
.header_top_location .adv_cities {
background-color:#fff
}
.header_top_location .adv_cities ul{
overflow:hidden;
}
.header_top_location .adv_cities li{
float:left;padding:10px;
}
How do i solve this?
The city_nav code is from a plugin and i use on multiple pages, so i don't want to change the code since i use in multiple places.
If all you want on your drop down menu is to hover over one list iten to display the submenu, then you dont necessarily need the inner div and stuff... here is a code snippet for you to work with...
.mega:hover > .adv_cities {
display: block !important;
}
.header_top_location .adv_cities {
background-color: #fff
}
.header_top_location .adv_cities ul {
overflow: hidden;
}
.header_top_location .adv_cities li {
float: left;
padding: 10px;
}
<div class="header_top_location">
<ul id="city_nav" class="city_nav menu">
<li class="mega">Choose Location
<div class="adv_cities" id="adv_cities" style="display:none">
<ul>
<li>London</li>
<li>Bristol</li>
<li>Manchester</li>
<li>Kent</li>
</ul>
</div>
</li>
</ul>
</div>
The only changes I made in css are in the 1st 3 lines... and I removed the extra div that IMO was not needed..
hope this helps
I have this html code
<ul id="list-table">
<li>
<table id="test-tab">...</table>
<ul id="panel-table">...</ul>
</li>
</ul>
I want table "test-tab" and ul "panel-table" inside li display horizontal like this http://img.photobucket.com/albums/v246/TuanVenus/table-css.png
I'd suggest using float: left. Normally, I'd go with display: inline-block but that might break the table layout. Don't forget to add a pseudo-element which provides the clear-fix for the parent element (<li>).
#test-tab, #panel-table {
float: left;
}
#list-table li::after {
content: "";
display: block;
clear: both;
}
Give float to your elements like this:
CSS
.fleft { float:left;}
HTML
<table id="test-tab" class="fleft">...</table>
<ul id="panel-table" class="fleft">...</ul>
Just add the same styles to your CSS as in http://jsfiddle.net/vMe5L/38/ Enjoy !!
you could use display and wrap your table in a div, so it doesn't get broken:
http://codepen.io/anon/pen/tjesx/
#list-table {
display:table;
width:600px;
border:solid;
border-spacing:1em;
padding:0;
}
#list-table > li {
display:table-row;
}
#list-table > li > ul ,
#list-table > li > div
{
display:table-cell;
border:solid;
margin:0;
}
try this,
<style>
#test-tab{
float:left;
}
#panel-table{
float:left;
}
</style>
<ul id="list-table">
<li>
<table id="test-tab"><tr><td>example table</td></tr></table>
<ul id="panel-table"><li>example li</li></ul>
</li>
</ul>
Try add a css style
<ul id="list-table" style="list-style: none;">
I've created a jsfiddle http://jsfiddle.net/zkLav/ showing the code in action. what's happening is the images and text alignment are step stacking and not aligning vertically. Can anyone explain why this is happening?
CSS markup:
.outList {
display:table;
}
.outList span {
display:table-cell;
vertical-align:middle;
width:10%;
}
.outList h4 {
display:table-cell;
vertical-align:middle;
width:50%;
padding-left: 10px;
}
.outList p {
float:right;
display:table-cell;
vertical-align:middle;
/*width:30%;*/
text-align:right;
}
.outList img {
width:100%;
}
HTML markup:
<ul>
<li data-theme="c">
<a href="detail.html">
<div class="outList">
<span><img src="simgs/listview_chk.png" /></span>
<h4>Warmup</h4>
<p>5 Minutes</p>
</div>
</a>
</li>
<li data-theme="c">
<a href="detail.html">
<div class="outList">
<span><img src="simgs/listview_chk.png" /></span>
<h4>Machine Press</h4>
<p>3 sets of</p>
</div>
</a>
</li>
<li data-theme="c">
<a href="detail.html">
<div class="outList">
<span><img src="simgs/listview_chk.png" /></span>
<h4>Lateral Pulldowns</h4>
<p>3 sets of</p>
</div>
</a>
</li>
</ul>
A proper image of the problem:
Ok, take a look at this update
Just remove the width in the next .css class:
.outList img {
width: 100%;
}
UPDATE
For the text at the right to be fully align, remove the float:right; from the p class:
.outList p {
float:right;
display:table-cell;
vertical-align:middle;
/*width:30%;*/
text-align:right;
}
Check this new update
Get rid of the divs, you don't need them given that you have the li's.
Also, why span the img? Get rid of that too.
When you did that, put the ul as the table, the li's as the rows and then the stuff in the a as the columns.
To my knowledge, the answer to this is no, can't be done, but I need a second opinion:
If I have the following:
<li>
<a >#</a>
<div class="sub">
#
</div>
</li>
and have a background image that appears on li a:hover is it possible to have that background stay on when hovering on the .sub div? This also has to work pure CSS - no javascript cheats.
My understanding is because .sub isn't a child of the a we can't reference it in css to keep the hover.
Because the image is for only one section of the code, I can't move it to the li and reference li:hover a.
Not sure what all you are trying to achieve, but there are many hover effects that can be done.
SECOND UPDATE: If you don't need to interact (other a tags, etc) at all with anything in the div, then this way cheats to get the effect. Note how the anchor inside the div does not register because of the z-index.
UPDATE I think I understand your issue better now. Can you add a wrapper and do the following?:
Example HTML:
<ul>
<li>
<div>
<a>Some anchor text</a>
<div class="sub">Some div content <a>and anchor</a></div>
</div>
</li>
</ul>
Example CSS:
li:hover {
background-color: cyan;
}
li > div:hover > a {
background-color: green;
}
a:hover {
color: yellow;
display: block;
}
a:hover + .sub {
outline: 1px solid blue;
}
.sub:hover {
color: red;
outline: 1px solid red;
}
If you can't use a class on the li or modify the div.sub to be in the a, you're probably out of luck without Javascript:
Is there a CSS parent selector?
However, if you can, you could use:
<ul>
<li class="sub">
<a>Class #</a>
<div class="sub">#</div>
</li>
<li>
<a>Inner #
<div class="sub">#</div>
</a>
</li>
<li>
<a>None #</a>
<div class="sub">#</div>
</li>
</ul>
li.sub:hover,
li a:hover {
background: url(http://www.gravatar.com/avatar/e1122386990776c6c39a08e9f5fe5648?s=32&d=identicon&r=PG);
}
li a {
border: 1px solid blue;
display: block;
}
.sub {
border: 1px solid green;
}
http://jsfiddle.net/B7Au2/4/
I don't know if you can modify the html, but if you can, try swapping the div and the a:
<li>
<div class="sub">
#
</div>
<a >#</a>
</li>
Now you can use the adjacent sibling selector:
li a:hover, li .sub:hover + a {background:url('some-image.png')}
Unfortunately there's no way to select the previous element through CSS: that's why you need to swap your elements.