gpt4 book ai didi

html - 我该如何解决这个CSS问题?

转载 作者:太空宇宙 更新时间:2023-11-03 22:49:17 26 4
gpt4 key购买 nike

我想在一些 html 元素周围放置一个框。但是,此代码会导致每个单独的元素。我不想使用 html 或 body 元素,因为我还有其他想要的元素。

h1, p {
width: 300px;
padding: 50px;
border: 20px solid #0088dd;
text-align: center;}

</style>
</head>
<body>
<p>this should be in the box</p>
<h1>this should be in the box</h1>
<h2> this should not be in the box</h2>

最佳答案

您需要一个周围的元素来附加边框。在这种情况下,您可以按如下方式在您的样式中使用正文。

<style type="text/css">
body {
width: 300px;
padding: 50px;
border: 20px solid #0088dd;
text-align: center;}

</style>

警告:在 body 标记上放置边框不会出现在任何最佳实践列表中。曾经!

正确的方法是只使用一个类

   <style type="text/css">
.boxme {
width: 300px;
padding: 50px;
border: 20px solid #0088dd;
text-align: center;}

</style>
</header>
<body>
<div class="boxme">
<p>lol</p>
<h1>Thanks for helping</h1>
</div>
<p>Other text</p>

关于html - 我该如何解决这个CSS问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40817519/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com