#html #css
#HTML #css
Вопрос:
Я новичок в веб-дизайне и использую его, чтобы иметь возможность запускать свою собственную страницу и, возможно, больше. Возможно, это неподходящая область для этого поста или может быть, но у меня есть проблема, которая не решается путем изменения цвета в css.кнопка: наведение красного на другой цвет. Это изменяет исходный цвет кнопки, но остальная часть текста на большей части страницы по-прежнему остается красной при наведении курсора. Текст ниже, сначала css, затем html. Это руководство, которому мы следуем. Что не так со ссылкой / текстом, спасибо.
/*
*{
margin: 0;
padding: 0;
}
above = every element and style = even auto top padding (reset)*/
body{
background color: #f4f4f4;
color: #555555;
font font-family: Sans-Serif, monospace, serif, sans-serif,
Bookman Old Style, Ubuntu;
font-size:16px;
font-weight: normal;
/*same as above --- em or px for line heights*/
font: normal 16px Sans-Serif, monospace, serif, sans-serif,
Bookman Old Style, Ubuntu;
line-height: 1.6em;
margin: 0;
}
a{
text-decoration: none;
/* = removes underline of links,"a<>"
is added later to links to standardise links styles and more =
hover state - active state - visited state - */
color: #000;
}
a:hover{
color: red;
}
a:active{
color: green;
}
a:visited{
/* removed color:black; = interfering with link of button colour. */
}
.container{
width: 80%;
margin: auto;
}
.button{
background-color:#333;
color:#fff;
padding:10px 15px;
border:none;
}
.button:hover{
background-color:green;
color:#fff;
}
.box-1{
background-color: #333333;
color: #fff;
border-right: 5px red solid;
border-left: 5px red solid;
border-top: 5px red solid;
border-bottom: 5px red solid;
/* same as above in a shorter syntax for "borders, padding amp; margins" */
border: 5px red solid;
/* shortcut color = #333 = same darkish "black"
or use black/white/words...container is better as percentage
therefore allowing movement scaling. */
border-width: 3px;
border-bottom-width: 10px;
border-top-style: dotted;
/* overwrites border above = 3, 10, dotted ... also "padding" = inside of border,
margin = outside of border*/
border: 5px red solid;
padding: 20px;
margin-top: 20px;
/* overwrite is next for 20px top amp; bottom and 0 for right amp; left */
margin:20px 0;
}
.clr{
clear:both;
}
.box-1 h1{
font-family: serif;
font-weight: 800;
font-style: italic;
text-decoration:underline;
text-transform:uppercase;
letter-spacing:0.2em;
word-spacing:1em;
}
.box-2{
border: 3px dotted #ccc;
padding: 20px;
margin: 20px 0;
}
.categories{
border: 1px #ccc solid;
padding:10px;
border-radius: 15px;
/* radius = rounded corners of "categories" */
}
.categories h2{
text-align: center;
}
.categories ul{
padding:0; /* = reset to remove "auto-padding" */
padding-left: 20px; /* for check mark spacing*/
list-style: square;
list-style: none;
}
.categories li{
padding-bottom: 6px;
border-bottom: dotted 1px #333;
list-style-image: url('../images/check.png');
/* adjust size of image used in gimp or photo shop such as 10px */
}
.my-form{
padding:20px;
}
.my-form .form-group{
padding-bottom:15px;
}
.my-form label{
display:block;
}
.my-form input[type="text"], .my-form textarea {
padding:8px;
width: 100%; /* = any input = button = 100% width of the "container"
but text and textarea are targeted byt the added "type " ---
.my-form [type="submit"] {
background-color:#333;
color:#fff;
padding:10px 15px;
border:none; = was before "global button class" change above for all */
}
.block{
float:left;
width:33.3%;
border:1px solid #ccc;
padding:10px; /* warning = this adds to void % = 10px (too wide = 2 rows created), therefore, next lines added */
box-sizing:border-box;
}
#main-block{
float:left;
width:70%;
padding:15px 15px 15px 15px;
box-sizing:border-box;
}
#sidebar{
float:right;
width:30%;
background-color: #333;
color:#fff;
padding:15px;
box-sizing:border-box;
}
..................
<!DOCTYPE html>
<html>
<head>
<title>CSS Cheat Sheet</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div class="container"> <!-- c/ container starts here /// -->
<div class="box-1">
<h1>Hello World</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</div>
<div class="box-2">
<h1>Goodbye World</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<a class="button" href="">read more</a>
</div>
<div class="categories">
<h2>Categories</h2>
<ul>
<li><a href="#no-where-linked-page-location">Category 1</li>
<li><a href="#no-where-linked-page-location">Category 2</li>
<li><a href="#no-where-linked-page-location">Category 3</li>
<li><a href="#no-where-linked-page-location">Category 4</li>
<li><a href="test.html">Category 5</li>
</ul>
</div>
<form class="my-form">
<div class="form-group">
<label>Name:</label>
<input type="text" name="name">
</div>
<div class="form-group">
<label>E-mail:</label>
<input type="text" name="message">
</div>
<div class="form-group">
<label>Message</label>
<textarea name="message"></textarea>
</div>
<input class="button" type="submit" value="Submit" name="">
</form>
<div class="block">
<h3>Heading</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.
</p>
</div>
<div class="block">
<h3>Heading</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.
</p>
</div>
<div class="block">
<h3>Heading</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.
</p>
</div>
<div class="clr">
</div>
<div id="main-block">
<h3>Heading</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.
</p>
</div>
<div id="sidebar">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.
</p>
</div>
<div class="clr"></div>
<div class="p-box">
<h1>Hello</h1>
<h2>Goodbye</h2>
</div>
</div> <!--/ container ends here, also p-box means "positioning box". /// -->
</body>
</html>
Ответ №1:
Если я понимаю вопрос, все ссылки должны быть зелеными при наведении?
В настоящее время зеленый цвет применяется только к кнопке класса ( .button
в CSS) при наведении. Ссылки в разделе «Категории» — это не кнопки, а ссылки, и у них нет button
класса. Таким образом, стиль не может быть применен.
Ссылки, поскольку у них нет класса, используют:
a:hover{
color: red;
}
Поэтому нормально, что при наведении красный цвет. Если вы хотите, чтобы цвет стал зеленым, измените «красный» на «зеленый».
PS: в коде есть несколько проблем. В начале CSS:
- мы обнаруживаем
font font-family:
, что вам нужно объявить одно или другое свойство, например:font:
или.font-family:
- мы обнаруживаем
background color
, что нет пробела, а-
вот такbackground-color
В HTML: ссылки требуют закрывающего тега, например </a>