Daniil Dubchenko Asked:2020-06-24 23:51:56 +0000 UTC2020-06-24 23:51:56 +0000 UTC 2020-06-24 23:51:56 +0000 UTC 如何渲染这个元素?[复制] 772 如何布置这样的元素,使线条全宽? html 3 个回答 Voted Shnur 2020-06-25T00:08:47Z2020-06-25T00:08:47Z 像这样 .test { text-align: center; position: relative; } .test:after { content: ""; display: block; height: 2px; background-color: #555555; width: 100%; position: absolute; top: 0; bottom: 0; margin: auto; z-index: 1; } .test span { border-radius: 6px; background-color: #555555; color: #ffffff; display: inline-block; padding: 0 15px; position: relative; z-index: 2; } <div class="test"><span>TEST</span></div> Best Answer Stanislav Belichenko 2020-06-25T00:07:34Z2020-06-25T00:07:34Z 可以使用十几个选项,但例如试试这个: hr { width: 100%; height: 3px; background-color: black; border: 0px; } span { display: block; position: absolute; width: 100px; background-color: black; color: white; margin-top: -28px; margin-left: -50px; padding: 10px; left: 50%; text-align: center; border-radius: 10px; } <br /> <br /> <br /> <hr /> <span>Text</span> webDev_ 2020-06-25T02:03:08Z2020-06-25T02:03:08Z div { position: relative; text-align: center; } div::before { content: ""; position: absolute; width: 100%; top: 50%; left: 0px; transform: translateY(-50%); border: 1px solid rgb(48,48,48); } div::after { content: attr(title); background-color: rgb(48,48,48); padding: 10px; display: inline-block; color: white; position: relative; z-index: 1; border-radius: 6px; min-width: 150px; } <div title="TEST"></div>
像这样
可以使用十几个选项,但例如试试这个: