简体   繁体   English

下划线时,反射不应移动

[英]Reflection should not move at hover with underline

My goal is that when the user hovers over the nav the underline should not move the reflection. 我的目标是,当用户将鼠标悬停在导航上方时,下划线不应移动反射。 It should just overlay the reflection. 它应该只是覆盖反射。 At the moment as soon i hover over the nav elements the underline pushes down the reflection. 此刻,当我将鼠标悬停在导航元素上时,下划线会降低反射。 How can I change this? 我该如何更改?

I have this code: 我有以下代码:

HTML 的HTML

<div class="container">
    <header>
        <img id="logo" src="http://placekitten.com/440/53"></img>
        <div id="header-address">
            <ul>
                <li>Hagartenstrasse 16 <span> T 032 672 35 84</span></li>
                <li>4562 Biberist <span> F 032 672 15 22</span></li>
                <li>info@malerei-hubler.ch <span> M 079 251 23 22</span></li>
            </ul>
        </div>
    </header>
    <nav>
        <ul>
            <li id="reflect" class="navp txtRot"><h1>HOME</h1></li>
            <li id="reflect" class="navp txtOrange"><h1>ANGEBOT</h1></li>
            <li id="reflect" class="navp txtGelb"><h1>TEAM</h1></li>
            <li id="reflect" class="navp txtGruen"><h1>UMWELT</h1></li>
            <li id="reflect" class="txtBlau"><h1>KONTAKT</h1></li>
        </ul>
    </nav>
</div>

CSS 的CSS

* {
    margin: 0px;
    padding: 0px;
}

body, html, ul, li, h1 {
    font-family: 'Titillium Web', sans-serif;
    font-size: 100%;
    line-height: 1em;
}
.container {
    width: 900px;
    height: 100vh;
    margin: 0 auto;
}
h1, h2, h3 {
    font-weight: 600;
}

.txtRot {
    color: #e60004;
}
.txtOrange {
    color: #f28e00;
}
.txtGelb {
    color: #f0d80e;
}

.txtGruen {
    color: #009836;
}
.txtBlau {
    color: #0068b5;
}

header {
    margin-top: 56px;
}

ul {
    padding: 0px;
}

/* HEADER */ 
#logo {
    height: 100%;
    float: left;
}

#header-address {
    font-weight: 400;
    font-style: italic;
    font-size: 14px;
}
#header-address ul {
    list-style: none;
    float: right;
}
#header-address ul li {
    line-height: 19px;
    text-transform: uppercase;
}#header-address ul li span {
    line-height: 19px;
    float: right;
    padding-left: 5px;
}
nav {
    float: left;
    margin-top: 60px;
    margin-left: 0px;
}
nav ul li  {
    display: inline-block;
    list-style: none;
    height: 100%;
}
nav ul li h1  {
    font-size: 40px;
    font-weight: 600;
    height: 100%;
    padding:0px;
}
/* PADDING FOR NAV */
.navp {
    padding-right: 46.4px;
    height: 100%;
}

#reflect h1:hover {
    border-bottom: 4px solid;

}
#reflect {
    position: relative;
    -webkit-box-reflect: below -3px -webkit-linear-gradient(bottom, rgba(255, 255, 255, 0.1) 0%, transparent 70%, transparent 100%);
}


#reflect:before {
    background: -moz-linear-gradient(center top, #FFFFFF, #FFFFFF 30%, rgba(255, 255, 255, 0.9) 65%, rgba(255, 255, 255, 0.7)) repeat scroll 0 0 padding-box, -moz-element(#reflect) no-repeat scroll 0 -127px content-box rgba(0, 0, 0, 0);
    content: "";
    height: 140px;
    left: 0;
    position: absolute;
    top: 277px;
    -webkit-transform: scaleY(-1);
    transform: scaleY(-1);
    width: 360px;
}

Here is the codepen: 这是codepen:

http://codepen.io/patrickhofer/pen/JKdgVN http://codepen.io/patrickhofer/pen/JKdgVN

Any help much appreciated. 任何帮助,不胜感激。

It should look like this: 它看起来应该像这样:

在此处输入图片说明

You have to give a specific height to navp . 您必须给navp指定一个特定的高度。 You can try changing your .navp like this: 您可以尝试如下更改.navp

.navp {
   padding-right: 46.4px;
   height: 40px;
   margin-bottom:7px;
 }

Set

#reflect h1 {
    border-bottom: 4px solid transparent;

}
#reflect h1:hover{
    border-bottom: 4px solid currentcolor;

}

Note you can not have multiple ID in the same document read ID selectors 注意,在同一文档中不能有多个ID读取ID选择器

Defines a unique identifier (ID) which must be unique in the whole document. 定义在整个文档中必须唯一的唯一标识符(ID)。 Its purpose is to identify the element when linking (using a fragment identifier), scripting, or styling (with CSS). 其目的是在链接(使用片段标识符),脚本或样式(使用CSS)时标识元素。

so the final result shall look like this 所以最终结果应该像这样

 /* http://meyerweb.com/eric/tools/css/reset/ v2.0 | 20110126 License: none (public domain) */ /*Reset Safari User Agent Styles*/ * { margin: 0px; padding: 0px; } body, html, ul, li, h1 { font-family: 'Titillium Web', sans-serif; font-size: 100%; line-height: 1em; } .container { width: 900px; height: 100vh; margin: 0 auto; } h1, h2, h3 { font-weight: 600; } .txtRot { color: #e60004; } .txtOrange { color: #f28e00; } .txtGelb { color: #f0d80e; } .txtGruen { color: #009836; } .txtBlau { color: #0068b5; } header { margin-top: 56px; } ul { padding: 0px; } /* HEADER */ #logo { height: 100%; float: left; } #header-address { font-weight: 400; font-style: italic; font-size: 14px; } #header-address ul { list-style: none; float: right; } #header-address ul li { line-height: 19px; text-transform: uppercase; } #header-address ul li span { line-height: 19px; float: right; padding-left: 5px; } nav { float: left; margin-top: 60px; margin-left: 0px; } nav ul li { display: inline-block; list-style: none; margin-bottom: 50px; } nav ul li h1 { font-size: 40px; font-weight: 600; height: 100%; padding: 0px; } /* PADDING FOR NAV */ .navp { padding-right: 46.4px; height: 100%; } .reflect h1 { border-bottom: 4px solid transparent; } .reflect h1:hover { border-bottom: 4px solid currentcolor; } .reflect { position: relative; -webkit-box-reflect: below -3px -webkit-linear-gradient(bottom, rgba(255, 255, 255, 0.1) 0%, transparent 70%, transparent 100%); } .reflect:before { background: -moz-linear-gradient(center top, #FFFFFF, #FFFFFF 30%, rgba(255, 255, 255, 0.9) 65%, rgba(255, 255, 255, 0.7)) repeat scroll 0 0 padding-box, -moz-element(#reflect) no-repeat scroll 0 -127px content-box rgba(0, 0, 0, 0); content: ""; height: 140px; left: 0; position: absolute; top: 277px; -webkit-transform: scaleY(-1); transform: scaleY(-1); width: 360px; } 
 <div class="container"> <header> <img id="logo" src="http://placekitten.com/440/53"></img> <div id="header-address"> <ul> <li>Hagartenstrasse 16 <span> T 032 672 35 84</span> </li> <li>4562 Biberist <span> F 032 672 15 22</span> </li> <li>info@malerei-hubler.ch <span> M 079 251 23 22</span> </li> </ul> </div> </header> <nav> <ul> <li class="reflect navp txtRot"> <h1>HOME</h1> </li> <li class="reflect navp txtOrange"> <h1>ANGEBOT</h1> </li> <li class="reflect navp txtGelb"> <h1>TEAM</h1> </li> <li class="reflect navp txtGruen"> <h1>UMWELT</h1> </li> <li class="reflect txtBlau"> <h1>KONTAKT</h1> </li> </ul> </nav> </div> 

you can use box-shadow too 你也可以使用阴影

.reflect h1:hover {
    box-shadow: 0 4px;
}

that will look like this 看起来像这样

 * { margin: 0px; padding: 0px; } body, html, ul, li, h1 { font-family: 'Titillium Web', sans-serif; font-size: 100%; line-height: 1em; } .container { width: 900px; height: 100vh; margin: 0 auto; } h1, h2, h3 { font-weight: 600; } .txtRot { color: #e60004; } .txtOrange { color: #f28e00; } .txtGelb { color: #f0d80e; } .txtGruen { color: #009836; } .txtBlau { color: #0068b5; } header { margin-top: 56px; } ul { padding: 0px; } /* HEADER */ #logo { height: 100%; float: left; } #header-address { font-weight: 400; font-style: italic; font-size: 14px; } #header-address ul { list-style: none; float: right; } #header-address ul li { line-height: 19px; text-transform: uppercase; } #header-address ul li span { line-height: 19px; float: right; padding-left: 5px; } nav { float: left; margin-top: 60px; margin-left: 0px; } nav ul li { display: inline-block; list-style: none; margin-bottom: 50px; } nav ul li h1 { font-size: 40px; font-weight: 600; height: 100%; padding: 0px; } /* PADDING FOR NAV */ .navp { padding-right: 46.4px; height: 100%; } .reflect h1:hover { box-shadow: 0 4px; } .reflect { position: relative; -webkit-box-reflect: below -3px -webkit-linear-gradient(bottom, rgba(255, 255, 255, 0.1) 0%, transparent 70%, transparent 100%); } .reflect:before { background: -moz-linear-gradient(center top, #FFFFFF, #FFFFFF 30%, rgba(255, 255, 255, 0.9) 65%, rgba(255, 255, 255, 0.7)) repeat scroll 0 0 padding-box, -moz-element(#reflect) no-repeat scroll 0 -127px content-box rgba(0, 0, 0, 0); content: ""; height: 140px; left: 0; position: absolute; top: 277px; -webkit-transform: scaleY(-1); transform: scaleY(-1); width: 360px; } 
 <div class="container"> <header> <img id="logo" src="http://placekitten.com/440/53" /> <div id="header-address"> <ul> <li>Hagartenstrasse 16 <span> T 032 672 35 84</span> </li> <li>4562 Biberist <span> F 032 672 15 22</span> </li> <li>info@malerei-hubler.ch <span> M 079 251 23 22</span> </li> </ul> </div> </header> <nav> <ul> <li class="reflect navp txtRot"> <h1>HOME</h1> </li> <li class="reflect navp txtOrange"> <h1>ANGEBOT</h1> </li> <li class="reflect navp txtGelb"> <h1>TEAM</h1> </li> <li class="reflect navp txtGruen"> <h1>UMWELT</h1> </li> <li class="reflect txtBlau"> <h1>KONTAKT</h1> </li> </ul> </nav> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM