2014-04-16 4 views
0

누군가가 메뉴 탭을 가리킬 때마다 메뉴 탭이 슬라이드되도록 클라이언트의 요청을 받았습니다.슬라이딩 메뉴 탭

지금은 li.active 롤과 li : hover 롤이 있습니다.

활성 메뉴가 아닌 메뉴 탭에서 마우스를 가져갈 때 활성 메뉴가 스타일을 적절하게 변경한다는 롤 정의 방법을 모르겠습니다.

심지어 가능합니까?

+0

슬라이드 어떻게, 어디서? 아마도 현재 HTML과 CSS를 보여주고 JSFiddle을 만들 수도 있습니다. –

+0

여기에 게시 된 예제는 슬라이드와 견인되지 않은 호버 효과가 하나만 필요하다는 점에서 매우 가깝습니다. 다른 대답에 대한 내 의견을 참조하십시오. – theguy

+0

나는이 게시물을 찾았습니다. -> http://stackoverflow.com/questions/11603980/hover-effect-on-another-class-in-css 내가 필요로하는 것이지만 그것은 저에게 효과적이지 않았습니다. # sp-main-menu ul.level-0> li : hover> a # sp-main-menu ul.level-0> li.active> a { background : transparent! important; \t} – theguy

답변

0

이와 비슷한? HTML

@theguy

<ul class="menu"> 
    <li><a href="#" class="active">Option1</a></li> 
    <li><a href="#">Option2</a></li> 
    <li><a href="#">Option3</a></li> 
    <li><a href="#">Option4</a></li> 
    <li class="slider"></li> 
</ul> 

CSS

다음
@import url(http://fonts.googleapis.com/css?family=PT+Sans); 
* { 
    -webkit-box-sizing: border-box; 
    -moz-box-sizing: border-box; 
    box-sizing: border-box; 
} 
html, 
body { 
    margin: 0; 
    padding: 0; 
} 
body { 
    font-family: 'PT Sans', Arial, Verdana; 
    background-color: #eee; 
} 
h1 { 
    text-align: center; 
    font-size: 48px; 
    text-transform: uppercase; 
    letter-spacing: 3px; 
    color: #222; 
} 
.menu { 
    list-style: none; 
    margin: 0; 
    padding: 0; 
    width: 100%; 
    height: 120px; 
    margin: auto; 
    position: relative; 
    background-color: #2c3e50; 
    z-index: 7; 
} 
.menu li { 
    float: left; 
    width: 25%; 
    height: 100%; 
    margin: 0; 
    padding: 0; 
} 
.menu a { 
    display: -webkit-box; 
    display: -webkit-flex; 
    display: -ms-flexbox; 
    display: flex; 
    width: 100%; 
    height: 100%; 
    -webkit-box-pack: center; 
    -webkit-justify-content: center; 
    -ms-flex-pack: center; 
    justify-content: center; 
    -webkit-box-align: center; 
    -webkit-align-items: center; 
    -ms-flex-align: center; 
    align-items: center; 
    color: #fff; 
    text-decoration: none; 
    position: relative; 
    font-size: 18px; 
    z-index: 9; 
} 
a.active { 
    background-color: #e74c3c; 
    pointer-events: none; 
} 
li.slider { 
    width: 25%; 
    height: 100%; 
    position: absolute; 
    left: 0; 
    top: 0; 
    background-color: #e74c3c; 
    z-index: 8; 
    -webkit-transition: left 0.4s, background-color 0.4s; 
    transition: left 0.4s, background-color 0.4s; 
} 
.menu li:nth-child(1):hover ~ .slider, 
.menu li:nth-child(1):focus ~ .slider, 
.menu li:nth-child(1):active ~ .slider { 
    left: 0; 
    background-color: #3498db; 
} 
.menu li:nth-child(2):hover ~ .slider, 
.menu li:nth-child(2):focus ~ .slider, 
.menu li:nth-child(2):active ~ .slider { 
    left: 25%; 
    background-color: purple; 
} 
.menu li:nth-child(3):hover ~ .slider, 
.menu li:nth-child(3):focus ~ .slider, 
.menu li:nth-child(3):active ~ .slider { 
    left: 50%; 
    background-color: #e67e22; 
} 
.menu li:nth-child(4):hover ~ .slider, 
.menu li:nth-child(4):focus ~ .slider, 
.menu li:nth-child(4):active ~ .slider { 
    left: 75%; 
    background-color: #16a085; 
} 

당신이 JSfiddle 있습니다 http://jsfiddle.net/luiggi/Ugyh8/

+0

감사합니다. 이것은 내가 필요한 것에 아주 가깝다. 유일한 점은 클라이언트가 전체 상자를 이동하도록 요청했기 때문입니다. 이 데모에서는 탭이 끝났지 만 활성화 된 항목은 계속 표시됩니다. 그래서 당신은 2 개의 호버 박스를 얻습니다. 마우스를 가져 가면 슬라이드가 하나만 있어야합니다. – theguy

+0

내가 실제로 알아야 할 것은 다른 li 탭 위로 마우스를 가져 가면 li.active 탭 스타일을 제거하는 방법입니다. – theguy

+0

나는 가까이 있지만 아직 거기에 없다고 느낍니다. 이것을 시도했지만 잘 작동하지 않았습니다 : # sp-main-menu ul.level-0> li : hover # sp-main-menu ul.level-0> li.active { background : transparent! important; } – theguy