reactjs react-bootstrapv 2.5.0模态打开时背景变黑

2uluyalo  于 2022-11-04  发布在  React
关注(0)|答案(3)|浏览(140)

所以基本上我使用的是React引导模型。
我正在使用React和react-bootstrap组件。我实现了它,但是当我打开它时,背景不是半透明的(不透明度0.5),而是黑色的。

你也可以看到。当我打开模态时,背景变黑了,你几乎看不到后面的任何东西。
像这样使用模态

<Modal
  {...props}
  size="lg"
  aria-labelledby="contained-modal-title-vcenter"
  centered
>
  <Modal.Header style={{ backgroundColor: "#E8EDF9" }}>
    <Modal.Title id="contained-modal-title-vcenter">
      More Coupon Details
    </Modal.Title>
  </Modal.Header>
  <Modal.Body style={{ backgroundColor: "#F2F4FA" }}>
    <div className=" py-3">
      <div className="p-6 space-y-4 ">
        <div color="" className="bg-gray-400">
          <div className="d-flex fs-5 align-items-baseline justify-content-start">
            <h4 className="fs-5 text-black">Coupon Code : </h4>
            <p className="ms-2">{detailComponent.couponCode}</p>
          </div>
        </div>

        <div className="d-flex align-items-center justify-content-start">
          <div className="d-flex fs-5 align-items-baseline justify-content-start me-5">
            <h4 className="fs-5 text-black">Max Discount Percent :</h4>
            <p className="ms-2 ">{detailComponent.maxDiscountPer} %</p>
          </div>
          <div className="d-flex fs-5 align-items-baseline justify-content-start ms-5">
            <h4 className="fs-5 text-black">Max Discount Absolute :</h4>
            <p className="ms-2 ">{detailComponent.maxDiscountAbs} %</p>
          </div>
        </div>

        <div className="d-flex align-items-center justify-content-start">
          <div className="d-flex fs-5 align-items-baseline justify-content-start me-5">
            <h4 className="fs-5 text-black">Maximum Usage User :</h4>
            <p className="ms-2 ">{detailComponent.maxUsageUser}</p>
          </div>
          <div className="d-flex fs-5 align-items-baseline justify-content-start ms-5">
            <h4 className="fs-5 text-black">Maximum Usage Overall :</h4>
            <p className="ms-2">{detailComponent.maxUsageOverall}</p>
          </div>
        </div>

        <div className="d-flex align-items-center justify-content-start">
          <div className="d-flex fs-5 align-items-baseline justify-content-start me-5">
            <h4 className="fs-5 text-black">Start Date :</h4>
            <p className="ms-2">{detailComponent.startDate}</p>
          </div>
          <div className="d-flex fs-5 align-items-baseline justify-content-start ms-2">
            <h4 className="fs-5 text-black">End Date :</h4>
            <p className="ms-2">{detailComponent.endDate}</p>
          </div>
        </div>

        <div className="d-flex fs-5 align-items-baseline justify-content-start">
          <h4 className="fs-5 text-black">Coupon Description :</h4>
          <p className="ms-2">{detailComponent.description}</p>
        </div>

        <div className="d-flex fs-5 align-items-baseline justify-content-start">
          <h4 className="fs-5 text-black">Landing Page :</h4>
          <p className="ms-2">{detailComponent.landingPage}</p>
        </div>

        <div className="d-flex fs-5 align-items-baseline justify-content-start">
          <h4 className="fs-5 text-black">Redeem Steps :</h4>
          <p className="ms-2">{detailComponent.redeemSteps}</p>
        </div>

        <div className="d-flex fs-5 align-items-baseline justify-content-start">
          <h4 className="fs-5 text-black">Terms and Conditions :</h4>
          <p className="ms-2">{detailComponent.tnc}</p>
        </div>

        <div className="d-flex col-12 fs-5 align-items-baseline justify-content-start">
          <h4 className="fs-5 col-4 text-black">Applicable Channels :</h4>
          <p className="">
            {detailComponent.applicableChannelsDTOList
              ? detailComponent.applicableChannelsDTOList.map((item) => {
                  return <span key={item}>{item}, </span>;
                })
              : detailComponent.applicableVerticalsDTOList}
          </p>
        </div>
      </div>
    </div>
  </Modal.Body>
  <Modal.Footer style={{ backgroundColor: "#E8EDF9" }}>
    <Button variant="danger" className="mx-auto" onClick={props.onHide}>
      Close
    </Button>
  </Modal.Footer>
</Modal>

我附加的CSS文件的代码。(如果我使用的任何类的情况下,影响默认的模态类)。

应用程序.css

.no-border {
  border: 0;
  box-shadow: none;
}

.label {
  display: block;
  padding-left: 0;
  padding-right: 0;
  padding-top: 0.625rem;
  padding-bottom: 0.625rem;
  background-color: transparent;
  color: #111827;
  font-size: 0.8rem;
  line-height: 1.25rem;
  width: 100%;
  border-width: 0;
  border-bottom-width: 2px;
  border-color: #d1d5db;
  appearance: none;
}
.form {
  padding: 0.5rem;
  width: 100%;
  border-radius: 0.75rem;

  @media (min-width: 640px) {
    padding: 1rem;
  }
  @media (min-width: 768px) {
    width: 66.666667%;
  }
}

.drop {
  display: block;
  padding-left: 0;
  padding-right: 0;
  padding-top: 0.625rem;
  padding-bottom: 0.625rem;
  background-color: transparent;
  color: #111827;
  font-size: 0.875rem;
  line-height: 1.25rem;
  width: 100%;
  border-width: 0;
  border-bottom-width: 2px;
  border-color: #e5e7eb;
  appearance: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  whitespace: nowrap;
  borderwidth: 0;
}

.vertical {
  display: inline-flex;
  padding-top: 0.625rem;
  padding-bottom: 0.625rem;
  padding-left: 1rem;
  padding-right: 1rem;
  margin-left: 2rem;
  margin-top: 1.5rem;
  margin-bottom: 1.5rem;
  background-color: #e0e7ff;
  color: #000000;
  font-size: 0.875rem;
  line-height: 1.25rem;
  font-weight: 500;
  text-align: center;
  align-items: center;
  border-radius: 0.5rem;
}

.vertical:hover {
  background-color: #dbeafe;
}

.verticalBlock {
  display: block;
  background-color: #e0e7ff;
  width: 24rem;
  border-radius: 0.25rem;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}

.verticalHidden {
  display: none;
  background-color: #e0e7ff;
  width: 24rem;
  border-radius: 0.25rem;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}

.dropdownSearchButton {
  overflow-y: auto;
  padding-left: 0.75rem;
  padding-right: 0.75rem;
  padding-bottom: 0.75rem;
  color: #374151;
  font-size: 0.875rem;
  line-height: 1.25rem;
  height: 12rem;
}

.verticalflex {
  display: flex;
  flex-direction: row;
}

.verticalflex2 {
  display: flex;
  padding-left: 0.5rem;
  align-items: center;
  border-radius: 0.25rem;
}

.verticalflex2:hover {
  background-color: #e0e7ff;
}

.verticalInput {
  background-color: #f3f4f6;
  color: #4f46e5;
  width: 1rem;
  height: 1rem;
  border-radius: 0.25rem;
  border-color: #d1d5db;
}

.verticalLabel {
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
  margin-left: 0.5rem;
  color: #111827;
  font-size: 0.875rem;
  line-height: 1.25rem;
  width: 100%;
  border-radius: 0.25rem;
}

.verticalButton {
  display: flex;
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
  padding-left: 1rem;
  padding-right: 1rem;
  justify-content: space-between;
  align-items: center;
}

.doubleDropdownBlock {
  display: block;
  z-index: 10;
  margin: 0.5rem;
  background-color: #eef2ff;
  width: auto;
  border-radius: 0.25rem;
  border-top-width: 1px;
  border-color: #e0e7ff;
}

.doubleDropdownHidden {
  display: none;
  z-index: 10;
  margin: 0.5rem;
  background-color: #eef2ff;
  width: auto;
  border-radius: 0.25rem;
  border-top-width: 1px;
  border-color: #e0e7ff;
}

.doubleDropdownUl {
  display: flex;
  padding-top: 0.25rem;
  padding-bottom: 0.25rem;
  color: #374151;
  font-size: 0.875rem;
  line-height: 1.25rem;
  flex-direction: row;
}

.verticalTypeButton {
  display: block;
  padding: 0.25rem;
}
.verticalTypeButton:hover {
  background-color: #c7d2fe;
}

.verticalTypeButtonLabel {
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
  padding-left: 1rem;
  padding-right: 1rem;
}

.landing1 {
  position: relative;
  z-index: 0;
  margin-top: 1.5rem;
  margin-bottom: 1.5rem;
  width: 100%;
}

.landing2 {
  display: block;
  padding-left: 0;
  padding-right: 0;
  padding-top: 0.625rem;
  padding-bottom: 0.625rem;
  background-color: transparent;
  color: #111827;
  font-size: 0.875rem;
  line-height: 1.25rem;
  width: 100%;
  border-width: 0;
  border-bottom-width: 2px;
  border-color: #d1d5db;
  appearance: none;
}

.landing3 {
  position: absolute;
  top: 0.75rem;
  transition-duration: 300ms;
  --transform-scale-x: 0.75;
  --transform-scale-y: 0.75;
  --transform-translate-y: -1.5rem;
  color: #374151;
  font-size: 0.875rem;
  line-height: 1.25rem;
}

索引.css

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
    "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
    sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background-image: url("./assets/banner02.svg");
  background-repeat: no-repeat;
  background-size: cover;
}

.no-border {
  border: 0;
  box-shadow: none;
}

code {
  font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
    monospace;
}

a {
  color: inherit;
  text-decoration: none;
}

* {

  box-sizing: border-box;
}
xjreopfe

xjreopfe1#

较暗的背景是由以下原因造成的:

.modal-backdrop.show {
  opacity: var(--bs-backdrop-opacity);
}

首先,试试这个:

.modal-backdrop.show {
  opacity: 1;
}

这应该会完全移除不透明度。如果没有,可能是因为您在不透明度的上方套用了不透明度,所以才会如此暗。请检查您第二次套用不透明度的位置。

2ic8powd

2ic8powd2#

所提供的屏幕截图表明,在打开模态时,DOM中有多个.modal-backdrop.show元素。
这可能是由以下任何原因引起的(我怀疑该列表是否详尽):

  • 嵌套的情态动词(情态动词中的情态动词)
  • 重复的模式id s(运行时存在于DOM中)
  • 错误的模态实现,在关闭时没有删除.modal-backdrop,导致它在每次后续打开时都有+1个背景。

您没有提供足够的代码来确定原因(或重现问题),所以我只能提供一个隐藏问题的解决方案,而不修复错误源:

.modal-backdrop:not(#_) ~ .modal-backdrop,
body:not(.modal-open) .modal-backdrop {
  display: none;
}

我不推荐这样做,(这是在掩盖灰尘)。相反,你应该找到并修复bug源。

tvz2xvvm

tvz2xvvm3#

所以我对@鹿的答案做了一些操作,得出了这个解。

.modal-backdrop
{
    --bs-backdrop-bg: rgb(0 0 0 / 30%) !important;
}

这对我有用。

相关问题