Испытание: взломанный котопрофайл [18/18]

Занимаюсь всего несколько дней, очень хочется знать, насколько адекватно и грамотно такое решение. При проверке получила 100%. Спасибо!

html,
body {
margin: 0;
padding: 0;
}

body {
width: 550px;
height: 300px;
font-size: 12px;
font-family: Tahoma, Arial, sans-serif;
}

.profile {
padding: 5px 10px;
}

.profile img {
display: block;
padding: 10px;
border: 2px solid #34495e;
border-radius: 8px;
}

.profile .photo {
float: left;
width: 152px;
}

.profile .info {
float: left;
width: 368px;
margin-left: 10px;
}

#info-title,
.info h2 {
margin: 0 !important;
padding: 10px !important;
font-weight: normal;
font-size: 12px;
color: #ffffff;
background: #34495e;
border-radius: 4px;
}

.profile .info .fact {
padding: 10px;
background: white;
}

.info .fact:nth-child(odd) {
background: #ecf0f1;
}

.fact::after {
content: “”;
display: table;
clear: both;
}

.profile .fact .title {
float: left;
width: 120px;
text-align: right;
color: #7f8c8d;
}

.profile .fact .value {
margin-left: 140px;
color: #34495e;
}

.albums {
margin-top: 5px;
}

.albums img,
#miska {
float: left;
margin-right: 5px;
}

.albums img:last-child {
margin-right: 0;
}

.photo .button {
display: block;
height: 30px;
margin: 5px 0;
line-height: 30px;
text-align: center;
color: #ffffff;
border-radius: 4px;
}

.photo .stroke {
background: #3498db;
}

.photo .feed {
background: #2ecc71;
}

.photo .startle {
background: #e74c3c;
}

Поясните, почему нельзя обойтись без использования !important в этом правиле?

Это единственные две позиции, когда усилять селектор уже просто некуда - он в html прописан через style, а это самая сильная позиция из всех возможных. единственный способ ее перебить - пойти на хамство и добавить в css !important

1 лайк

А не подскажите как перебить, у меня как то не получаеться

Какой именно селектор вы не можете сделать?

Я нашел уже спасибо)

html,
body {
margin: 0;
padding: 0;
}

body {
width: 550px;
height: 300px;
font-size: 12px;
font-family: Tahoma, Arial, sans-serif;
}

.profile {
padding: 5px 10px;
}

.profile img {
display: block;
padding: 10px;
border: 2px solid #34495e;
border-radius: 8px;
}

.profile .photo {
float: left;
width: 152px;
}

.profile .info {
float: left;
width: 368px;
margin-left: 10px;

}

.info #info-title, .info h2 {
margin: 0 !important;
padding: 10px !important;
font-weight: normal;
font-size: 12px;
color: #ffffff;
background: #34495e;
border-radius: 4px;

}
#info-title{
background: #34495e;
}

.profile div .fact {
padding: 10px;
background: white;
}

.info .fact:nth-child(odd) {
background: #ecf0f1;
}
.fact::after {
content: “”;
display: table;
clear: both;
color: red;
}

.info .fact .title {
float: left;
width: 120px;
text-align: right;
color: #7f8c8d;
}

.info .fact .value {
margin-left: 140px;
color: #34495e;
}

.albums {
margin-top: 5px;
}

.albums #miska,
.albums img {
float: left;
margin-right: 5px;
}
.albums img:last-child {
margin-right: 0;
}

.profile .button {
display: block;
height: 30px;
margin: 5px 0;
line-height: 30px;
text-align: center;
color: #ffffff;
border-radius: 4px;
}

.profile .stroke {
background: #3498db;
}

.profile .feed {
background: #2ecc71;
}

.profile .startle {
background: #e74c3c;
}

Подскажите в заданий нужно только преопределить стили и нужно изменять свойств и значений в некоторых местах или как? никак не могу проити уже 3-й день

Стили (свойства) изменять нельзя, можно менять только селекторы.

Добрый день . Я выслал мой код, мне кажется он слишком “читерный” ? Могли бы посмотреть ?

html,
body{
margin: 0;
padding: 0;
}

body {
width: 550px;
height: 300px;
font-size: 12px;
font-family: “Tahoma”, “Arial”, sans-serif;
}

.profile {
padding: 5px 10px;
}

.profile img {
display: block;
padding: 10px;
border: 2px solid #34495e;
border-radius: 8px;
}

.profile .photo {
float: left;
width: 152px;
}

.profile .info {
float: left;
width: 368px;
margin-left: 10px;
}

.info h2 {
margin: 0 !important ;
padding: 10px !important ;

font-weight: normal;
font-size: 12px;
color: #ffffff;
background: #34495e;
border-radius: 4px;
}

.profile div.fact {
padding: 10px;
background: white;

}

.profile .fact:nth-child(odd) {
background: #ecf0f1;
}

.fact::after {
content: “”;
display: table;
clear: both;
}

.profile .fact .title {
float: left;
width: 120px;
text-align: right;
color: #7f8c8d;
}

.profile .fact .value {
margin-left: 140px;
color: #34495e;
}

.albums {
margin-top: 5px;
}

#miska, .albums img {
float: left;
margin-right: 5px;
}

.albums img:last-child {
margin-right: 0;
}

.profile .button {
display: block;
height: 30px;
margin: 5px 0;

line-height: 30px;
text-align: center;
color: #ffffff;
border-radius: 4px;
}

.stroke.button {
background: #3498db;
}

.feed.button {
background: #2ecc71;
}

.startle.button {
background: #e74c3c;
}

#info-title {
background:#34495e;
}

Может кому-нибудь понадобится. 100% выдает.

html,
body {
margin: 0;
padding: 0;
}

body {
width: 550px;
height: 300px;
font-size: 12px;
font-family: “Tahoma”, “Arial”, sans-serif;
}

.profile {
padding: 5px 10px;
}

.profile img {
display: block;
padding: 10px;
border: 2px solid #34495e;
border-radius: 8px;
}

.profile .photo {
float: left;
width: 152px;
}

.profile .info {
float: left;
width: 368px;
margin-left: 10px;
}

.info h2 {
margin: 0 !important;
padding: 10px !important;

font-weight: normal;
font-size: 12px;
color: #ffffff;
background: #34495e !important;
border-radius: 4px;
}

.profile .info .fact {
padding: 10px;
background: white;
}

.profile .info .fact:nth-child(odd) {
background: #ecf0f1;
}

.fact::after {
content: “”;
display: table;
clear: both;
}

.profile .info .fact .title {
float: left;
width: 120px;
text-align: right;
color: #7f8c8d;
}

.profile .info .fact .value {
margin-left: 140px;
color: #34495e;
}

.albums img:nth-child(3) {
margin-top: 5px;
margin-left: -45px;

}

.albums img {
margin-top: 5px;
float: left;
margin-right: 5px; /было 5/

}

.albums img:last-child {
margin-right: 0px;
}

.profile .photo .button {
display: block;
height: 30px;
margin: 5px 0;

line-height: 30px;
text-align: center;
color: #ffffff;
border-radius: 4px;
}

.profile .photo .stroke {
background: #3498db;
}

.profile .photo .feed {
background: #2ecc71;
}

.profile .photo .startle {
background: #e74c3c;
}

Пришлось повозиться :pensive:

мой котопрофайл
html,
body {
  margin: 0;
  padding: 0;
}

body {
  width: 550px;
  height: 300px;
  font-size: 12px;
  font-family: "Tahoma", "Arial", sans-serif;
}

.profile {
  padding: 5px 10px;
}

.profile img {
  display: block;
  padding: 10px;
  border: 2px solid #34495e;
  border-radius: 8px;
}

.profile .photo {
  float: left;
  width: 152px;
}

.profile .info {
  float: left;
  width: 368px;
  margin-left: 10px;
}

#info-title, 
h2 {
  margin: 0 !important;
  padding: 10px !important;

  font-weight: normal;
  font-size: 12px;
  color: #ffffff;
  background: #34495e;
  border-radius: 4px;
}

.profile .info .fact {
  padding: 10px;
  background: white;
}

.profile .info .fact:nth-child(odd) {
  background: #ecf0f1;
}

.fact::after {
  content: "";
  display: table;
  clear: both;
}

.profile .fact .title {
  float: left;
  width: 120px;
  text-align: right;
  color: #7f8c8d;
}

.profile .fact .value {
  margin-left: 140px;
  color: #34495e;
}

.albums {
  margin-top: 5px;
}

.albums img,
#miska {
  float: left;
  margin-right: 5px;
}

.albums img:last-child {
  margin-right: 0;
}

.profile .button {
  display: block;
  height: 30px;
  margin: 5px 0;

  line-height: 30px;
  text-align: center;
  color: #ffffff;
  border-radius: 4px;
}

.photo .stroke {
  background: #3498db;
}

.photo .feed {
  background: #2ecc71;
}

.photo .startle {
  background: #e74c3c;
}

[Получилось вот так, дало 100%.]
html,
body {
margin: 0;
padding: 0;
}

body {
width: 550px;
height: 300px;
font-size: 12px;
font-family: “Tahoma”, “Arial”, sans-serif;
}

.profile {
padding: 5px 10px;
}

.profile img {
display: block;
padding: 10px;
border: 2px solid #34495e;
border-radius: 8px;
}

.profile .photo {
float: left;
width: 152px;
}

.profile .info {
float: left;
width: 368px;
margin-left: 10px;
}

#info-title,
.info h2 {
margin: 0 !important;
padding: 10px !important;
font-weight: normal;
font-size: 12px;
color: #ffffff;
background: #34495e;
border-radius: 4px;
}

.profile .info .fact {
padding: 10px;
background: white;
}

.info .fact:nth-child(odd) {
background: #ecf0f1;
}

.info .fact::after {
content: “”;
display: table;
clear: both;
}

.profile .info .fact .title {
float: left;
width: 120px;
text-align: right;
color: #7f8c8d;
}

.profile .info .fact .value {
margin-left: 140px;
color: #34495e;
}

.albums {
margin-top: 5px;
}

.albums img, #miska{
float: left;
margin-right: 5px;
}

.albums img:last-child {
margin-right: 0;
}

.profile .photo .button {
display: block;
height: 30px;
margin: 5px 0;
line-height: 30px;
text-align: center;
color: #ffffff;
border-radius: 4px;
}

.profile .button.stroke {
background: #3498db;
}

.profile .button.feed {
background: #2ecc71;
}

.profile .button.startle {
background: #e74c3c;
}

И возник вопрос при точном указании .profile .photo или других которые не были прописаны в мы ведь можем опустить полное указание всех элементов и насколько это будет правильно при длинных кодах ? Чисто теоритически, понятно что редко в HTML указывается, но все же.

Всю цепочку указывать не надо. Чем короче селектор (насколько это возможно), тем лучше.

Подскажите почему так не работает? Выдает 92%

.albums img{
  float: left;
  margin-right: 5px !important;
}

А так работает.

.albums img, #miska{
  float: left;
  margin-right: 5px;
}

Пришлите весь код целиком.

html,
body {
  margin: 0;
  padding: 0;
}

body {
  width: 550px;
  height: 300px;
  font-size: 12px;
  font-family: "Tahoma", "Arial", sans-serif;
}

.profile {
  padding: 5px 10px;
}

.profile img {
  display: block;
  padding: 10px;
  border: 2px solid #34495e;
  border-radius: 8px;
}

.profile .photo {
  float: left;
  width: 152px;
}

.profile .info {
  float: left;
  width: 368px;
  margin-left: 10px;
}

.info #info-title, .info h2{
  margin: 0 !important;
  padding: 10px !important;

  font-weight: normal;
  font-size: 12px;
  color: #ffffff;
  background: #34495e;
  border-radius: 4px;
}

.profile div.fact {
  padding: 10px;
  background: white;
}

.profile div.fact:nth-child(odd) {
  background: #ecf0f1;
}

.fact::after {
  content: "";
  display: table;
  clear: both;
}

.profile div.fact .title {
  float: left;
  width: 120px;
  text-align: right;
  color: #7f8c8d;
}

.profile div.fact .value {
  margin-left: 140px;
  color: #34495e;
}

.albums {
  margin-top: 5px;
}
/*------------------------Вот здесь если убрать выбор по индентификатору и вставить  !important, то не работает*/
.albums img, #miska{
  float: left;
  margin-right: 5px;
}

.albums img:last-child {
  margin-right: 0;
}

.photo .button {
  display: block;
  height: 30px;
  margin: 5px 0;

  line-height: 30px;
  text-align: center;
  color: #ffffff;
  border-radius: 4px;
}

.profile .stroke {
  background: #3498db;
}

.profile .feed {
  background: #2ecc71;
}

.profile .startle {
  background: #e74c3c;
}

Обратите внимание на следующее после .albums img свойство — .albums img:last-child. Там задаётся нулевой маргин для последней картинки, а используя !important, вы его переопределяете. Поэтому он становится 5px, и все картинки уже не помещаются в одни ряд. Можно и у .albums img:last-child переопределить на ноль с помощью !important, конечно, тогда всё сработает. Но практика использования для стилизации !important — нехорошее дело, так что лучше остановитесь на рабочем варианте с селектором по id.

Спасибо, вот это я не учел.

1 лайк

подскажите пожалуйста

.stroke {
background: #3498db;
}

.feed {
background: #2ecc71;
}

.startle {
background: #e74c3c;
}

вот изначальный блок кода , который отображается при начале задания. Если сюда дописать по второму селектору по классу, то цвета станут как на примере, как нам и нужно, только я не могу понять почему так?? Тут же нету никакого конфликта стилей, задается и так каждый класс которые имеют разные имена стиль цвета. Подскажите пожалуйста, не могу понять