Hi. Thanks for reading:
I am trying to develope a standard page header. On the right side I have 6 “linkboxes”. I would like to have them change background color and font color when hovering over any of them. “Home” works as I wish. It has no anchor (<a>).
Problem 1: The others only work when the anchor (<a>) has the cursor over the text portion.
Link 3 is a pulldown menu.
Problem 2: When activated, it pushes everything down. I would like it to open on top of whatever is below it without pushing down.
For problem 1, it’s because the text for the link only changes when you hover over the link, but the link doesn’t fill the entire square. You should make the a element fill the entire linkbox div so that way when your mouse is over that square it is always hovering the a element.
For problem 2, you’ll most likely want to use absolute positioning on the list.
which caused an overflow to a new line. This did not help. The text needed to be hovered over.
I tried adding position: absolute; as well as others to .linkbox without any luck.
Ahh, that’s not the method I would use to make the link take up the entire space of the div. By default an a element will only take up as much space as needed because it is known as an inline element. Block elements on the other hand will take up as much space as they can, in other words, they will fill out their parent container. So I would change the a element into a block level element. You can do this using the CSS display property.
Well, I’m not sure what to tell you. Using a copy of your codepen, I just added display: block to that rule set and it worked for me. Also, I would recommend you get rid of border on .linkbox and find another way to add space between the menu items.
Please try again and make sure you save your codepen so I can see your changes.
Thanks, Bruce @bbsmooth .
Codepen holds my latest version. I am making progress, thanks to you.
I can squeeze down and the .linkboxes will stack as I wish.
This is looking pretty good (at least problem 1). Just a few things to consider:
There is no reason to add display: block to the .linkbox div as divs are block level by default. There’s no real harm adding it. It just isn’t doing anything for you and having unnecessary code is usually seen as bad.
You still have a very minor issue with your hover color changes. Since the border on the .linkbox div is 1px and you are changing the background color to blue on hover over this div, this means that there is a 1px region around the link which will turn blue without the link text turning yellow. So you either need to change the color change to hover over the link or you can remove the border from the div and add it to the link instead.
Thanks again, @bbsmooth . I am probably wrong, it looks like the .linkbox expands to accommodate the ul > li children. I don’t see any border displayed around them.
Do you see how my mouse pointer is just barely over the black border so it is triggering the :hover on the .linkbox div which is turning the background blue but it is not hovering over the link itself and thus the link text is not turning yellow. It’s a very minor issue and most likely no one will notice, but if you are a perfectionist like me then you’ll want to fix it
Thanks again, @bbsmooth
In the updated CodePen, I removed the borders, add box-shadow: 0 0 3px black; to .linkbox and put an <hr> under the table. This looks more like what I hope for.
Is this a solution you would use, or is there something better?
Any suggestion for problem 2? Or comment on the colors?
I appreciate and obviously need the help you have given.
Thanks.
– Fred
I tried position: absolute; under each of the hovers. Yes, it comes over the top. “link-3” highlighted shows link-3-b, link 3-a is not seen.
Ill be back in a couple of hours.
Thanks, @bbsmooth
Hi Bruce @bbsmooth ,
My latest version is on CodePen, I used flex-wrap: wrap-reverse; so that the linkboxes stack when the screen width is reduced and allow all of the links to be seen.
I would appreciate any suggestions or comments. I went back to black and white as I am not able to get a good evaluation for the color change idea (suggested by my granddaughter).
Thank you again for your teaching and guidance.
– Fred