2

EDIT: I think this boils down to browsers rendering fonts differently. I reduced and reduced my code to try to figure out where the problem was, and I ended up just having a plain webpage with only <h1>Ladesoft</h1> in the body and nothing else, with nothing in my CSS file other than a global choice of font, and I noticed that Chrome and Firefox rendered the heading quite differently. Searching around online, I found this query, and basically it looks like there's unlikely to be any way of achieving my goal. So I'm going to have to resort to creating an image I think. I'll leave this post unanswered for now in case anyone comes up with a solution.


I'm having a problem where the header (h1) on my website looks completely different depending on which browser I use. I am doing something a little unusual with it, but I can't figure out how to get things to look the same. My website is http://www.ladesoft.com

I want to have the title of my site written with just the one line:

<h1>Ladesoft</h1>

I am using CSS to manipulate the text to look like this:

enter image description here

My CSS file can be found here: https://github.com/andylatham82/Website/blob/master/styles.css

Edit: Adding CSS code. Apologies for including it all, but I just don't know where the problem is.

html
{
    height: 100%;
    width: 1000px;
    margin-left: auto;
    margin-right: auto;
}
body
{
    height: 100%;
    background-color: rgb(43, 43, 43);
    font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;
    margin-left: auto;
    margin-right: auto;
}

h1
{
    color: orange;
    font-size: 600%;
    font-weight: 100;
    margin-top: 20px;
    margin-bottom: -60px;
    margin-left: -60px;
    transform:scale(0.9,1);
    text-decoration: underline;
    text-decoration-color: cornflowerblue;
    overflow: hidden;
    position:relative;
    z-index: -1;
}

h1::first-letter
{
    color: cornflowerblue;
    font-size: 300%;
    margin-right: -20px;
    float: left;
    margin-top: -125px;
    margin-right: -106px;
    position: relative;
}

h2
{
    color: cornflowerblue;
    text-align: center;
    font-weight: 50;
    margin-top: 20px;
    margin-bottom: 20px;
}

p
{
    color: rgb(228, 226, 179);
}

table
{
    margin-left: auto;
    margin-right: auto;
    padding: 0;
    border-spacing:0;
}

td
{
    color: rgb(228, 226, 179);
    width: auto;
    text-align: left;
    border-spacing: 0;
    padding: 2px;
    padding-left: 10px;
    padding-right: 10px;
}

a
{
    color: cornflowerblue;
}

ul
{
    list-style-type: none;
    margin: 0;
    overflow: hidden;
    background-color: orange;
}

li
{
    float: left;
}

li a
{
    display: block;
    color: white;
    text-align: center;
    padding: 16px;
    text-decoration: none;
}

li a:hover
{
    background-color: red;
}

hr
{
    margin-top: 0px;
    border-color: cornflowerblue;
    align: left;
    size: 4;
    border-style: solid;
}

iframe
{
    height: 650px;
    width: 405px;
    border: none;
    overflow: hidden;
    justify-content: center;
}

.gamelink
{
    margin-left: 20px;
}

.date
{
    color: orange;
}

.wrapper {
  margin: 0px;
  padding: 0px;
  height: 128px;
  display: flex;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-box;
  display: -webkit-flex;
  padding-bottom: 400px;
  justify-content: center;
}

canvas {
  border: 0px;
  width: 512px;
  height: 512px;
  background: black;
  image-rendering: optimizeSpeed;
  image-rendering: -moz-crisp-edges;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: optimize-contrast;
  image-rendering: pixelated;
  -ms-interpolation-mode: nearest-neighbor;
}

#centered
{
    text-align: center;
    margin-left: auto;
    margin-right: auto;
}

One of my HTML files can be found here: https://github.com/andylatham82/Website/blob/master/pages/games.html

Edit: Adding HTML code:

<!DOCTYPE html>
<html lang="en-GB">
    <head>
    <meta charset="utf-8"/>
    <meta name="keywords" content="Game, Video, Videogame, C++, C#, Monogame, Pico-8, Pico8, Arduboy, Lua, CSS, Ladesoft, Andy, Latham">
    <meta name="description" content="Video games made by Andy Latham">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="author" content="Andy Latham">
    <link rel="stylesheet" href="../styles.css">
    <TITLE>Ladesoft: Games</TITLE>
    </head>
    <body>
    <h1>Ladesoft</h1>
    <ul>
        <li><a href="games.html">Games</a></li>
        <li><a href="experiments.html">Software & Experiments</a></li>
        <li><a href="about.html">About</a></li>
    </ul>
    
    <hr style="margin-left: 55px; width: 48px">
    <h2>Games</h2>
    <p>I love making games. Here's a selection of my output. The purpose of any game is to be played, so I'd love to <a href=about.html>hear</a> from anyone who plays any of these!</p>
    <br>
    <table>
        <tr>
        <td>
            <a href="games/textadventure.html"><img src="../images/thumbnails/textadventurethumb.png" title="Text Adventure" alt="Text Adventure" style="float:left;"></a></td>
        <td><span class="date">[2020]</span> A  work-in-progress text adventure.</td>
        </tr>

        <tr>
        <td>
            <a href="games/pointandclickadventure.html"><img src="../images/thumbnails/pointandclickthumb.png" title="Point-and-Click Adventure" alt="Point-and-Click Adventure" style="float:left;"></a></td>
        <td><span class="date">[2020]</span> A work-in-progress 'point-and-click' adventure.</td>
        </tr>

        <tr>
        <td>
            <a href="games/babydump.html"><img src="../images/thumbnails/babydumpthumb.png" title="Text Adventure" alt="Text Adventure" style="float:left;"></a></td>
        <td><span class="date">[September 2020]</span> Earn money by having (and abandoning) babies.</td>
        </tr>

        <tr>
        <td>
            <a href="games/blackdeath.html"><img src="../images/thumbnails/blackdeaththumb.png" title="Black Death" alt="Black Death" style="float:left;"></a></td>
        <td><span class="date">[August 2019]</span> Play as bubonic plague and try to wipe out the villagers.</td>
        </tr>

        <tr>
        <td>
            <a href="games/thecrawl.html"><img src="../images/thumbnails/thecrawlthumb.png" title="The Crawl" alt="The Crawl" style="float:left;"></a></td>
        <td><span class="date">[March 2019]</span> A mini dungeon crawling platform game.</td>
        </tr>
    </table>
    <br>
    <br>
    <p id="centered">
        <a href="http://www.ladesoft.com">-Ladesoft-</a>
    </p>
    <br>
    </body>
</html>

With Chrome on Linux, things look correct:

enter image description here

but with Firefox on Linux, this is what I see:

enter image description here

With Chrome on Windows, it's this:

enter image description here

and with Firefox on Windows, it's this:

enter image description here

And just for good measure, with Edge on Windows, it's this:

enter image description here

Would anyone be kind enough to help me work out what's going on? I understand that different browsers render things differently, but is there any way of achieving my goal of having this logo look the same everywhere without resorting to using an image?

Andy Latham
  • 377
  • 3
  • 10
  • 6
    Please read [Something on my web site doesn't work. Can I just paste a link to it?](http://meta.stackoverflow.com/questions/125997/something-on-my-web-site-doesnt-work-can-i-just-paste-a-link-to-it). Questions that depend on external resources to be understood become useless when the external resource goes away or is fixed. Create a [MCVE] and put it in **the question itself** instead. Stackoverflow does support [inline live demos](https://stackoverflow.blog/2014/09/16/introducing-runnable-javascript-css-and-html-code-snippets/) – Quentin Dec 19 '20 at 15:47
  • Sorry, I never thought of that. I have added my code now :) – Andy Latham Dec 19 '20 at 15:58
  • Have you tried normalize CSS? Even better, for things like this, make the logo in something like photoshop and add is via element on the page, the least hassle. – ptts Dec 19 '20 at 16:32
  • Yeah I've tried normalising but it didn't work. I have resorted to using an image. – Andy Latham Dec 20 '20 at 17:51
  • 1
    You have given a wide list of fonts and it looks as though different systems have different fonts available and are choosing the first one they hit that they have. Which font do you actually want and have you tried making sure that is the one used by loading it (font-face)? Otherwise, whether or not we can get everything else to be the same the logo is going to look different on different systems. – A Haworth Dec 20 '20 at 18:01
  • 1
    could you try with bottom: -60px on h1 instead of margin-bottom? this should fix the menu position. – Lety Dec 21 '20 at 13:00
  • FYI 99.999999% of the time now Edge on Windows will be exactly the same as Chrome on Windows since Edge uses the same rendering engine as Chrome. Same goes for Opera and Brave (and probably some others). – TylerH Dec 21 '20 at 16:56

1 Answers1

1

There are a couple of problems in the approach which lead to malignment and different styles in the logo - variable fonts and reliance on underline.

The most obvious problem is that a selection of fonts is given, the first being Menlo which I believe may be present on some systems but is not present for example on my Windows 10 system. This means that the font style is different on different systems and that explains the different look of the orange characters shown in the question. Different fonts also have different spacing such as leading so you cannot compensate for this in general using px units.

To get exactly the same look fontwise you'll need to link to the font you want. I have used a google font Deja Vu mono as some of the fonts in the question are paid for and/or not available.

The more subtle problem is one of positioning of the lines and the first character. If you look at the position of underline on Firefox compared to Chrome it is not exactly the same in relation to the baseline of the characters. Whatever we do in CSS we cannot compensate for this without knowing exactly how each browser renders underline.

We avoid underline therefore and turn to borders and use borders to draw the 'L' as positioning of first character may also not be consistent across browsers. This approach worked reasonably well, except on some magnifications on some screens there was a pixel difference in the rendering.

So, the approach here uses linear-gradients to set backgrounds on the before and after pseudo elements. To get seemingly pixel-perfect fit we make the pseudo element colors overlap rather than abut.

Obviously you can tweak the sizes to suit, but all are in ems so things should be responsive.

Tested on Windows10 with Chrome, Edge, Firefox, IE11 and on iPadIOS 14 Safari and results are reasonably consistent. It may however be better to ditch using h1 as browsers do add their own styling and instead use div with a class. Only the h1 and its pseudo elements have been changed in this CSS, and the text of the logo has been transferred from the main HTML to pseudo elements, with the L rendered not as a character but as linear-gradients as browser rendering of first-letter differs.

<!DOCTYPE html>
<html lang="en-GB">
    <head>
    <meta charset="utf-8"/>
    <meta name="keywords" content="Game, Video, Videogame, C++, C#, Monogame, Pico-8, Pico8, Arduboy, Lua, CSS, Ladesoft, Andy, Latham">
    <meta name="description" content="Video games made by Andy Latham">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="author" content="Andy Latham">
    <TITLE>Ladesoft: Games</TITLE>
    <link rel="stylesheet" href="../styles.css">
    <link rel="preconnect" href="https://fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css2?family=Space+Mono&display=swap" rel="stylesheet">
    <style>

html
{
    height: 100%;
    width: 1000px;
    margin-left: auto;
    margin-right: auto;
}
body
{
    height: 100%;
    background-color: rgb(43, 43, 43);
    font-family: 'Space Mono', monospace;
    margin-left: auto;
    margin-right: auto;
}

h1 {
  border-style: solid;
  border-width: 0 0 0 0.2em;
  border-color: transparent transparent transparent transparent;
  height: 1.5em;
  position: relative;
  padding: 0 0 0.05em 0;
  margin: 0 0 0.1em 0;
  display: inline-block;
  width: auto;
  transform: scale(0.9, 1);
}
h1:before {
  content: '';
  position: absolute;
  background-image: linear-gradient(to top, cornflowerblue 0em, cornflowerblue 0.11em, transparent 0.11em, transparent 100%), linear-gradient(to right, cornflowerblue 0%, cornflowerblue 0.21em, transparent 0.21em, transparent 100%);
  height: 1em;
  width: 1.1em;
  top: 0.4em;
  margin-left: -0.2em;
  background-color: transparent;
  display: inline-block;
  z-index:2;
}
h1:after {
  color: orange;
  content: 'adesoft';
  position: relative;
  font-weight: 100;
  padding-left: 0.1em;
  background-image: linear-gradient(to top, transparent 0em, transparent 0.15em, cornflowerblue 0.15em, cornflowerblue 0.25em, transparent 0.25em, transparent 100%);
}

h2
{
    color: cornflowerblue;
    text-align: center;
    font-weight: 50;
    margin-top: 20px;
    margin-bottom: 20px;
}

p
{
    color: rgb(228, 226, 179);
}

table
{
    margin-left: auto;
    margin-right: auto;
    padding: 0;
    border-spacing:0;
}

td
{
    color: rgb(228, 226, 179);
    width: auto;
    text-align: left;
    border-spacing: 0;
    padding: 2px;
    padding-left: 10px;
    padding-right: 10px;
}

a
{
    color: cornflowerblue;
}

ul
{
    list-style-type: none;
    margin: 0;
    overflow: hidden;
    background-color: orange;
}

li
{
    float: left;
}

li a
{
    display: block;
    color: white;
    text-align: center;
    padding: 16px;
    text-decoration: none;
}

li a:hover
{
    background-color: red;
}

hr
{
    margin-top: 0px;
    border-color: cornflowerblue;
    align: left;
    size: 4;
    border-style: solid;
}

iframe
{
    height: 650px;
    width: 405px;
    border: none;
    overflow: hidden;
    justify-content: center;
}

.gamelink
{
    margin-left: 20px;
}

.date
{
    color: orange;
}

.wrapper {
  margin: 0px;
  padding: 0px;
  height: 128px;
  display: flex;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-box;
  display: -webkit-flex;
  padding-bottom: 400px;
  justify-content: center;
}

canvas {
  border: 0px;
  width: 512px;
  height: 512px;
  background: black;
  image-rendering: optimizeSpeed;
  image-rendering: -moz-crisp-edges;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: optimize-contrast;
  image-rendering: pixelated;
  -ms-interpolation-mode: nearest-neighbor;
}

#centered
{
    text-align: center;
    margin-left: auto;
    margin-right: auto;
}
</style>
</head>

    <body>
    <h1></h1>
    <ul>
        <li><a href="games.html">Games</a></li>
        <li><a href="experiments.html">Software & Experiments</a></li>
        <li><a href="about.html">About</a></li>
    </ul>
    
    <hr style="margin-left: 55px; width: 48px">
    <h2>Games</h2>
    <p>I love making games. Here's a selection of my output. The purpose of any game is to be played, so I'd love to <a href=about.html>hear</a> from anyone who plays any of these!</p>
    <br>
    <table>
        <tr>
        <td>
            <a href="games/textadventure.html"><img src="../images/thumbnails/textadventurethumb.png" title="Text Adventure" alt="Text Adventure" style="float:left;"></a></td>
        <td><span class="date">[2020]</span> A  work-in-progress text adventure.</td>
        </tr>

        <tr>
        <td>
            <a href="games/pointandclickadventure.html"><img src="../images/thumbnails/pointandclickthumb.png" title="Point-and-Click Adventure" alt="Point-and-Click Adventure" style="float:left;"></a></td>
        <td><span class="date">[2020]</span> A work-in-progress 'point-and-click' adventure.</td>
        </tr>

        <tr>
        <td>
            <a href="games/babydump.html"><img src="../images/thumbnails/babydumpthumb.png" title="Text Adventure" alt="Text Adventure" style="float:left;"></a></td>
        <td><span class="date">[September 2020]</span> Earn money by having (and abandoning) babies.</td>
        </tr>

        <tr>
        <td>
            <a href="games/blackdeath.html"><img src="../images/thumbnails/blackdeaththumb.png" title="Black Death" alt="Black Death" style="float:left;"></a></td>
        <td><span class="date">[August 2019]</span> Play as bubonic plague and try to wipe out the villagers.</td>
        </tr>

        <tr>
        <td>
            <a href="games/thecrawl.html"><img src="../images/thumbnails/thecrawlthumb.png" title="The Crawl" alt="The Crawl" style="float:left;"></a></td>
        <td><span class="date">[March 2019]</span> A mini dungeon crawling platform game.</td>
        </tr>
    </table>
    <br>
    <br>
    <p id="centered">
        <a href="http://www.ladesoft.com">-Ladesoft-</a>
    </p>
    <br>
    </body>
</html>
A Haworth
  • 30,908
  • 4
  • 11
  • 14
  • Wow that's impressive! My only question is whether it's good practice from the point of view of search engines. I am new to web development, but my understanding is that it's good to use things like headings in the way that they were designed to help search engines. In your solution, the actual h1 header doesn't have the title of the website. Of course neither does the easy option of using an image. Assuming that there is no way of using the website's title in the h1 header, while having it end up looking how I want it to look, is your solution any better or worse than just using an image? – Andy Latham Dec 21 '20 at 22:50
  • Interesting! I know very little about search engines, except I believe the days of being ranked on your heading texts are long since gone. Actually I was going to question whether using a heading element for a logo was a good idea - partly because browsers add bits of styling and partly because I wasn't sure it was really a heading in the text sense - it's a logo which just happens to be drawn in CSS to make it easily responsive. I'd have chosen a div and class="logo". instead of h1. If you go for an image instead I guess you'll make it svg? It was fun to do the CSS! – A Haworth Dec 21 '20 at 23:14