css 无法使徽标在可折叠选项卡中打开单击

bgtovc5b  于 2023-01-27  发布在  其他
关注(0)|答案(1)|浏览(157)

无论我尝试什么,我就是不能让图标打开点击。
在这里我已经张贴了我的代码的一节,所以我希望label::after旋转90deg当你点击标签,这里是我主要使用:
#accordion label + input[type="radio"]:checked + label::after
我有同样的一个,但不是标签::在它是. content之后,. content一个工作正常,但只要我尝试使用任何关于标签本身它根本不工作,有人能告诉我我做错了什么吗?

#accordion {
  margin: 100px auto;
  max-width: 500px;
}

#accordion li {
  list-style: none;
  width: 100%;
  margin-bottom: 0.5rem;
  padding: 5px;
  border-radius: 4px;
  background: none;
}

#accordion li label {
  padding: 5px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 1.7rem;
  font-weight: 700;
  cursor: pointer;
  color: #000000;
  background: white;
  border: 2px solid black;
  border-radius: 4px;
}

#accordion .content {
  background: none;
}

#accordion .content li p {
  background: none;
}

#accordion label+input[type="radio"] {
  display: none;
}

#accordion .content {
  padding: 0 10px;
  line-height: 26px;
  max-height: 0;
  overflow: hidden;
  color: black;
  transition: max-height 1s;
}

#accordion label+input[type="radio"]:checked+.content {
  max-height: 1000px;
}

#accordion label:hover {
  color: #ffffff;
  background-color: #0062cc;
  transition: ease all 0.35s;
  font-size: 2rem;
  border: 2px solid white;
}

#accordion .tab-close {
  width: 35%;
}

#accordion label::after {
  content: "\276F";
  width: 1em;
  height: 1em;
  text-align: center;
}

#accordion label+input[type="radio"]:checked+label::after {
  display: flex;
  transform: rotate(90deg);
  transition: 1s;
}
<section class="quantity" id="Quantity">
  <div class="services-container">
    <div class="quantity-left">
      <div class="content">
        <h1>Quantity Surveying</h1>
        <p>
          We at BGQS Consulting strive to offer the highest quality QS service in SA and our main objective is to maintain the highest possible standards with regards to: Services to the client, Effectiveness and competence, Integrity, secrecy, honesty and loyalty,
          Quality of documentation, Experience and scope of knowledge, Application of the latest technology, Professionalism and true commitment, Punctuality and response time and Friendliness. Here are some of the steps in our process:
        </p>
        <ul id="accordion">
          <li>
            <label for="quantity-first">Estimations</label>
            <input type="radio" name="accordion" id="quantity-first">
            <div class="content">
              <ul>
                <li>Preparing capital cost estimates for budget purposes and project approval through all the phases pre-concept to feasibility.</li>
                <li>Creating a compilation of budget cost though our in-house database of previously completed projects, quotations from equipment and special services suppliers.</li>
                <li>Conducting preliminary measures and elemental cost estimating.</li>
              </ul>
            </div>
          </li>
          <li>
            <label for="quantity-second">Pre-Contract Services</label>
            <input type="radio" name="accordion" id="quantity-second">
            <div class="content">
              <ul>
                <li>Preparing contract conditions, including special conditions.</li>
                <li>Standardisation of contract conditions and special conditions for any particular project</li>
                <li>Preparing tender bills of quantities for all construction contracts (e.g., civils, building, demolition works, structural, mechanical, piping, electrical and instrumentation, etc.)</li>
                <li>Assistance with compilation of vendor lists for client approval.</li>
                <li>Drafting of enquiry documents for tender purposes.</li>
                <li>Commercial tender evaluations, clarifications and adjudication reports.</li>
              </ul>
            </div>
          </li>
mklgxw1f

mklgxw1f1#

这是因为您的<label>元素在HTML中位于单选框<input>的下方,因此在样式方面,标签无法推断输入是否为"* checked *"。

#accordion {
  max-width: 500px;
  padding: 0;
}

#accordion li {
  list-style: none;
  width: 100%;
  margin-bottom: 0.5rem;
  padding: 5px;
  border-radius: 4px;
  background: none;
}

#accordion li label {
  padding: 5px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 1.7rem;
  font-weight: 700;
  cursor: pointer;
  color: #000000;
  background: white;
  border: 2px solid black;
  border-radius: 4px;
}

#accordion .content {
  background: none;
}

#accordion .content li p {
  background: none;
}

#accordion label+input[type="radio"] {
  display: none;
}

#accordion .content {
  padding: 0 10px;
  line-height: 26px;
  max-height: 0;
  overflow: hidden;
  color: black;
  transition: max-height 1s;
}

/* Changhed + to ~ since the order of HTML changed */
#accordion input[type="radio"]:checked ~ .content {
  max-height: 1000px;
}

#accordion label:hover {
  color: #ffffff;
  background-color: #0062cc;
  transition: ease all 0.35s;
  font-size: 2rem;
  border: 2px solid white;
}

#accordion .tab-close {
  width: 35%;
}

#accordion label::after {
  content: "\276F";
  width: 1em;
  height: 1em;
  text-align: center;
  transition: 1s; /* transition should be here and not below */
}

#accordion input[type="radio"]:checked + label::after {
  transform: rotate(90deg);
}
<ul id="accordion">
  <li>
    <input type="radio" hidden name="accordion" id="quantity-first" />
    <label for="quantity-first">Estimations</label>
    <div class="content">
      <ul>
        <li>Preparing capital cost estimates for budget purposes and project approval through all the phases pre-concept to feasibility.</li>
        <li>Creating a compilation of budget cost though our in-house database of previously completed projects, quotations from equipment and special services suppliers.</li>
        <li>Conducting preliminary measures and elemental cost estimating.</li>
      </ul>
    </div>
  </li>
  <li>
    <input type="radio" hidden name="accordion" id="quantity-second" />
    <label for="quantity-second">Pre-Contract Services</label>
    <div class="content">
      <ul>
        <li>Preparing contract conditions, including special conditions.</li>
        <li>Standardisation of contract conditions and special conditions for any particular project</li>
        <li>Preparing tender bills of quantities for all construction contracts (e.g., civils, building, demolition works, structural, mechanical, piping, electrical and instrumentation, etc.)</li>
        <li>Assistance with compilation of vendor lists for client approval.</li>
        <li>Drafting of enquiry documents for tender purposes.</li>
        <li>Commercial tender evaluations, clarifications and adjudication reports.</li>
      </ul>

我建议使用checkbox而不是radio类型的输入,因为radio accordion 项目不能被"关闭/折叠",除非另一个项目被"打开"。对于UX,最好使用checkbox类型。

相关问题