如何< pre>在HTML/CSS中的元素下放置按钮?

8dtrkrch  于 2023-02-01  发布在  其他
关注(0)|答案(2)|浏览(145)

我想把它放成这样:

这是我目前为止的代码,但是我尝试的代码没有一个能真正工作:
我做错了什么?

#container {
  text-align : center;
  }
.button {
  border          : none;
  color           : rgba(93, 24, 172, 0.603);
  padding         : 15px 15px;
  text-align      : center;
  text-decoration : none;
  display         : inline-block;
  font-size       : 10px;
  margin          : 10px 2px;
  cursor          : pointer;
  position        : absolute;
  }
.button1 {
  background-color : white;
  }
  
/*  added to see white text */
body { background : darkblue; }
<pre style="font-family:Calibri; color:white;text-align:left;">
  Duis aute irure dolor in reprehenderit in voluptare
  velit esse cillum dolore eu fugiat nulla pariatur.
  Exceptur sint occaecat cupidatat non proident, sunt
  in culpa qui officia deserunt mollit anim id est.
 </pre>

<div text-align="center">
  <button class="button button1" style="text-align:right;">READ MORE</button>
</div>

任何帮助都欢迎。谢谢!

c86crjj0

c86crjj01#

#container {
  text-align : center;
  }
.button {
  border          : none;
  color           : rgba(93, 24, 172, 0.603);
  padding         : 15px 15px;
  text-align      : center;
  text-decoration : none;
  display         : inline-block;
  font-size       : 10px;
  margin          : 15px 10px;
  cursor          : pointer;
 
  }
.button1 {
  background-color : white;
  }
  
/*  added to see white text */
body { background : darkblue; }

pre{
display:inline-block;
text-align:left;
margin:0 auto;}
<div id="container">
<pre style="font-family:Calibri; color:white;border: 1px solid white;">
  Duis aute irure dolor in reprehenderit in voluptare
  velit esse cillum dolore eu fugiat nulla pariatur.
  Exceptur sint occaecat cupidatat non proident, sunt
  in culpa qui officia deserunt mollit anim id est.</pre>
<div text-align="center">
  <button class="button button1" style="text-align:right;">READ MORE</button>
</div>
</div>
nuypyhwy

nuypyhwy2#

你的代码的主要问题是按钮有一个绝对的位置,所以它被从正常的文档流中删除了。同样根据你的网站,你需要一些布局,或者容器围绕按钮和文本,把它们放在一起。
我把按钮移到了文本下面,并为它们做了一个容器。我还删除了一些不必要的css和html,比如按钮周围的div。

body {
  background: #496bbe
}

.Container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: fit-content;
}

.button {
  border: none;
  color: rgba(93, 24, 172, 0.603);
  padding: 15px 15px;
  font-size: 10px;
  cursor: pointer;
}

.button1 {
  background-color: white;
}

pre {
  font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS", sans-serif;
  color: white;
  text-align: left;
  white-space: pre-wrap;
}
<section class="Container">
        <pre>
        Duis aute irure dolor in reprehenderit in voluptare
        velit esse cillum dolore eu fugiat nulla pariatur.
        Exceptur sint occaecat cupidatat non proident, sunt
        in culpa qui officia deserunt mollit anim id est.</pre>
        
        <button class="button button1" style="text-align:right;">READ MORE</button>
    </section>

相关问题