Text is breaking using absolute positioning

后端 未结 4 729
庸人自扰
庸人自扰 2021-02-13 23:04

I have a small challenge that I haven\'t found any solution on Stack Overflow.

That\'s what I got:

4条回答
  •  一个人的身影
    2021-02-13 23:39

    Here, I have made a few minor CSS changes for you.

    /* Cosmetics */
    * { box-sizing: border-box; }
    body { margin: 50px; }
    p { margin: 0; }
    
    
    /* True Code */
    .content {
      border: 3px double black;
      padding-top: 30px;
      position: relative;
      width: 350px;
    }
    
    .content p { margin: 20px; }
    
    .title {
      background: black;
      border-radius: 5px;
      color: white;
      left: 50%;
      padding: 10px;
      position: absolute;
      text-align: center;
      transform: translate(-50%, -50%);
      top: 0;
      white-space: nowrap;
      margin-top: 0px;
    }
    

提交回复
热议问题