-3

I'm writing a website and I encountered one problem. I used 'background-image' in CSS, but instead of my image I see grey square. It's Q&A section. Here is the HTML structure and CSS code (I replaced my website content with with other words, the code is the same):

.qa-background {
  width: 900px;
  background-color: white;
  border-radius: 10px;
  box-shadow: 2px 3px 5px 0 grey;
  vertical-align: middle;
  text-align: center;
  z-index: 0;
  padding: 40px 0 20px 0;
}

.question {
  padding: 0;
  background-color: white;
  border-radius: 10px;
  border: 2px solid #169149;
  display: flex;
  text-align: left;
  justify-content: space-between;
  padding: 5px 30px 5px 30px;
  margin: 0 60px 10px 60px;
  z-index: 1;
}

.question p {
  color: black;
  font-size: 20px;
}

.qa-arrow {
  all: unset;
  width: 30px;
  height: 30px;
  margin: 0;
  background-image: url('assets/img/icons/qa-arrow.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  border: none;
  cursor: pointer;
  z-index: 2;
}

.qa-arrow:hover {
  filter: brightness(1.3);
}

.qa-arrow:active {
  transform: scale(0.95);
}

.answer {
  background-color: white;
  border-radius: 10px;
  border: 1px solid #bababa;
  text-align: left;
  padding: 5px 80px 5px 30px;
  display: block;
  margin: 0 60px 30px 60px;
  z-index: 1;
  animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
<div class="qa-background">
  <div class="question">
    <p><b>Some really nice question</b></p>
    <button class="qa-arrow"></button>
  </div>
  <div class="answer">
    <p>Answer</p>
    <ul>
      <li>1</li>
      <li>2</li>
      <li>3</li>
      <li>4</li>
      <li>5</li>
      <li>6</li>
      <li>7</li>
    </ul>
  </div>

  <div class="question">
    <p><b>Another amazing question</b></p>
    <button class="qa-arrow"></button>
  </div>
  <div class="answer">
    <p>Answer<br> some content</p>
  </div>
</div>

I have checked file path in HTML and it's correct. I have also checked linking from my HTML file to CSS file and it's also correct. When I style other elements in the document everything works perfectly fine, except this one. I have tried 'all: unset;' option, but now the button is not showing at all, only the cursor is showing. Can someone help me figure out what's wrong, please? :)

7
  • 2
    Please remember to reduce your code to minimal reproducible example form. Commented 2 days ago
  • Look in the network tab of Chrome for the network call to fetch the image. What URL is it loading from? Is it erroring? You may also need to force the image to load from the root of your web server, assuming it exists, by changing assets/... to /assets/...
    – Andy Ray
    Commented 2 days ago
  • I changed it to ../img/icons/qa-arrow.png and now it works. Before it was showing in the network tab as assets/css/assets/img/icons/qa-arrow.png. I don't know why it was this way, but now everything works so I'm happy. :) The /assets/img/icons/qa-arrow.png didn't work unfortunately. I didn't know that browser can read the file path different. Thank you!
    – Nari
    Commented 2 days ago
  • You should learn about the <base>` element and please next time focus your code on the question, so nothing more than the <button> element Commented 2 days ago
  • 1
    @MisterJojo I don't think <base> applies to URLs in stylesheets.
    – gre_gor
    Commented 2 days ago

0

Browse other questions tagged or ask your own question.