如何让h1超过边界

时间:2017-01-07 10:15:09

标签: html css psd

我将自由PSD编码为HTML,一切都很好,除了一件事 - 我不知道如何得到这样的东西:

Slice from PSD

如何让h1超越边界,以便覆盖其中的一部分?它可以用纯CSS完成,还是使用JS?

4 个答案:

答案 0 :(得分:3)

legend {
  padding: 1em;
  margin-left: calc(50% - 3em);
}
<fieldset>
  <legend>Test</legend>
</fieldset>

答案 1 :(得分:2)

&#13;
&#13;
body{
  background:white;
}
fieldset {
      display: block;
      margin: 20px 1%;
      margin-bottom: 20px;
      padding: 0 auto;
      padding: 15px 0;
      border: 0;
      border: 1px solid #000;
      width: 98%;
      background:white;
      color:black;
}

fieldset:last-of-type {
      margin-bottom: 0px;
}

legend {
     display: table; 
     min-width: 0px;
     max-width: 70%;
     position: relative;
     margin: auto;
     padding: 5px 20px;
     color: #000;
     font-size: 20px;
     text-align: center;
}

fieldset div{
  margin:0 auto;
  text-align:center;
  width:50%;
  //border:thin red solid;
  font-size:12px;
}
&#13;
    <fieldset>
        <legend align="center" >About Us</legend>
          <div>
            When You work with us... content
          </div>
    </fieldset>
&#13;
&#13;
&#13;

你在找这个吗?

这是JSFiddle

希望这有帮助。

答案 2 :(得分:0)

也许有一些常规标签(不是语义)和flex,你可以这样做:

div {
  magin: 2em;
  margin-top: 2em;
  border: solid;
  border-top: 0;
  padding: 1px;
  text-align: center;
}
h1 {
  margin-top: -0.6em;
  display: flex;
  align-items: center;
}
h1:before,
h1:after {
  content: '';
  flex: 1;
  border-bottom: solid;
  margin: auto -3px auto 2em;
}
h1:before {
  margin: auto 2em auto -3px;
}
p {
  padding: 1em;
}
/* do i see through ? */

body {
  background:linear-gradient(to bottom left, gray,yellow,purple,gold,pink,tomato);
<div>
  <h1>HTML Ipsum Presents</h1>

  <p><strong>Pellentesque habitant morbi tristique</strong> senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris
    placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis
    tempus lacus enim ac dui. <a href="#">Donec non enim</a> in turpis pulvinar facilisis. Ut felis.</p>
  <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
    Mauris placerat eleifend leo.</p>

</div>

答案 3 :(得分:-3)

你可能正在寻找这个

<div>
   <h1>Some Text</h1>
    <p>Some text also</p>
</div>

风格是

div{
    border:1px solid #000;
    text-align:center;  
}
div h1{
    background:#fff;
    margin-top:-20px;
    width:200px;
    margin-left:auto;
    margin-right:auto;
 }

CSS在链接

中给出

jsfiddle