I have a sidebar that displays an icon and some text aligned. This sidebar is resizable and sometimes text and icon don't fit in the same line.
This jsfiddle shows an example. Blue button shows how it looks like when the line fits and orange button shows what happens when the text is too long.
My goal is to make it look like this when the line is too long:
It is text should stay at rigth side of the image vertically centered with it. No problem if I have to change HTML.
#Ivan; you can write like this http://jsfiddle.net/sandeep/UEk5b/15/
a, a:visited {
color: blue;
text-decoration: none;
display:table;
}
ul li a span {
display: inline-block;
width:102px;
vertical-align: middle;
}
display:table is not work in IE7 & below.
Edit
check this without display:table
http://jsfiddle.net/sandeep/UEk5b/19/
Try this way:
ul li {
cursor: pointer;
padding-left: 70px;
ul span {
vertical-align: middle;
display: inline-block;
}
ul img {
vertical-align: middle;
margin: 0 0 0 -70px;
}
http://jsbin.com/ogofun/5/edit#html,live
What you need is exactly described by html table elements:
<div id="resizable">
<ul>
<li>
<a href="#" class="ajax-page">
<table><tr><td valign="middle">
<img src="http://bit.ly/mRkUDB" alt="" width="60px" height="60px"/>
</td><td valign="middle">
<span>This is a test</span>
</td></tr></table>
</a>
</li>
<li>
<a href="#" class="ajax-page">
<table><tr><td valign="middle">
<img src="http://bit.ly/o7Elfp" alt="" width="60px" height="60px"/>
</td><td valign="middle">
<span>This is another larger test</span>
</td></tr></table>
</a>
</li>
</ul>
</div>
although you still might want different representation with different CSS styles or at low widths, in which case using tables might be a bad idea.
Related
I am using float right to make two links appear on the right of every list item. But they do not stick to the right side for all the list items, causing it to appear like a step. I have tried a lot of combinations from various answers on SO for about 4 days. Nothing seemed to work.
I asked this question, two days ago on SO, and did not get any response, probably because it had JSF code. So I have stripped down the html generated to the minimal code that replicates this issue.
https://jsfiddle.net/9g5h6687/10/
.labelTitleBox {
overflow: hidden;
width: 100%;
display: inline;
}
.layerPanelButton {
font-size: 18pt !important;
text-decoration: none;
color: #0092cf !important;
}
.layerPanelButtonWrap {
width: auto;
float: right;
padding-left: 4px;
padding-right: 4px;
color: #0092cf !important;
}
.label {
width: auto;
display: inline;
white-space: normal;
}
<div id="form:layerTree" class="ui-widget-content">
<ul>
<li id="form:layerTree:0">
<span class="label">
<span class="layerPanelButtonWrap">%</span>
<div class="labelTitleBox">Node 0</div>
</span>
<ul class="">
<li id="form:layerTree:0_0">
<span class="label">
<span class="layerPanelButtonWrap">=</span>
<span class="layerPanelButtonWrap">%</span>
<div class="labelTitleBox">Node 0.0</div>
</span>
</li>
<li id="form:layerTree:0_1">
<span class="label">
<span class="layerPanelButtonWrap">=</span>
<span class="layerPanelButtonWrap">%</span>
<div class="labelTitleBox">Node 0.1</div>
</span>
</li>
<li id="form:layerTree:0_2">
<span class="label">
<span class="layerPanelButtonWrap">=</span>
<span class="layerPanelButtonWrap">%</span>
<div class="labelTitleBox">Node 0.2</div>
</span>
</li>
</ul>
</li>
</ul>
</div>
You need to clear the floats because the font size of the floated items are larger than the line-height of li so they stack on each other
ul ul {clear:right;}
li:after {display:block; clear:right; content:'';}
Updated fiddle
Also, nothing to do with the problem but you have invalid html in your answer - div is not allowed to be a child element of a span
It is the wrapping element's height that causes the indent of the floating elements.
If you add a height the spans will float right as expected.
li {
height:50pt;
}
This will not fix your list completly, but it could point you in the right direction.
https://jsfiddle.net/9g5h6687/13/
I have the following code for my website and I am trying to center the images on the webpages
<ul class="">
<a href="https://www.github.com">
<img style="height:auto; width:auto; max-width:50px; max-height:50px;" src="images/github.png" border="0" alt="Code" class="">
</a>
<a href="http://www.linkedin.com">
<img style="height:auto; width:auto; max-width:50px; max-height:50px;" src="images/linkedin.png" border="0" alt="Connect" class="">
</a>
<a href="https://www.twitter.com">
<img style="height:auto; width:auto; max-width:50px; max-height:50px;" src="images/twitter.png" border="0" alt="Twitter">
</a>
</ul>
I also have the following CSS:
a{
color:black;
text-decoration: none;
margin: 0px auto;
width: 400px;
}
ul{
padding: 0;
}
What would I need to do to center all three image links on my website?
use
<ul style="display:block;margin:0px auto;">
///tags
</ul>
it will justify the ul tag.
<ul style="width:100%;display:block;text-align:center;">
///tags
</ul>
it will justify the content of the ul tags
use this code:
DEMO
ul{
padding: 0;
text-align:center; /* added */
}
ul{
margin: 0 auto; /* For hate it at the center*/
padding: 0;
width: aWidthToTheDiv; /* You could set it to 100% or an value as 800px (example) */
}
And done :)
This should work, also you could add a tag as "text-align:center;" but this is gonna keep all the text at the center and probably you want to have it in other alignment.
Since you haven't used <li> tag along with <ul>
I recommend you to use to <p> tag.
This might be funny.But its so simple and you dont need to do any additional styling.
All you need to do is add text-align:center
TRY THIS -> WORKING DEMO
Image Sprites, by themselves, are not evil; however, trying to get these to work in an unordered list is difficult. Going a step further and trying to get this unordered list to display horizontally (working example >> HERE <<) is certainly an enigma.
Here is my jsFiddle Project: jsFiddle: hNJmD
It seems like every time I get something working, I make the smallest edit to customize it for my app and it breaks.
Does it matter what order items in a CSS file are declared?
Does a <ul> tag have to be defined before a <li> tag?
Does height: need to be specified before width:? (I generally try to list things alphabetically so I don't accidentally have duplicates)
Here is the image I am using as my Sprite:
My Goal:
Center the menu horizontally the page
Have the full image display (all 50 px)
Disable the a.hover effect for the active item (Link 1)
The CSS is:
#nav {
text-shadow: 4px 4px 8px #696969;
white-space:nowrap;
vertical-align: middle;
}
#nav ul {
list-style-type:none; /* removes the bullet from the list */
}
#nav li {
display: inline-block;
text-align: center;
height: 50px;
width: 192px;
}
#nav a {
background: url('http://i.imgur.com/Sp7jc.gif') 0 -100px no-repeat;
display: block;
color:Blue;
}
#nav a:hover {
background-position: 0 -50px;
color:Red;
}
#nav .active, a:hover {
background-position: 0 0;
color:Black;
}
#nav span {
top: 15px;
padding-left: 5px;
}
The HTML used in the jsFiddle is repeated here as well:
<body>
<div>
<ul id="nav">
<li>
<a class="active" href="#">
<span>Link 1</span>
</a>
</li>
<li>
<a href="#">
<span>Link 2</span>
</a>
</li>
<li>
<a href="#">
<span>Link 3</span>
</a>
</li>
</ul>
</div>
<br/>
<br/>
<br/>
<br/>
<div style="text-align:center;">
<p>REFERENCE: Sprite (Width: 192, Height: 150):</p>
<img src="http://i.imgur.com/Sp7jc.gif">
</div>
</body>
Can somebody show me how to get this crazy thing to work?
If you want it to look like this: jsFiddle example, then this is what I did:
Combined your #nav and #nav ul rules since they refer to the same thing.
To that rule I added margin:0 auto; and width:600px; which centers the items
Then on #nav a I added display: block; and height:50px; which allows the links to take up the proper amount of height.
Finally I added a rule, #nav .active:hover that only affects the active element so it doesn't appear to change.
And to answer one of your questions about whether the order of CSS rules matters, the answer is yes and no. With respect to width and height in a rule, the order is irrelevant, but the order the rules appear in can matter, as does the specificity of the rule.
How do I get two buttons to appear one above the other in a span? The buttons should both be the same size also. I've tried vertical-align:middle and display:inline-block but with no success. The end goal is to have one list on the left, two buttons in the middle, and one list on the right. The buttons in the middle will be "Add" and "Remove" and move items between the two lists. I found this link but it was updated in 2004 and seems like a very poor way to do it. I've been searching for awhile and I must not be looking for the right things, so some guidance would be appreciated.
Here two buttons are aligned one above the other.
First between two lists:
http://jsfiddle.net/xGXER/
<!DOCTYPE html>
<html>
<head>
<title>Buttons in between</title>
</head>
<body>
<ul style="background: #afa; display: inline-block; width: 100px; vertical-align: top;">
<li>First</li>
<li>Second</li>
<li>Third</li>
<li>Fourth</li>
</ul>
<span style="display: inline-block; width: 70px; background: #6af; vertical-align: top;">
<button style="width: 70px;">Add</button>
<button style="width: 70px;">Remove</button>
</span>
<ul style="background: #afa; display: inline-block; width: 100px; text-align: right; vertical-align: top;">
<li>Ein</li>
<li>Zwei</li>
<li>Drei</li>
<li>Vier</li>
</ul>
</body>
</html>
...and then between two spans:
http://jsfiddle.net/JtXj2/
<!DOCTYPE html>
<html>
<head>
<title>Buttons in between spans</title>
</head>
<body>
<span style="background: #f06; vertical-align: top;">Foo bar has left the building</span>
<span style="display: inline-block; width: 70px; height: 52px; background: #06f;">
<button style="width: 70px;">Add</button>
<button style="width: 70px;">Remove</button>
</span>
<span style="background: #0f0; vertical-align: top;">Bar hopping is what we do at Friday nights</span>
</body>
</html>
span { display:block; }
span button { float: left; width:100px; height:100px; margin:10px; clear:left; }
span .clearingelement { clear:left; }
The span element is an inline display element. Why not use a div element which is a block element? I don't see the point of styling a span to act like a div
Have you has only two buttons inside a <SPAN>? I guess the <SPAN> are inside a <P>, so I hope this would be what you need:
http://jsfiddle.net/Gpt6a/
This seems too simple, but - if the question actually is "How do I get two buttons to appear one above the other in a span?", then... I think this is your answer.
<span>
BUTTON 1<br />
BUTTON 2
</span>
EDIT:
Set the width of the list and float it:
<ul style="width:100px; float:left;">
<li>list item 1</li>
<li>list item 2</li>
</ul>
<span>button1<br />button2</span>
The HTML code:
<ul>
<a href='index.php'>
<li>
<img src='images/icons/home.png' alt='' />
<p>Home</p>
</li>
</a>
</ul>
The CSS:
ul {
height:100%;
position: absolute;
right: 0;
text-align: left;
}
ul li {
height: 100%;
width:90px;
float: left;
}
ul li p {
margin-top: 4px;
width: 100%;
}
ul a li {
display:block;
}
ul li img {
margin-top: 8px;
width: 43px;
height: 43px;
}
(I've left all the properties here except the font stuff)
The problem:
In Internet Explorer only: the whole link (which is a square block with text and an image inside) functions normally as a link except for the part where the image is. In that part when clicked on the link does not work. It does, however, strangely, still, show the link in the status bar when you hover over any part, including the image.
You should provide a larger sample of your HTML, but I can already see that it's invalid:
<a href='index.php'>
<li>
..
</li>
</a>
You either have an a element as a direct child of a ul element which is invalid.
Or, you don't have a containing ul element, which is also invalid.
It's only valid to use an li element inside a ul or ol element (and a couple of other less common scenarios).
Valid HTML would look like this (assuming HTML5!):
<ul>
<li>
<a href="#">
<img src='images/icons/home.png' alt='' />
<p>Home</p>
</a>
</li>
</ul>
Once you use valid HTML, it should work in IE.
(But, you didn't specify what version of IE, so I'm just guessing that it will.)