css 星级设计成垂直

px9o7tmv  于 2023-03-25  发布在  其他
关注(0)|答案(3)|浏览(120)

我面临的问题,在创建一个评级界面,将要求用户率的网站(通过点击星星),并添加评论。星星成为垂直,而不是在水平,如链接的图片所示,我尝试了很多东西,但我不会工作。

/* New Rating CSS code */

.Cont {
  position: absolute;
  width: 633px;
  height: 438px;
  left: 413px;
  top: 252px;
  background: #F1F2F0;
  padding: 25px;
  border-radius: 9px;
  box-shadow: 4px 4px 2px #F1F2F0(230, 254, 164);
}

.cont {
  position: absolute;
  width: 20px;
  background: #f1f2f0;
  padding: 10px 10px;
  border: 1px solid gray;
  border-radius: 10px;
  /* display: inline-block; */
  align-items: center;
  justify-content: center;
  /* flex-direction: row-reverse; */
}

.cont .post {
  display: none;
}

.cont .text {
  font-size: 25px;
  color: #000;
  font-weight: 500;
}

.cont .edit {
  position: absolute;
  right: 10px;
  top: 5px;
  font-size: 16px;
  color: #000;
  font-weight: 500;
  cursor: pointer;
}

.cont .edit:hover {
  text-decoration: underline;
}

.cont .star-widget input {
  transform: rotate(90deg);
  display: none;
}

.star-widget label {
  font-size: 40px;
  position: relative;
  color: #fff;
  padding: 10px;
  float: right;
  transition: all 0.2s ease;
}

input:not(:checked)~label:hover,
input:not(:checked)~label:hover~label {
  color: #fd4;
}

input:checked~label {
  color: #fd4;
}

input#rate-5:checked~label {
  color: #fe7;
  text-shadow: 0 0 20px #952;
}

.container form {
  display: none;
}

input:checked~form {
  display: block;
}

form header {
  width: 100%;
  font-size: 25px;
  color: #fe7;
  font-weight: 500;
  margin: 5px 0 20px 0;
  text-align: center;
  transition: all 0.2s ease;
}

form .textarea {
  height: 100px;
  width: 100%;
  overflow: hidden;
}

form .textarea textarea {
  height: 130px;
  position: absolute;
  width: 588px;
  top: 230px;
  outline: #777;
  color: gray;
  border: 1px solid gray;
  background: #fff;
  padding: 10px;
  font-size: 16px;
  resize: none;
  text-align: center;
  justify-content: center;
}

.textarea textarea:focus {
  border-color: #000;
}

form .btn {
  position: absolute;
  height: 30px;
  width: 590px;
  top: 380px;
  left: 23px;
}

form .btn button {
  height: 100%;
  width: 100%;
  border: 0px solid #000;
  outline: none;
  background: #c5e8b4;
  color: #000;
  font-size: 17px;
  font-weight: bold;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.3s ease;
}

form .btn button:hover {
  background: #c5e8b4;
}
<div class="Cont">
  <form action="" method="post">
    <div class="cont">
      <div class="post">
        <div class="text">Success </div>
        <div class="edit">edit</div>
      </div>

      <div class="star-widget">
        <input type="radio" name="Rate" id="rate-5" value="5">
        <label for="rate-5" class="fas fa-star" value="rate-5"></label>

        <input type="radio" name="Rate" id="rate-4" value="4">
        <label for="rate-4" class="fas fa-star" value="rate-4"></label>

        <input type="radio" name="Rate" id="rate-3" value="3">
        <label for="rate-3" class="fas fa-star" value="rate-3"></label>

        <input type="radio" name="Rate" id="rate-2" value="2">
        <label for="rate-2" class="fas fa-star" value="rate-2"></label>

        <input type="radio" name="Rate" id="rate-1" value="1">
        <label for="rate-1" class="fas fa-star" value="rate-1"></label>
      </div>

    </div>
    <div dir="ltr" class="textarea">
      <textarea name="Comment" cols="30" placeholder="Describe your experince in the website"></textarea>
    </div>
    <div class="btn">
      <button type="submit" name="submit">Send</button>
    </div>

  </form>

</div>
chhkpiq4

chhkpiq41#

您可以将每个标签和输入 Package 在div中,并将星形小部件转换为flex。

/* New Rating CSS code */
.Cont{
  position: absolute;
  width: 633px;
  height: 438px;
  left: 413px;
  top: 252px;
  background: #F1F2F0;
  padding: 25px;
  border-radius: 9px;
  box-shadow: 4px 4px 2px #F1F2F0(230, 254, 164);  
}
.cont{
  position: absolute;
  background: #f1f2f0;
  padding: 10px 10px;
  border: 1px solid gray;
  border-radius: 10px;
  /* display: inline-block; */
  align-items: center;
  justify-content: center;
  /* flex-direction: row-reverse; */
}
.cont .post{
  display: none;
}
.cont .text{
  font-size: 25px;
  color: #000;
  font-weight: 500;
}
.cont .edit{
  position: absolute;
  right: 10px;
  top: 5px;
  font-size: 16px;
  color: #000;
  font-weight: 500;
  cursor: pointer;
}
.cont .edit:hover{
  text-decoration: underline;
}
.cont .star-widget {
  display: flex;
}
.cont .star-widget input{
  transform:rotate(90deg);
  display: none;
}
.star-widget label{
  font-size: 40px;
  position: relative;
  color: #fff;
  padding: 10px;
  float: right;
  transition: all 0.2s ease;
}
input:not(:checked) ~ label:hover,
input:not(:checked) ~ label:hover ~ label{
  color: #fd4;
}
input:checked ~ label{
  color: #fd4;
}
input#rate-5:checked ~ label{
  color: #fe7;
  text-shadow: 0 0 20px #952;
}

.container form{
  display: none;
}
input:checked ~ form{
  display: block;
}
form header{
  width: 100%;
  font-size: 25px;
  color: #fe7;
  font-weight: 500;
  margin: 5px 0 20px 0;
  text-align: center;
  transition: all 0.2s ease;
}
form .textarea{
  height: 100px;
  width: 100%;
  overflow: hidden;

}
form .textarea textarea{
  height: 130px;
  position: absolute;
  width: 588px;
  top:230px;
  outline:#777;
  color: gray;
  border: 1px solid gray;
  background: #fff;
  padding: 10px;
  font-size: 16px;
  resize: none;
  text-align: center;
  justify-content: center;
}
.textarea textarea:focus{
  border-color: #000;
}
form .btn{
  position: absolute;
  height: 30px;
  width: 590px;
  top:380px;
  left: 23px;

}
form .btn button{
  height: 100%;
  width: 100%;
  border: 0px solid #000;
  outline: none;
  background: #c5e8b4;
  color: #000 ;
  font-size: 17px ;
  font-weight: bold;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.3s ease;
}
form .btn button:hover{
  background: #c5e8b4;
}
<div class="Cont">
  <form action="" method="post">
    <div class="cont">
      <div class="post">
        <div class="text">Success </div>
        <div class="edit">edit</div>
      </div>

      <div class="star-widget">
        <div>
          <input type="radio" name="Rate" id="rate-5" value="5">
          <label for="rate-5" class="fas fa-star" value="rate-5"></label>
        </div>
        <div>

          <input type="radio" name="Rate" id="rate-4" value="4">
          <label for="rate-4" class="fas fa-star" value="rate-4"></label>
        </div>
        <div>
          <input type="radio" name="Rate" id="rate-3" value="3">
          <label for="rate-3" class="fas fa-star" value="rate-3"></label>
        </div>
        <div>
          <input type="radio" name="Rate" id="rate-2" value="2">
          <label for="rate-2" class="fas fa-star" value="rate-2"></label>
        </div>
        <div>
          <input type="radio" name="Rate" id="rate-1" value="1">
          <label for="rate-1" class="fas fa-star" value="rate-1"></label>
        </div>
      </div>

    </div>
    <div dir="ltr" class="textarea">
      <textarea name="Comment" cols="30" placeholder="Describe your experince in the website"></textarea>
    </div>
    <div class="btn">
      <button type="submit" name="submit">Send</button>
    </div>

  </form>

</div>
but5z9lq

but5z9lq2#

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Form Submission Example</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css" integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ==" crossorigin="anonymous" referrerpolicy="no-referrer" />
    <style type="text/css">
      /* New Rating CSS code */

.Cont {
  position: absolute;
  width: 633px;
  height: 438px;
  left: 413px;
  top: 252px;
  background: #F1F2F0;
  padding: 25px;
  border-radius: 9px;
  box-shadow: 4px 4px 2px #F1F2F0(230, 254, 164);
}

.cont {
background: #f1f2f0;
padding: 10px 10px;
border: 1px solid gray;
border-radius: 10px;
display: flex;
justify-content: center;
}

.cont .post {
  display: none;
}

.cont .text {
  font-size: 25px;
  color: #000;
  font-weight: 500;
}

.cont .edit {
  position: absolute;
  right: 10px;
  top: 5px;
  font-size: 16px;
  color: #000;
  font-weight: 500;
  cursor: pointer;
}

.cont .edit:hover {
  text-decoration: underline;
}

.cont .star-widget input {
  transform: rotate(90deg);
  display: none;
}

.star-widget label {
  font-size: 40px;
  position: relative;
  color: #fff;
  padding: 10px;
  float: right;
  transition: all 0.2s ease;
}

input:not(:checked)~label:hover,
input:not(:checked)~label:hover~label {
  color: #fd4;
}

input:checked~label {
  color: #fd4;
}

input#rate-5:checked~label {
  color: #fe7;
  text-shadow: 0 0 20px #952;
}

.container form {
  display: none;
}

input:checked~form {
  display: block;
}

form header {
  width: 100%;
  font-size: 25px;
  color: #fe7;
  font-weight: 500;
  margin: 5px 0 20px 0;
  text-align: center;
  transition: all 0.2s ease;
}

form .textarea {
  height: 100px;
  width: 100%;
  overflow: hidden;
}

form .textarea textarea {
  height: 130px;
  position: absolute;
  width: 588px;
  top: 230px;
  outline: #777;
  color: gray;
  border: 1px solid gray;
  background: #fff;
  padding: 10px;
  font-size: 16px;
  resize: none;
  text-align: center;
  justify-content: center;
}

.textarea textarea:focus {
  border-color: #000;
}

form .btn {
  position: absolute;
  height: 30px;
  width: 590px;
  top: 380px;
  left: 23px;
}

form .btn button {
  height: 100%;
  width: 100%;
  border: 0px solid #000;
  outline: none;
  background: #c5e8b4;
  color: #000;
  font-size: 17px;
  font-weight: bold;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.3s ease;
}

form .btn button:hover {
  background: #c5e8b4;
}
    </style>
  </head>
  <body>
    <div class="Cont">
  <form action="" method="post">
    <center>
      <div class="cont">
      <div class="post">
        <div class="text">Success </div>
        <div class="edit">edit</div>
      </div>

      <div class="star-widget">
        <input type="radio" name="Rate" id="rate-5" value="5">
        <label for="rate-5" class="fas fa-star" value="rate-5"></label>

        <input type="radio" name="Rate" id="rate-4" value="4">
        <label for="rate-4" class="fas fa-star" value="rate-4"></label>

        <input type="radio" name="Rate" id="rate-3" value="3">
        <label for="rate-3" class="fas fa-star" value="rate-3"></label>

        <input type="radio" name="Rate" id="rate-2" value="2">
        <label for="rate-2" class="fas fa-star" value="rate-2"></label>

        <input type="radio" name="Rate" id="rate-1" value="1">
        <label for="rate-1" class="fas fa-star" value="rate-1"></label>
      </div>

    </div>
    </center>
    <div dir="ltr" class="textarea">
      <textarea name="Comment" cols="30" placeholder="Describe your experince in the website"></textarea>
    </div>
    <div class="btn">
      <button type="submit" name="submit">Send</button>
    </div>

  </form>

</div>

    <script>
      function submitForm(event) {
        event.preventDefault(); // prevent default form submission behavior

        // get form data
        const form = event.target;
        const formData = new FormData(form);

        // submit form data asynchronously
        fetch(form.action, {
          method: form.method,
          body: formData
        })
        .then(response => {
          if (!response.ok) {
            throw new Error('Form submission error');
          }
          // do something with successful form submission
        })
        .catch(error => {
          console.error(error);
          // handle form submission error
        });
      }
    </script>
  </body>
</html>

试试这段代码的一些变化的CSS。

2nbm6dog

2nbm6dog3#

/* New Rating CSS code */
.Cont{
  position: absolute;
  width: 633px;
  height: 438px;
  left: 413px;
  top: 252px;
  background: #F1F2F0;
  padding: 25px;
  border-radius: 9px;
  box-shadow: 4px 4px 2px #F1F2F0(230, 254, 164);  
}
.cont{
  position: absolute;
  width: 20px;
  background: #f1f2f0;
  padding: 10px 10px;
  /*border: 1px solid gray;*/
  border-radius: 10px;
  /* display: inline-block; */
  align-items: center;
  justify-content: center;
  /* flex-direction: row-reverse; */
}
.cont .post{
  display: none;
}
.cont .text{
  font-size: 25px;
  color: #000;
  font-weight: 500;
}
.cont .edit{
  position: absolute;
  right: 10px;
  top: 5px;
  font-size: 16px;
  color: #000;
  font-weight: 500;
  cursor: pointer;
}
.cont .edit:hover{
  text-decoration: underline;
}
.cont .star-widget input{
  transform:rotate(90deg);
  display: none;
}
.star-widget label{
  font-size: 40px;
  position: relative;
  color: #fff;
  padding: 10px;
  float: right;
  transition: all 0.2s ease;
}
input:not(:checked) ~ label:hover,
input:not(:checked) ~ label:hover ~ label{
  color: #fd4;
}
input:checked ~ label{
  color: #fd4;
}
input#rate-5:checked ~ label{
  color: #fe7;
  text-shadow: 0 0 20px #952;
}

.container form{
  display: none;
}
input:checked ~ form{
  display: block;
}
form header{
  width: 100%;
  font-size: 25px;
  color: #fe7;
  font-weight: 500;
  margin: 5px 0 20px 0;
  text-align: center;
  transition: all 0.2s ease;
}
form .textarea{
  height: 100px;
  width: 100%;
  overflow: hidden;

}
form .textarea textarea{
  height: 130px;
  position: absolute;
  width: 588px;
  top:230px;
  outline:#777;
  color: gray;
  border: 1px solid gray;
  background: #fff;
  padding: 10px;
  font-size: 16px;
  resize: none;
  text-align: center;
  justify-content: center;
}
.textarea textarea:focus{
  border-color: #000;
}
form .btn{
  position: absolute;
  height: 30px;
  width: 590px;
  top:380px;
  left: 23px;

}
form .btn button{
  height: 100%;
  width: 100%;
  border: 0px solid #000;
  outline: none;
  background: #c5e8b4;
  color: #000 ;
  font-size: 17px ;
  font-weight: bold;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.3s ease;
}
form .btn button:hover{
  background: #c5e8b4;
}

/* use reverse flexbox to take advantage of flex-direction: reverse */
.star-rating {
  display: flex;
  align-items: center;
  width: 160px;
  flex-direction: row-reverse;
  justify-content: space-between;
  margin: 40px auto;
  position: relative;
}
/* hide the inputs */
.star-rating input {
  display: none;
}
/* set properties of all labels */
.star-rating > label {
  width: 30px;
  height: 30px;
  font-family: Arial;
  font-size: 30px;
  transition: 0.2s ease;
  color: orange;
}
/* give label a hover state */
.star-rating label:hover {
  color: #ff69b4;
  transition: 0.2s ease;
}
.star-rating label:active::before {
  transform:scale(1.1);
}

/* set shape of unselected label */
.star-rating label::before {
  content: '\2606';
  position: absolute;
  top: 0px;
  line-height: 26px;
}
/* set full star shape for checked label and those that come after it */
.star-rating input:checked ~ label:before {
  content:'\2605';
}

@-moz-document url-prefix() {
  .star-rating input:checked ~ label:before {
  font-size: 36px;
  line-height: 21px;
  }
}
<div class="Cont">
        <form action="" method="post">
            <div class="cont">
                <div class="post">
                    <div class="text">Success </div>
                    <div class="edit">edit</div>
                </div>
        
            <div class="star-rating">
      <input type="radio" name="stars" id="star-a" value="5"/>
      <label for="star-a"></label>

      <input type="radio" name="stars" id="star-b" value="4"/>
      <label for="star-b"></label>
  
      <input type="radio" name="stars" id="star-c" value="3"/>
      <label for="star-c"></label>
  
      <input type="radio" name="stars" id="star-d" value="2"/>
      <label for="star-d"></label>
  
      <input type="radio" name="stars" id="star-e" value="1"/>
      <label for="star-e"></label>
</div>

            
        </div>
        <div dir="ltr" class="textarea">
            <textarea name="Comment" cols="30" placeholder="Describe your experince in the website"></textarea>
          </div>
          <div  class="btn">
            <button type="submit" name="submit">Send</button>
          </div>

        </form>

    </div>

试试这个代码。

相关问题