Adding text titles to inline <li> images - html

I am building a portfolio site and am looking to add html text titles under my home page images. The images are formatted in an inline list, floated left. I'm somewhat new to this, so bear with me if it's ultra simple. I'd like the text to align left under each image and be hidden upon rollover.
Page:
http://www.lauradimeo.com/TEST/index2.html
Forgot to add -- I'd like this to look great on a tablet device. I know the rollovers won't work but otherwise it should be ipad, etc friendly.
thank you!

I think I have what you're looking for using a CSS-only (no Javascript) approach: demo page
Inside your first list item I inserted a div:
div.caption {
width:200px; /* Because your images are 200px wide, this must match */
clear:both; /* This places the div after the floated image */
position:relative; /* Required to set positioning on the line below */
top:-100px; /* The div would normally appear at the bottom of the image. Move it up a little. */
margin-bottom:-500px; /* A hack because the div causes the li to have a larger bottom margin. Not sure how to get around this */
z-index:2 /* Will explain this later */
}
<li> ... <div class="caption">The quick brown fox jumped over the lazy dog</div></li>
And I added z-index attributes to your li/a/img elements:
#work ul li, #work ul li a, #work ul li a img {
position: relative; /* z-index only works on positioned elements */
z-index: 1; /* Default z-index 1 */
display: block;
float: left;
}
#work ul li a:hover, #work ul li a:active {
position: relative; /* Hover/active z-index 3 */
z-index: 3;
}
Take a look at how to use z-index if you're not familiar with it. On the test page the caption div has a higher z-index than the regular image but a lower z-index than the mouse-overed image.
This is a little hacky, but there's room for improvement. Also FYI, your page doesn't look right in IE 7- all the images appear in a single column. My code might not need the hacks if and after you fix your markup. =)

Try wrapping the images in a container like a <div>-tag (you can also use a <table>). Insert the image into a div tag and put the text in too. Upon mouse-hover, use javascript to hide the text and make the image larger.

Another possible solution would be to absolutely position the images in your li's, and use margins / padding to position your text under the images as to be visible until the image is moused over. While this approach would likely allow you to retain your no-JavaScript hover effects, it may not be the easiest to implement as your markup stands currently.

you can also try using the dl, dt, dd tags. It would get you the same result and you can use javascript to show and hide the text. You can specify the width of the DIV and DL. Then you can have the DL float: left inside that DIV. Please let me know if this is helpful.
Link to the DL tag
http://www.w3schools.com/tags/tag_dl.asp
<div id="main-holder">
<dl id="box1" class="my-images">
<dt>Image</dt>
<dd>HTML Text</dd>
</dl>
<dl id="box2" class="my-images">
<dt>Image</dt>
<dd>HTML Text</dd>
</dl>
</div>

Related

HTML / CSS - Unexplained margins

I have the following page with some HTML / CSS : http://jsfiddle.net/Hf6dB/1/
For some reason the buttons of the toolbar at the top of the screen have a margin right. Margin left, top and bottom is ok because the container has a padding, but where is the margin right from ?
Also in the real version of the page, which you can't see on the fiddle bbecause there are no icons, i have a similar problem in each of the menu entries :
<li>
<div class="draggable">
<input id="tb-btn-search" title="Search" type="button">
<p>Search</p>
</div>
</li>
When the mouse is out of the button, the <p> has a width that gets animated from 0 to something like 2 using CSS transitions. For some reason, when the width of the <p> is zero, the icon is not centered anymore because, here too, there is an extra margin that comes from nowhere.
Would this be related to the usage of inline block display property ?
Thanks for yor help !
display: inline-block creates a gap between elements. Further reading here.
Edit:
bjb568 mentioned in the comments re 4px gap:
NO! 4px gap depends on the font and size. You cannot use negative margins to solve this, since you don't know how big the gap is. -4px is a magic number, and thus should be avoided. Use font-size: 0, instead
You can delete inline-block in the <ul> and add float: left; to the li
#toolbar ul,
#toolbar li
{
display: inline-block; /* delete this
}
#toolbar ul,
#toolbar .tb-separator,
#toolbar li
{
float:left;
}
Updated JsFiddle
The line breaks between the elements are treated as whitespace, because the elements are inline-block, so they are part of a line of text. You can solve this by removing spaces and line breaks between the elements. If you want to keep the indenting in your document, you can choose to add a line break inside the element itself:
<outer
><inner
></outer>

How can I make my background-color fill all my content, even with horizontal scrolling?

I'm using an <ol> to show a code snippet with line numbers. Since I'm showing program code, I disable wrapping (and enable indentation) by setting white-space: pre on li, which means an li's content can extend past the right margin and cause the page to have a horizontal scroll bar. So far so good.
The problem comes when I want to set background colors on some of the lis to call out particular lines of code. I can set background-color on the li, but the color only extends to the right margin of the page; in fact, the last 10 pixels or so of text (an amount equal to the body's right margin) has no background color. And if I scroll horizontally, it's even worse: the background color scrolls left off the page. The background-color is only one browser-width wide (minus the page margins).
Here's a fiddle illustrating the problem. If you scroll right, I want the background to be blue for as far as there's text.
How can I get the background-color to fill the full width of the content, even if the page scrolls horizontally?
You can "shrink-wrap" each li's content with a combination of float and clear, as in this answer.
li {
white-space: pre;
background: blue;
float:left;
clear:left;
min-width:100%;
}
The last line is from koala_dev's answer. It forces shorter-content elements to have full-width background.
Fiddle
You can use display: inline-block to make each list item fit its content. Combine this with min-width:100%; to make shorter-content lis stretch to full container's width.
li {
white-space: pre;
background: blue;
display: inline-block;
min-width:100%;
}
Demo fiddle
This is not possible with using directly a li item.
But a simple span inside the li fixes this.
Here is the relevant code:
span {
white-space: pre;
}
.highlight {
background: blue;
}
Your markup would be along the lines of:
<ol>
<li><span> Code Here... </span></li>
<li><span class="highlight"> Code Here... </span></li>
</ol>
The reason for this is. If you change the li's display to anything else than list-item it will lose it's numbering. (In Chrome at least.) So this way you get both with just a bit more overhead.
A jsfiddle showcasing it: http://jsfiddle.net/tp6Um/4/
I found a way to kind of fix your problem
li
{
white-space:pre;
display:block;
width:150%;
}
set the percentage accordingly

CSS submenu alignment issue

I've currently working through a tutorial on responsive webdesign, and I wanted to make my navigation different than what the tutorial had (I want my nav bar to have a coloured background, and be centered..as opposed to the tut's not having a bkgd and was left-aligned).
Without the background I had the submenu displaying properly. When working to setup the coloured bar in the background, the only way I could get it to show up was to remove the 'float:left;' that I originally had in my '.primary ul li{}' selector. Now that that is removed, when I mouse over 'Item 4' which is the item with the submenu, the submenu now displays left-aligned with the bar instead of directly below Item 4. You can see what I mean here:
http://jsfiddle.net/mark_a_b/ytB66/1/
If I add the 'float:left;' back in, you'll see that the background colour bar of my navigation disappears, and my menu items are no longer centered as I want them (not I set the bkgd colour for this version to be dark grey just so you can see the menu items) as shown here:
http://jsfiddle.net/mark_a_b/ytB66/3/
I'm sure it's likely something silly that I'm just overlooking, but I've spent too much time messing around with it and getting nowhere, so was hoping someone else might be able to help me out with this. Appreciate any help offered!
Thanks!!
Just add a positioning to your sub-menu left: 0; - DEMO
.primary ul ul{
position: absolute;
left: 0; /* this */
z-index: 999;
background-color: #ccc;
height:0px;
overflow: hidden;
min-width: 100%;
}
<ul> and <li> are block-level elements;
normally <li> are placed vertically, while here they're displayed horizontally because of the display: inline; property value.
Every <li> here is also a container for another <ul> and it's not good to use an inline-level element as container for a block-level element.
The solution is: use display: inline-block;, which combine inline-level display style with block-level behaviour:
.primary ul li{
display: inline-block;
position: relative;
}

CSS HTML : my drop down menu li is cutting off an image height

learning html/css here. I can't seem to understand how to tweak this drop down menu. I'm trying have to tweak it to hold an image and a name, then to have the links.
Right now the image is getting cut off due to the <li> height, when I change the <li> height to 100% it get some weird behavior that I don't understand. Any help would be really appreciated to learn whats going on.
image getting cut off
http://jsfiddle.net/FyU89/
odd behavior after I add height: 100%
.menu ul li ul li{
padding:0;
float:none;
margin:0 0 0 0px;
width:100%;
height: 100%
}
http://jsfiddle.net/FyU89/1/
Add to your css
ul.menu-drop li {
display: inline-block;
}
Fiddle link
Update:
Upon adding the new css rule you'll find the name disappears from next to the image on Chrome, at least it does for me. To fix that add a float: left on your image and the name will appear next to the image on Chrome, Firefox, and IE; you can then style it more to your liking. Fiddle link with the float change.
just going through your css and code, it appears that these drop downs would inherit the height from their parent (.menu), which is set to 30px. the images seem like they are set to have a height of 48px; this maybe causing your cutoff.
Add this to your css code:
ul.menu-drop li {
height: 50px;
}
That sets the height of your list within the menu-drop menu thing so its big enough for the picture.

css link not making all text a link?

I have dropdown menu and its made via a list and position absolute, however the dropdown links are very very very small area and do not cover the text completely.
How can I fix this?
Example http://outreviews.com/v%202/index.html (the dropdown menus)
Remove the padding from the sub menu's UL and LI and give the A element "display:block" This will make the A element take up the entire width of the menu.
You can fiddle with the padding to get it the way you want it.
If you add:
ul li a {
display: inline-block;
width: 100%;
height: 100%;
}
It should work okay, and since even IE allows display: inline-block; on natively in-line elements it should be relatively cross-browser friendly (certainly under a valid doctype).
It's worth remembering that padding on the parent li will also reduce the possible width of the child a element, and the display: inline on the same parent li is also likely to cause you a little trouble (since display: block; on the a would be so much simpler).
Edited to note that #Chris Bentley correctly noted the points in my final paragraph (above the hr) just prior to my answer.
make the following changes:
in #headermenu li change the padding:20px; to padding :0 20px;
add delete the top:55px; from #headermenu li ul
What you can do is make the li elements display:list-item and the a elements display:block. That's what's being done on the site you're linking to.