如何在按钮的中心添加两行

发布于 2025-01-26 23:11:47 字数 641 浏览 4 评论 0 原文

有一个带有边框的按钮:3PX实心#E82929;哪些技术可以用来添加照片中的其他行?

“在此处输入图像说明”

.btn {
  position: relative;
  width: 362px;
  height: 71px;
  color: #FFFFFF;
  background-color: #000000;
  border: 3px solid #E82929;
  font-family: 'Flamenco';
  font-style: normal;
  font-weight: 400;
  font-size: 24px;
  line-height: 25px;
  text-align: center;
}
<button class="btn">Забронировать столик</button>

There is a button with a border: 3px solid #E82929; what technology can be used to add additional lines like in the photo?

enter image description here

.btn {
  position: relative;
  width: 362px;
  height: 71px;
  color: #FFFFFF;
  background-color: #000000;
  border: 3px solid #E82929;
  font-family: 'Flamenco';
  font-style: normal;
  font-weight: 400;
  font-size: 24px;
  line-height: 25px;
  text-align: center;
}
<button class="btn">Забронировать столик</button>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青衫儰鉨ミ守葔 2025-02-02 23:11:47

使用梯度

.btn {
  position: relative;
  padding: 20px 50px;
  color: #FFFFFF;
  border: 3px solid #E82929;
  font-family: 'Flamenco';
  font-style: normal;
  font-weight: 400;
  font-size: 24px;
  line-height: 25px;
  text-align: center;
  
  background: linear-gradient(90deg, #E82929 40px,#0000 0 calc(100% - 40px), #E82929 0) 50%/100% 3px no-repeat;
  background-color: #000000;
}
<button class="btn">Забронировать столик</button>

Use gradient

.btn {
  position: relative;
  padding: 20px 50px;
  color: #FFFFFF;
  border: 3px solid #E82929;
  font-family: 'Flamenco';
  font-style: normal;
  font-weight: 400;
  font-size: 24px;
  line-height: 25px;
  text-align: center;
  
  background: linear-gradient(90deg, #E82929 40px,#0000 0 calc(100% - 40px), #E82929 0) 50%/100% 3px no-repeat;
  background-color: #000000;
}
<button class="btn">Забронировать столик</button>

沫尐诺 2025-02-02 23:11:47

您不需要额外的标记,因为可以使用 :: :: After 伪元素。

假设您在左右2行应具有 30px 的宽度和 10px 的左右填充,您可以将其添加到已经存在的CSS:

.btn {
  position: relative;
  width: 362px;
  height: 71px;
  color: #FFFFFF;
  background-color: #000000;
  border: 3px solid #E82929;
  font-family: 'Flamenco';
  font-style: normal;
  font-weight: 400;
  font-size: 24px;
  line-height: 25px;
  text-align: center;
}

/* extra code comes here */
.btn {
  padding: 0 40px; /* 30px line width + 10px padding */
}

.btn::before,
.btn::after {
  background-color: #E82929; /* border color */
  content: ''; /* content is mandatory for the element to show up */
  height: 3px; /* 3px border width */
  position: absolute;
  top: 50%; /* 50% from the top */
  transform: translateY(-50%); /* half of its height back to the top */
  width: 30px; /* 30px line width */
}

.btn::before {
  left: 0;
}

.btn::after {
  right: 0;
}
<button class="btn">Забронировать столик</button>

根据您的需要更改宽度和填充。

它的作用是:它添加 :: /code> and 伪元素在左右没有文本内容,并垂直定位它们。

如果您对详细信息有任何疑问,请随时提出。

You do not need extra markup, because it can be done with the ::before and ::after pseudo elements.

Assuming your 2 lines at the left and right should have a width of 30px and a left and right padding of 10px, you could add this to your already existing CSS:

.btn {
  position: relative;
  width: 362px;
  height: 71px;
  color: #FFFFFF;
  background-color: #000000;
  border: 3px solid #E82929;
  font-family: 'Flamenco';
  font-style: normal;
  font-weight: 400;
  font-size: 24px;
  line-height: 25px;
  text-align: center;
}

/* extra code comes here */
.btn {
  padding: 0 40px; /* 30px line width + 10px padding */
}

.btn::before,
.btn::after {
  background-color: #E82929; /* border color */
  content: ''; /* content is mandatory for the element to show up */
  height: 3px; /* 3px border width */
  position: absolute;
  top: 50%; /* 50% from the top */
  transform: translateY(-50%); /* half of its height back to the top */
  width: 30px; /* 30px line width */
}

.btn::before {
  left: 0;
}

.btn::after {
  right: 0;
}
<button class="btn">Забронировать столик</button>

Change the width and padding according to your needs.

What it does: It adds the ::before and ::after pseudo elements with no text content on the left and right and positions them vertically centered.

If you have any questions regarding details, feel free to ask.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文