CSS underline and letter-spacing - css

In a website menu, I have implemented some wishes of my customer concerning typography in CSS. She needs a different tracking on the font, no problem. But, she wants the active link to be underlined. As I have not implemented the code to target the active link, I just underlined them all to see how it would look. The CSS is as follows:
.main-navigation a {
display: block;
color: black;
font-weight: bold;
letter-spacing: 0.45em;
line-height: 4.5em;
text-decoration: underline;
text-transform: uppercase;
}
And this is the result:
The problem is that the letter spacing kind of messes up the underlining. I've drawn some vote magnets freehand circles to indicate the problem. The line starts nicely at the left side but is extended with the value of letter-spacing to the right.
Screenshot is from Firefox 25. Jsfiddle to see for yourself.
I could solve this using borders and using margins instead of line height, but is this fixable otherwise?

CSS Text underlining too long when letter-spacing is applied?
http://jsfiddle.net/isherwood/JWcGh/2
.main-navigation a:after {
/* absolute positioning keeps it within h1's relative positioned box, takes it out of the document flow and forces a block-style display */
position: absolute;
/* the same width as our letter-spacing property on the h1 element */
width: 0.45em;
/* we need to make sure our 'mask' is tall enough to hide the underline. For my own purpose 200% was enough, but you can play and see what suits you */
height: 200%;
/* set the background colour to the same as whatever the background colour is behind your element. I've used a red box here so you can see it on your page before you change the colour ;) */
background-color: #fff;
/* give the browser some text to render (if you're familiar with clearing floats like this, you should understand why this is important) */
content: ".";
/* hide the dynamic text you've just added off the screen somewhere */
text-indent: -9999em;
/* this is the magic part - pull the mask off the left and hide the underline beneath */
margin-left: -.40em;
}

Related

Combining font icon and Image Replacement

My HTML is like this:
<li>Facebook</li>
I'm using the fontello icon font system however, I can't seem to work out how to make the word Facebook disappear and the icon remain! The generated content looks like this:
<li>:before "Facebook"</li>
Thanks
(note: I know I can add a span to the text and toggle it but I thought there may have been a purely CSS way to do it?)
This is one way
.icon-facebook {
text-indent: -9999px; /* sends the text off-screen */
background-image: url(/the_img.png); /* shows image */
height: 100px; /* be sure to set height & width */
width: 600px;
white-space: nowrap; /* because only the first line is indented */
}
.icon-facebook {
outline: none; /* prevents dotted line when link is active */
}
and there's also another. I found this question answered here:
Hide text using css

Layout broken in IE 10. Firefox, Opera, Safari and Chrome are working fine

http://www.alecos.it/new/125027/125027.php this link is an example of my problem... I used a png 1x16 for drawing the rows... the rows are visible in the link posted... my question is:
why under IE 6/8, FireFox, Opera, Safari and other browsers the rows are perfectly aligned with the text while under IE 9/10/11 the text do not fit in the rows?
I used a simple css:
/* Style Source Code */
.code {
border-radius: 7px;
border: #6666FF 1px solid;
background-color: #FFF5EE;
background-image: url("../bkg/Bkg_116.png"); /* Horizontal Rows */
background-repeat: repeat;
background-position: 0 10px;
}
/* Style Source Code */
.xcode {
color: #008000;
font-family: 'Courier New', Courier, FreeMono, 'Nimbus Mono L', monospace;
font-size: 13px;
font-style: normal;
line-height: normal;
font-weight: normal;
font-variant: normal;
}
/* Style Div */
.alignment {
line-height: 20px;
text-align: justify;
}
Hope in workround to fix the issue...
here there is my css: http://www.alecos.it/css/alecos.css
I'm not on Windows machine right now but my guess is .xcode(line-height:16px;} would solve your problem, but I must say that this is the wrong way of creating row borders. Why not add:
.xcode td{border-bottom:1px solid #ddd;}
instead of using background image?
Firefox is temporarily outdated unti it's next update meaning that it's browser does not have the ability to process codes in the same manner as other browsers.
.alignment {line-height: 20px;}
Gets over ruled by .xcode line-height normal;
IE aint normal ;)
Besides content tages like h1, p, font all have slightly different margins/paddings around them. So a non responsive img isnt the best way to go.
Would be better if you could wrap each line with a span, div or sinces its a table a tr,td and give those a border-bottom.
Gr.
Kevin
In order to make your text inside .xcode aligned with the horizontal lines, the "code" lines must be distributed vertically. Unfortunately, It seems that you did not understand the meaning of line-height property and use the default value without considerations.
The line-height property
As you can see, the line-height property will decide how much is the distance of two lines of text. In your case, we need it to be exactly 16px inside the whole block of .xcode.
The value of normal value of the line-height property
From the W3C CSS spec, the value of normal value is defined as:
Tells user agents to set the used value to a "reasonable" value based
on the font of the element. The value has the same meaning as
. We recommend a used value for 'normal' between 1.0 to 1.2.
From some online resource like this article or this page, you can see that the real value of normal value depends on many arguments like font size, font family, OS, user agent, ... Therefore, it is recommended that you should use some css normalize stylesheet to set the value of line-height correctly and cross-browser.
About your case
The quick fix here is setting the line-height inside the .xcode class to be 16px (which is the height of the of your background image).

Highlight element in navigation

Hell I'm making a navigation where one specific Element should be highlighted from other elements of the navigation.
I created a css class highlighted where i increase font the size. But then the text is not on the same hight as the smaller texts.
#navigation .bar a.highlight{
font-size: large;
}
It looks like this:
Sorry I'm new to css and html and I guess it's an easy solution.
Please take a look at my code
http://jsfiddle.net/FcbJv/
First, I would suggest not using keywords like large in your CSS for font-size, instead use px or em units (better for maintainability, and browsers can interpret these keywords differently).
You can achieve the effect you want by decreasing the line-height on your .highlight menu item in proportion to the increase in font-size. This maintains the vertical rythm of your menu items.
jsfiddle
CSS
/*EM (personal preference) */
#navigation .bar a.highlight{
font-size: 1.4em; /* we increase size by .4ems */
line-height:.6em; /* so we reduce line-height by .4 ems */
}
/* PX */
#navigation .bar a.highlight{
font-size: 18px; /* just guessing here, make sure to set this to the actual desired height */
line-height:10px;
}
You need to add a line-height.
Try this:
#navigation .bar a.highlight {
font-size: large;
line-height: 12px; /*Same as your font-size for normal items*/
}
Because your font size for the page is 12px, a line-height of 12px will vertically center it. If you change the font-size, be sure to change the line-height.
Check this JSFiddle.
Aligning things vertically in CSS is one of the things that can make you go crazy.
Try improving the line-height of the list items:
line-height: 16px;
Also, try to be specific with the font-size you want instead of using large because it can vary from browser to browser.

How can I get the website menu bar to stay in one line?

I am building a site, and hanged on a problem.
I positioned the menu bar perfectly, but for some reason on bigger display resolutions or android devices the Contact Us menu item tends to jump to a new line.
The link of the web page is http://uk.delux.lv Just try to zoom it and see what happens.
This is the css for menu:
#topmenu_wrap {
margin:auto;
overflow: auto;
background: #fff;
}
#topmenu {
background-color: #fff;
width:966px;
margin:auto;
padding-left: 0px;
font-family: 'Droid Sans', sans-serif; font-weight: 400;
font-size: 13px;
color: #969696;
}
What I suggest is to set the padding of the a tags in the ul>li to padding: 16px 15px. Set the total width of the topnav>ul with class menu to width: 966px.
You are not going to be able to control the width of the text on the topnav unless you make them images. That will allow the text to remain the same no matter how far the user zooms or the size they set the text in their browser.
I thought I found somewhere a while ago a way to set the text as static so when someone zoomed nothing happened but I can't find it.
As far as making it expand I wouldn't do that. You aren't going to be able to control every persons browser and the way it looks. Where I work we only check a normal view in the 5 major browsers and if they change something on their end then oh well.

CSS: Strike-through not centered through the text

We are using strike-through to actually show oldprice vs new price for a product.
If you open this link, at the bottom of the page, we have a product on sale.
http://www.gkelite.com/Gymnastics-Shopby-GiftoftheWeek
The strike-through for the old price is not centered vertically for the text.
Can any one help out as to why it's happening?
A strike-through is traditionally some percentage (70% to 90%) of the x-height (or the height of a lower case 'x'). If the line were at the 50% of cap-height, it may be possible the strike-through would be above or at the top of any lowercase letter in the set. A strike-through is supposed to put a line through all letters in the text, which is why is gauged from the x-height.
Whether or not browsers actually use the x-height for their strikethrough calculation, this tradition is why is why strike-throughs are displayed short of the 50% of cap height.
See the following illustration for some examples of the terms:
I found a solution for it utilizing psuedo elements http://jsfiddle.net/urjhN/
.strike-center {
position: relative;
white-space: nowrap; /* would center line-through in the middle of the wrapped lines */
}
.strike-center:after {
border-top: 1px solid #000;
position: absolute;
content: "";
right: 0;
top:50%;
left: 0;
}
However this technique fails if the text is wrapped between lines, the line would be centered among those lines.
It seems to work among all major browsers; for IE7 (and prior) you could just fallback to the classic line-through using conditional comments.
There is no way to control the offset/placement of a strike-through, but, there is a way for controlling this using for text-decoration: underline using the below combination:
span {
background: lightyellow;
text-decoration: underline;
text-underline-offset: -40%; /* <-- this */
text-decoration-skip-ink: none;
}
output { display:inline-block; width:50px; }
<output>-40%</output>
<input type='range' min='-100' max='100' value='-40' oninput='this.nextElementSibling.style.textUnderlineOffset=this.value+"%"; this.previousElementSibling.innerHTML=this.value+"%"'/>
<span>Text with strike-through</span>
👉 Here's a Codepen of mine with an alternative strike-through approach:
https://codepen.io/vsync/pen/KKQoVRZ

Resources