Jump to content
  • 0

background-position c background не должен работать ?


iillyyaa2
 Share

Question

background-position c background не должен работать ?

почему второй див не работает ??

<style>
div.all {
display:block;
position: relative;
width:100px;
height:100px;
background:url(9x100.png);
cursor:pointer;
}
.background_position_300_0{
background-position: 300px 0px;
}
</style>

<div class="all" style="background-position: 300px 0px"></div>
<div class="all background_position_300_0"></div>

а вот так работают правильно оба дива:

<style>
div.all {
display:block;
position: relative;
width:100px;
height:100px;
background-image:url(9x100.png);
cursor:pointer;
}
.background_position_300_0{
background-position: 300px 0px;
}
</style>

<div class="all" style="background-position: 300px 0px"></div>
<div class="all background_position_300_0"></div>

(в коде изменены только background на background-image)

почему так ?

Edited by iillyyaa2
Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

Потому что div.all - более мощное правило с большим приоритетом. Так будет работать:


.all {
display:block;
position: relative;
width:100px;
height:100px;
background:url(9x100.png);
cursor:pointer;
}
.background_position_300_0{
background-position: 300px 0px;
}

или так:


div.all {
display:block;
position: relative;
width:100px;
height:100px;
background:url(9x100.png);
cursor:pointer;
}
div.background_position_300_0{
background-position: 300px 0px;
}

рекомендую первый вариант.

  • Like 1
Link to comment
Share on other sites

  • 0

вот ещё такой вопрос...

.all {
display:block;
position: relative;
width:450px;
height:60px;
background:url(900x420.png) no-repeat;
cursor:pointer;
}
.background_position_0_0{
background-position: 0px 0px;
}
.background_position_0_60{
background-position: 0px -60px;
}
.background_position_0_0:hover{
background-position: -450px 0px;
}
.background_position_0_60:hover{
background-position: -450px -60px;
}

<div class="all background_position_0_0"></div>
<div class="all background_position_0_60"></div>

всё работает, вот только напрягает большое кол-во .background_position_0_0:hover

можно как то в одну строчку им задать ? ;)

как поменять только смещение по х ?

background-position-x не предлагать, т.к. он не во всех браузерах работает ;)

Edited by iillyyaa2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy