The problem isn't in your CSS, it's the new line after you close the
</code> part. If you remove it, the space will disappear.
This happens because text in a pre element is displayed in a fixed-width font, and it preserves both spaces and line breaks.
<html>
<head>
<!-- CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.9.0/themes/prism-coy.css" />
<!-- JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.9.0/prism.min.js"></script>
<style>
pre{margin:0px;border:2px solid red;}
pre::before,pre::after,code::before,code::after{height:0!important;}
pre[class*="language-"]:before, pre[class*="language-"]:after{height:0px!important;display:inline-block;}
code{border-bottom:2px solid green;}
</style>
</head>
<body>
<pre class="brush: html line-numbers language-html">
<code ="language-html"><html>
<head></head>
<body>
Hi, my name is Peter Martin.
This is my first program in HTML.
</body>
</html></code></pre>
</body>
</html>
Answer from Jonas Grumann on Stack OverflowCan I remove all spaces, including between words?
Does this tool remove tabs and newlines as well?
When should I use this whitespace cleaner?
The problem isn't in your CSS, it's the new line after you close the
</code> part. If you remove it, the space will disappear.
This happens because text in a pre element is displayed in a fixed-width font, and it preserves both spaces and line breaks.
<html>
<head>
<!-- CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.9.0/themes/prism-coy.css" />
<!-- JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.9.0/prism.min.js"></script>
<style>
pre{margin:0px;border:2px solid red;}
pre::before,pre::after,code::before,code::after{height:0!important;}
pre[class*="language-"]:before, pre[class*="language-"]:after{height:0px!important;display:inline-block;}
code{border-bottom:2px solid green;}
</style>
</head>
<body>
<pre class="brush: html line-numbers language-html">
<code ="language-html"><html>
<head></head>
<body>
Hi, my name is Peter Martin.
This is my first program in HTML.
</body>
</html></code></pre>
</body>
</html>
The space is caused by the </code> & </pre> tags if you remove the space from tags like this it should work </code></pre>.
Your code is reading the html as it is. Html does not read spaces however in your code it is.
You need to reset the natural padding and margin of the body and ol. Set:
body{
margin: 0;
padding: 0;
}
.header-left ol{
width: auto;
float: left;
display: block;
background-color: #6899D3;
margin: 0; //RESET DEFAULT
padding: 0; // RESET DEFAULT
}
Add padding-left:0; to your .header-left ol rules.
.header-left ol {
width: auto;
float: left;
display: block;
background-color: #6899D3;
padding-left:0;
}
jsFiddle example
element.text().replace(/\s+/g, " ");
This uses a regular expression (/.../) to search for one or more (+) whitespace characters (\s) throughout the element's text (g, the global modifier, which finds all matches rather than stopping after the first match) and replace each with one space (" ").
For the string
" this is my string "
You probably want to make the excessive spaces single spaces, but remove the leading and trailing spaces entirely. For that, add another .replace
s.replace(/\s+/g, " ").replace(/^\s|\s$/g, "");
For
"this is my string"
Update
s.replace(/\s+/g, " ").trim()
Thanks, @Pier-Luc Gendreau
You must remove the margin on body:
body {
padding:0;
margin:0;
}
You can also remove padding and margin on html and body
html, body {
padding:0;
margin:0;
}
See it on jsfiddle
But I would not advise to use * (the universal selector)
* {
margin: 0px;
padding: 0px;
}
This would remove padding and margins on all elements.
The good method is to always use at the begining of the file (I forgot to metion this):
*{
margin: 0px;
padding: 0px;
}
This two line's at the begining of main CSS file fix many problem's that you can encounter. Hope it'll help you.