将姓名和职位以两行显示在网页上的最佳方式是使用HTML和CSS。

huangapple go评论85阅读模式
英文:

What is the best way to put name and job title on two separate lines on a webpage using HTML, CSS?

问题

以下是已翻译的内容:

  1. .landing {
  2. height: 100vh;
  3. width: 100vw;
  4. display: flex;
  5. align-items: center;
  6. justify-content: center;
  7. }
  1. <div class="landing">
  2. <div class="landing1">HasanMirza</div>
  3. <div class="landing2">Web De<span class="v">v</span>eloper</div>
  4. </div>
英文:

What is the best way to put my name and job title centered vertically and horizontally on a webpage for my own website. I want to have my name with Web Developer underneath it.

I used this method:

  1. .landing{
  2. height: 100vh;
  3. width: 100vw;
  4. display: flex;
  5. align-items: center;
  6. justify-content: center;
  7. }

This works but doesnt take into account a position:fixed border with height=60px into account (it doesn't come out totally vertically centered).

Is there another way to centred these items regardless of additional elements on the page? (margin: auto also creates the same problem as above).

In addition, how should the html layout look, currently:

  1. &lt;div class=&quot;landing&quot;&gt;
  2. &lt;div class=&quot;landing1&quot;&gt;HasanMirza&lt;/div&gt;
  3. &lt;div class=&quot;landing2&quot;&gt;Web De&lt;span class=&quot;v&quot;&gt;v&lt;/span&gt;eloper&lt;/div&gt;
  4. &lt;/div&gt;

(the 'v' is rotated to look like an angle bracket, just an effect I am trying to achieve).

答案1

得分: 2

如果您想在视口中无论其他元素如何都将某物定位在固定位置,请使用 position: fixed。Grid 允许您轻松地将项目放置在中心位置。请参阅下面的代码:

  • 有关定位的信息请参考 css tricks
  • 如何使用网格进行居中对齐请参考 W3docs.com
  1. body {
  2. margin: 0; /* 如果不将其设置为零,则项目将具有 8px 的偏移 */
  3. }
  4. .landing {
  5. position: fixed;
  6. height: 100vh;
  7. width: 100vw;
  8. display: grid;
  9. place-content: center;
  10. }
  1. <div class="landing">
  2. <div class="landing1">HasanMirza</div>
  3. <div class="landing2">Web Developer</div>
  4. </div>
英文:

If you want to position anything in your viewport in a fixed position irrespective of any other element then use position: fixed. Grid allows you to place items in the center really easily. See code below:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

  1. body {
  2. margin:0; /* the items will have an 8px offset if this isn&#39;t set to zero */
  3. }
  4. .landing {
  5. position: fixed;
  6. height: 100vh;
  7. width: 100vw;
  8. display: grid;
  9. place-content: center;
  10. }

<!-- language: lang-html -->

  1. &lt;div class=&quot;landing&quot;&gt;
  2. &lt;div class=&quot;landing1&quot;&gt;HasanMirza&lt;/div&gt;
  3. &lt;div class=&quot;landing2&quot;&gt;Web De&lt;span class=&quot;v&quot;&gt;v&lt;/span&gt;eloper&lt;/div&gt;
  4. &lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年6月8日 15:34:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76429583.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定