Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - Link not clickable when using absolute position

Here is the HTML script of my header:

<div class="header"> <div class="logo"><a href="Default.aspx"><img src="style/images/logo.png" alt="" /></a></div> <div class="toplink"><a href="Signin.aspx">Sign in</a></div> <div class="search">     <form class="searchform" runat="server" method="get">         <input type="text" id="s" name="s" value="Search for photos" onFocus="this.value=''" onBlur="this.value='Search for photos'"/>     </form> </div> </div> 

And here is the CSS script:

.logo {     padding: 30px 0; }  .logo img {     display: inline; }   .toplink {     position: absolute;     bottom: 40px;     right: 280px;     font-size: 14px; }  .search {     position: absolute;     bottom: 10px;     right: 0;     font-size: 14px;     width: 330px; } 

Somehow the Sign in link isn't clickable, but when I remove the absolute position, it works normally. Is there anyway to make the link work while still keeping the position? Any suggestion is appreciated, and thanks in advance.

-Edit- Turns out the problem lies somewhere else. Actually I'm using masterpage and I created a default ASP page using it. The problem only occurs when I test that ASP page, not the HTML file that I used to create the masterpage. Sorry if I sound complicated but yeah, the problem's sort of complicated to me. Hopefully someone can point out the reason for me.

like image 305
huong Avatar asked May 19 '12 07:05

huong


People also ask

Why does position absolute not working?

If you are placing an element with absolute position, you need the base element to have a position value other than the default value. In your case if you change the position value of the parent div to 'relative' you can fix the issue.

What happens when position is absolute in CSS?

An element with position: absolute; is positioned relative to the nearest positioned ancestor (instead of positioned relative to the viewport, like fixed). However; if an absolute positioned element has no positioned ancestors, it uses the document body, and moves along with page scrolling.

Is it bad to use absolute positioning CSS?

As long as you structure your HTML so that the elements follow a logical order that makes sense when rendered without CSS, there is no reason why using absolute positioning should be considered bad practice.

Is it bad to use position relative in CSS?

It's a bad idea imho as it changes the default behaviour of elements without clear indication and it will have unforseen consequences. If you really want to have most elements positioned relative, you might want to think about just making div and similar relative.


1 Answers

Try adding z-index:10; to .toplink{...} class.

like image 93
Krishanu Dey Avatar answered Sep 29 '22 23:09

Krishanu Dey