gpt4 book ai didi

html -
 中同一行中未对齐的 

转载 作者:太空宇宙 更新时间:2023-11-03 21:05:04 24 4
gpt4 key购买 nike

我的博客遇到了一些 CSS 问题,该博客基于 Cayman 主题。

我遇到的问题是,在使用 Jekyll 启用行号后,代码块严重错位,如下图所示。

before

我的目标是让它看起来像这样:

after

我在 Developer Console 中注意到,由于额外的代码块,代码块呈现得很糟糕:

show

这是生成第一张图片的最少代码。

.main-content {
word-wrap: break-word !important;
overflow-wrap: break-word !important;
background-color: rgba(255, 255, 255, 0.95);
max-width: 64rem;
padding: 3rem 6rem;
font-size: 1.1rem;
margin: 0 auto 3rem;
border-radius: 4rem;
}

.main-content :first-child {
margin-top: 0;
}

.main-content code {
padding: 2px 4px;
font-family: monospace;
font-size: 0.95em;
color: #567482;
background-color: #f3f6fa;
border-radius: 0.3rem;
}

.main-content pre:not(.highlight) {
max-height: 30rem;
margin-top: 0;
margin-bottom: 1rem;
font: 0.95em monospace;
color: #567482;
word-wrap: normal;
background-color: #f3f6fa;
border: solid 1px #dcf0e6;
border-radius: 0.5rem;
padding: 0.8rem;
overflow: auto;
line-height: 1.45;
-webkit-overflow-scrolling: touch;
}

.main-content pre:not(.highlight) > code {
padding: 0;
margin: 0;
font-size: inherit;
color: #567482;
word-break: normal;
white-space: pre;
background: transparent;
border: 0;
}

.main-content .highlight {
background-color: #f3f3f3;
margin-bottom: 1rem;
}

.main-content .highlight pre:not(.highlight) {
margin-bottom: 0;
word-break: normal;
padding: 0.8rem;
overflow: auto;
font-size: 0.95em;
line-height: 1.45;
border-radius: 0.5rem;
-webkit-overflow-scrolling: touch;
}

.main-content pre code {
display: inline;
max-width: initial;
padding: 0;
margin: 0;
overflow: initial;
line-height: inherit;
word-wrap: normal;
background-color: transparent;
border: 0;
}

.main-content table {
border-spacing: 0;
}

.main-content .highlight table th, .main-content .highlight table td {
padding: 0;
border: none;
}

* {
box-sizing: border-box;
}

body {
padding: 0;
margin: 0;
font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 16px;
line-height: 1.5;
color: #606c71;
background-color: #15CC57;
background-image: /*url("https://ibug.github.io/image/bg.jpg"), */ linear-gradient(120deg, #155799, #15CC57);
background-repeat: no-repeat;
background-size: cover;
background-attachment: fixed;
background-position: center;
}
<!DOCTYPE html>
<html lang="en-US"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Title title title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#159A34">
<link rel="stylesheet" href="./style.css">
</head>
<body>
<section class="main-content blog-post">
<div class="language-vb highlighter-rouge">
<div class="highlight"><pre class="highlight"><code>
<table class="rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1
2
3
4
</pre>
</td>
<td class="rouge-code">
<pre><span class="n">asdfghjkl</span>
<span class="n">asdfghjkl</span>
<span class="n">asdfghjkl</span>
<span class="n">asdfghjkl</span>
</pre>
</td>
</tr>
</tbody>
</table>
</code></pre>
</div>
</div>
</section>
</body></html>

特殊要求:由于HTML是Jekyll生成的,我不方便修改。我需要纯 CSS 调整。

注意:由于本人对CSS知识不多,以上文件是从真实页面中减去代码生成的。我试图切断所有不必要的东西,但我不确定它是否是最低限度的。

最佳答案

现有答案提供了很好的提示,我很惊讶地发现最佳答案如此简单:

pre.highlight {
white-space: normal;
}

<pre class="highlight"> 中的空格不再“堆叠”并创建大量空白区域。

.main-content {
word-wrap: break-word !important;
overflow-wrap: break-word !important;
background-color: rgba(255, 255, 255, 0.95);
max-width: 64rem;
padding: 3rem 6rem;
font-size: 1.1rem;
margin: 0 auto 3rem;
border-radius: 4rem;
}

.main-content :first-child {
margin-top: 0;
}

.main-content code {
padding: 2px 4px;
font-family: monospace;
font-size: 0.95em;
color: #567482;
background-color: #f3f6fa;
border-radius: 0.3rem;
}

.main-content pre:not(.highlight) {
max-height: 30rem;
margin-top: 0;
margin-bottom: 1rem;
font: 0.95em monospace;
color: #567482;
word-wrap: normal;
background-color: #f3f6fa;
border: solid 1px #dcf0e6;
border-radius: 0.5rem;
padding: 0.8rem;
overflow: auto;
line-height: 1.45;
-webkit-overflow-scrolling: touch;
}

.main-content pre:not(.highlight) > code {
padding: 0;
margin: 0;
font-size: inherit;
color: #567482;
word-break: normal;
white-space: pre;
background: transparent;
border: 0;
}

.main-content .highlight {
background-color: #f3f3f3;
margin-bottom: 1rem;
}

.main-content .highlight pre:not(.highlight) {
margin-bottom: 0;
word-break: normal;
padding: 0.8rem;
overflow: auto;
font-size: 0.95em;
line-height: 1.45;
border-radius: 0.5rem;
-webkit-overflow-scrolling: touch;
}

.main-content pre code {
display: inline;
max-width: initial;
padding: 0;
margin: 0;
overflow: initial;
line-height: inherit;
word-wrap: normal;
background-color: transparent;
border: 0;
}

.main-content table {
border-spacing: 0;
}

.main-content .highlight table th, .main-content .highlight table td {
padding: 0;
border: none;
}

* {
box-sizing: border-box;
}

body {
padding: 0;
margin: 0;
font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 16px;
line-height: 1.5;
color: #606c71;
background-color: #15CC57;
background-image: /*url("https://ibug.github.io/image/bg.jpg"), */ linear-gradient(120deg, #155799, #15CC57);
background-repeat: no-repeat;
background-size: cover;
background-attachment: fixed;
background-position: center;
}

pre.highlight {
white-space: normal;
}
<!DOCTYPE html>
<html lang="en-US"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Title title title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#159A34">
<link rel="stylesheet" href="./style.css">
</head>
<body>
<section class="main-content blog-post">
<div class="language-vb highlighter-rouge">
<div class="highlight"><pre class="highlight"><code>
<table class="rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1
2
3
4
</pre>
</td>
<td class="rouge-code">
<pre><span class="n">asdfghjkl</span>
<span class="n">asdfghjkl</span>
<span class="n">asdfghjkl</span>
<span class="n">asdfghjkl</span>
</pre>
</td>
</tr>
</tbody>
</table>
</code></pre>
</div>
</div>
</section>
</body></html>

关于html - <pre><code> 中同一行中未对齐的 <td>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54604957/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com