(编辑:jimmy 日期: 2024/11/13 浏览:2)
:hover
states immediately below. There’s no clear division between the four links at the moment, so imagine that each piece of text is a link for now. (For the sake of simplicity, we’ll continue to refer to link images as “before” images and the :hover
state as “after” for the rest of this article. It’s possible to extend this method to :active
, :focus
, and :visited
links states as well, but we won’t go into that here.)
<ul>
instead. You’ll see why in a moment.
#skyline
block and the list items, starting positions for the list items, and it turns off the unwanted list bullets.
<li>
s. If we were to position the links themselves and effectively ignore the <li>
s, we’d start seeing errors in older browsers, so let’s avoid this.
<li>
s are absolutely positioned, so why aren’t they at the top of the browser window? A quirky but useful property of positioned elements is that all descendent elements contained within them base their absolute position not off the corners of the browser window, but off the corners of the nearest positioned ancestor element.The upshot of this is that since we applied position: relative;
to #skyline
, we’re able to absolutely position the <li>
s from the top left corner of #skyline
itself.
#panel1
isn’t horizontally positioned at all, #panel2b
is positioned 96px to the left of #skyline
’s left edge, and so on. We assigned the links a display: block;
value and the same height as the <li>
s in the past listing, so they’ll end up filling their containing <li>
s, which is exactly what we want.
:hover
states. See the example. It’s probably easier to see what’s happening with borders turned on.
:hover
state without additional values, we make only the top left corner visible — not what we want, though clipped by the link area, which is what we want. We need to move the position of the image somehow.
<li>
s prior to the one we’re working with. So the first link doesn’t require an offset, since there are no pixels before its horizontal starting point. The second link requires an offset the width of the first, the third link requires an offset of the combined width of the first two links, and the last requires an offset of the combined width of all three previous links.
<ul>
for placing the original background image, we’ll end up applying it to all <li>
s instead and offsetting each the same way we offset the after states in the prior example.
<li>
, we’ve got buttons.
<ul>
and turning off list item bullets and setting widths and so forth. The big difference is where we position the <li>
s; the goal is to surround each graphical element with a box that tightly hugs the edges.