html - 将文本锚定到页面中间

标签 html css

我在网上搜索了这个问题的答案,我知道这样做是可能的,但我就是无法弄清楚那里有什么。

背景:我正在创建一个常见问题部分,人们可以在其中单击问题并转到同一页面上的答案。我还将问题分为几类。

虽然我已经能够通过基本的 href 概念实现这一点,但我希望问题的答案显示在页面中间,而不是在用户点击页面顶部边缘的正下方单击锚定的问题。

希望我能够大致描绘出我的意思。现在,我将向您展示我在语法方面的知识。

我确实相信有多种方法可以使用样式、类或其他属性创建代码,但我没有很强的编码背景 :(。因此,我选择了自己的方式能够从 W3School 学习东西 XD。

如果有人能帮助我,我将不胜感激,因为它会使常见问题解答部分更易于使用。

这里的图片也更好地解释了这个场景。

Question Section Answer Section

         <p> 
         <strong>Color Questions</strong>
         <br/>
         <a href="#A">What is the door's color?</a>
         <br />
         <a href="#B">What is the window's color?</a>
         </p>
         <p>
         <strong>Shape Questions</strong>
         <br/>
         <a href="#C">What is the shape of a ball?</a>
         <br/>
         <a href="#D">What is the shape of a box?</a>
         </p>
         <h3>Answers</h3>
         <p>
         <strong>Color Questions</strong>
         </p>
         <p>
         <strong>
         <a id="A"></a>What is the door's color?
         </strong>
         <br />The door's color is blue. 
         </p>
         <p>
         <strong>
         <a id="B"></a>What is the window's color?</strong>
         <br />The windows's color is red. 
         </p>
         <p>
         <strong>
         Shape Questions</strong>
         </p>
         <p>
         <strong>
         <a id="C"></a>What is the shape of a ball?
         </strong>
         <br />A ball has the shape of a sphere.  
         </p>
         <p>
         <strong>
         <a id="D"></a>What is the shape of a box?
         </strong>
         <br />A box has the shape of a cube. 
         </p>

最佳答案

如果你想把你的文字放在中间,你可以使用<center>并将您的文本放入此标签中,但它现在已过时,有更好的方法可以做到这一点。您可以使用 marginpadding把你的文字放在很好的位置你也可以使用position .检查w3schools.com了解更多详情。这很有帮助。

关于html - 将文本锚定到页面中间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47658212/

相关文章:

html - 网站上线时图片不会显示为背景

javascript - 选择占位符选项时选择的 Jquery 切换类

jquery width() 不适用于文本

html - CSS 响应式,等边三 Angular 形,适用于 Firefox

html - 将 img 的上边距设置为依赖于另一个 div 的高度

javascript - 如何使选定的触发 div 保持可见性,直到其他 div 悬停在上面?

html - 仅使用 CSS/HTML 平滑滚动到页面顶部?

php - 数据库帮助 PHP 初学者

jquery - 调整菜单大小时将菜单项移动到溢出 div 中?

css - 使用媒体查询从纵向切换到横向时出现问题