In a mobile web application I have recently created there are many anchor tags used throughout. The anchor tags by default have a clickable area that is purely surrounding the text. I am looking to try and expand this area without affecting the position of the anchor tag at all.
The black border shows the current clickable area and the red border shows the clickable area I would much prefer. The first thing you think of is to add padding, but this moves the tag which is the whole reason what I'm asking is a problem. How can I expand the clickable area of all the anchor tags in the application without affecting their positions?
You can use an absolute positionned pseudo element to increase space where a link stands.
basic DEMO:
a {
display:inline-block;
position:relative;
border:solid;
}
a:before {
content:'';
position:absolute;
top:-1em;
left:-1em;
right:-1em;
bottom:-1em;
border:solid red;
}
This a technique that can be usefull for menus that close too easily because submenu is too much on the edge.
Related
This web page uses a vertical menu that shows a neat little arrow pointing from the currently selected menu item to the page. I examined the code in Chrome and found the following.
For the anchor that displays the arrow the markup is
<li class="current">
<a...>
::before
"Welcome"
</a>
The corresponding CSS is
aside li.current a:before
{
content:"";
border-color:transparent transparent transparent #fff;
border-style:solid;
border-width:10px;
width:0;height:0;position:absolute;left:-30px;
}
I have a fair idea of what is going on here but I haven't quite been able to figure out just how it is that the end result is a triangle pointing to the left. Perhaps someone who understands CSS better than I might be able to explain?
you had used border color of top right and bottom transparent and so it will take color of your left main div. Also as you had used a:before so before start of every a tag it will create this kind of structure in which no content is there and with position absolute you can set it as a triangle view...
If you remove transparent from your code and give colors to border you can see that originally its just like simple square box. So, its a CSS tips and tricks to make shapes using CSS.
I am trying to make use of the transition css rule but my problem is all the content inside the div is bunched together when the transition is idle and not being moused over. Once you mouse over the content in the div, or the title in my example, is stretched out to full form.
Is there a way to make the title stretch out on one line the way it should look while the box is not being moused over?
Here is a jsfiddle of an example of my code: http://jsfiddle.net/3W2hC/
.title {
width:420px;
text-align:center;
Thanks in advance.
EDIT: I was able to do this. By adding a width. However, there is now a scroll bar. How do i go about removing the scroll bar?
If you want the content to be cut off inside of the div, just give your div overflow:hidden in your css.
In your case it will be:
#main {
overflow:hidden;
...
}
Here's a fiddle: http://jsfiddle.net/3W2hC/1/
I'm trying to use only css to turn a nested div and a normal div into something where the top one can be hovered to view more content without moving all the layout around.
Essentially:
[hover me for more]
[content-that-gets-overlapped-by-hover-content]
or see the nearly-working example on jsfiddle:
http://jsfiddle.net/tchalvakspam/vVgY2/9/
Unfortunately, when you do overflow:visible, it seems to be nearly useless because you can't give the content that overflows any background style, so it remains unreadable.
Is that right, there is no way to give overflow:visible overflowing content a background? If that is the sad state of affairs, what is the shortest amount of changes that could be done to that content to turn it into a readable hover-to-expand section?
Finally found the solution in the form of a sibling selector on the hover to give the next element after the hovered element a margin to take the place of the now-absolute hover element.
http://jsfiddle.net/tchalvakspam/MBcDW/
So the pertinent css becomes:
#fixed-height{
position:relative;
width:100%;
height:1.25em;
overflow:hidden;
background-color:lightblue;
color:red;
z-index:10;
}
#fixed-height:hover{
overflow:visible;
height:auto;
position:absolute;
max-width:20em;
}
#fixed-height:hover + #right-below{
margin-top:1.25em;
}
I am trying to use <span> to move some text in my navbar. My navbar is a <ul> and the elements are all <li>s but the text is aligned to the top of the navbar and I want it to be vertically centered. As you can see in the JSFiddle, I am using an a:hover property in CSS to change the background and color of the text when it's hovered over. When I apply the span to just the text, the whole hovering section gets moved too. See if you can understand what I mean.
My JSFiddle is here:
http://jsfiddle.net/G8CJ7/
Basically I just want the text vertically aligned in a simple, concise way. Originally I was using '' tags and setting a margin on them but I want to avoid using header tags for this purpose for improved SEO. Thanks.
http://jsfiddle.net/G8CJ7/1/
Added line-height:40px to center the text vertically. IE7 will have issues with this as it is not fully supported, so a conditional stylesheet with a padding-top on the li will solve it.
Adding line height works, you could also adding padding to the top:
.class { padding-top: 10px; }
Adjust the padding to center.
Updating this a couple years later but there's always the option of using:
display:table;
display:table-row;
display:table-cell;
with vertical-align:middle; in order to center the items. I prefer this approach these days because you can apply responsive rules to the display style (for example, change it to display:block and display:inline-block etc. if you need to update it for other screen sizes. Here is a fiddle:
http://jsfiddle.net/G8CJ7/68/
I'm looking for a bit of brainstorming assistance.
I am coding a layout that was put together by a designer and am trying to think of a way to handle a horizontal navigation that has angled edges, and goes from a blue background, to a white background when a link is selected.
I'll actually just include a screenshot. This is actually the navigation for a Tabbed content area. The top half of the screenshot shows what it will look like when the first tab is selected. The bottom half of the screenshot shows the 2nd tab selected.
http://i.stack.imgur.com/P34yI.gif
So my problem comes from the fact that HTML elements are rectangles, not rectangles with angled edges. I saved the angled edge with the shadow as a CSS background, and that worked fine, until I realized that each link can turn white and the BG image has a bit of the next link embedded in it to give the illusion of the angle, and thus the left most link would need a different background then the middle link, and the right most link, etc...
I could assign a unique class / id (or use nth child) to each link, but I would like to keep the solution flexible so I can add another link/tab in the future.
I was curious if anyone had any ideas on how to create this appearance by possibly using CSS3 / HTML5 / or some transparent PNG and negative margins or relative positioning?
I'm not asking for code or for you to do my work for me :) I'm just looking for ideas - just a bit of community brainstorming. If anyone has any suggestions please let me know, it might lead me to a solution.
Thanks!!
Assuming you're using a 'ul > li > a' structure for the menu, I would use two angled backgrounds (right and left... the right one is about 27px with the shadow, the left about 22px). Apply the left corner to the <li>, and the right corner to the <a>. That will give you doubled backgrounds on each list item, so you should use negative margins on each side of the <li> to pull its siblings to overlap. Then use z-index to make sure on hover or highlight that the menu item shows up on top of the others. I've added an additional 30px of padding on both sides to create the extra space around the text:
li {
margin-right: -27px;
margin-left: -22px;
padding-left: 52px;
position: relative;
background: url(leftcorner.jpg) left top no-repeat;
background-color: #3aa1cc
}
li a {
padding-right: 57px;
background: url(rightcorner.jpg) right top
}
li:hover {z-index: 5; background: url(leftcorner-hover.jpg) left top no-repeat}
li:hover a {background: url(rightcorner-hover.jpg) left top no-repeat}
I haven't tested this but I think it should work... possibly with some additional tweaking.
This solution doesn't include the subtle inner shadow... to do that you would have to use a 1px repeating gradient background on the <li> then use :before and :after pseudo elements for the two corner background images.
Additionally in my code I put two seperate .jpgs (normal and hover) but really you should use a sprite and background-position so there is no flash while the hover state image is loading.