Свойства CSS-файла не применяются. Цвет текста должен быть красным, а фон - светло-зеленым. Но ничего не применяется. Цвет текста просто черный, а фон белый. Я хочу изменить цвета вещей, которые находятся внутри класса fade. HTML-страница выглядит так Мой HTML-код:
<!DOCTYPE html>
<html xmlns = "http://www.w3.org/1999/xhtml"
xmlns:th = "http://www.thymeleaf.org">
<head>
<link rel = "stylesheet" type = "text/css" href = "cs.css">
<!-- <link rel = "stylesheet" href = "https://stackpath.bootstrapcdn.com/bootswatch/4.5.2/cosmo/bootstrap.min.css" />-->
<!-- <link-->
<!-- rel = "stylesheet"-->
<!-- href = "https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"-->
<!-- />-->
<script src= "https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" ></script>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
</head>
<body>
<script>
$(window).on("load",function() {
$(window).scroll(function() {
var windowBottom = $(this).scrollTop() + $(this).innerHeight();
$(".fade").each(function() {
/* Check the location of each desired element */
var objectBottom = $(this).offset().top + $(this).outerHeight();
/* If the element is completely within bounds of the window, fade it in */
if (objectBottom < windowBottom) { //object comes into view (scrolling down)
if ($(this).css("opacity")==0) {$(this).fadeTo(500,1);}
} else { //object goes out of view (scrolling up)
if ($(this).css("opacity")==1) {$(this).fadeTo(500,0);}
}
});
}).scroll(); //invoke scroll-handler on page-load
});
</script>
<div>
<form th:action = "@{/}">
Filter: <input type = "text" name = "keyword" id = "keyword" size = "50" th:value = "${keyword}" required />
<input type = "submit" value = "Search" />
<input type = "button" value = "Clear" id = "btnClear" onclick = "clearSearch()" />
</form>
</div>
<div class = "mimi">
<h2 >Search Recipe By Ingredients</h2>
<!-- <tr>-->
<div class = "col-sm-5" align = "center">
<div class = "panel-body" align = "center" >
<table>
<thead class = "thead-dark">
<tr>
<th>Recipe ID</th>
<th>Title</th>
<th>Source</th>
<th>Cuisine</th>
<th>Ingredients</th>
<th>Links</th>
</tr>
</thead>
<tbody>
<tr class = "fade" th:each = "recipe: ${listrecipe }">
<td th:text = "${recipe.Recipe_Id}">Recipe ID</td>
<td th:text = "${recipe.Title}">Title</td>
<td th:text = "${recipe.Source}">Source</td>
<td th:text = "${recipe.Cuisine}">Cuisine</td>
<td th:text = "${recipe.Ingredients}">Ingredients</td>
<td th:text = "${recipe.Links}">Links</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- </tr>-->
</div>
</body>
<script type = "text/javascript">
function clearSearch() {
window.location = "[[@{/}]]";
}
</script>
</html>
CSS:
.fade {
margin: 50px;
padding: 50px;
background-color: lightgreen;
opacity: 1;
color: red !important;
}



![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


Проверьте свои инструменты разработчика, применяется ли класс к элементу? Вы видите какие-либо другие CSS-стили, применяемые к элементу?
Попробуйте переместить свой скрипт в нижнюю часть страницы, а не вверх вне тела.
Пс. Я запустил ваш код в коде, и он работает нормально.
Спасибо за ответ. Теперь работает! Проблема заключалась в пути к файлу CSS. Я не упомянул путь как следует.