简体   繁体   English

CSS边框:hover元素

[英]Css border to :hover element

I'm new to css. 我是CSS的新手。 I want to make a replica of the menu (excluding the sub-menu part) on this page: http://www.ibta-arabia.com/ 我要在此页面上复制菜单(不包括子菜单部分): http : //www.ibta-arabia.com/

This is my progress so far: https://jsfiddle.net/yny2u85j/ 到目前为止,这是我的进步: https : //jsfiddle.net/yny2u85j/

This is my code for the css: 这是我的CSS代码:

.menu {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
}

.topnav {
    overflow: hidden;
    background-color: #2C4059;
}

.topnav a {
    float: left;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
    font-size: 17px;
}

.topnav a:hover {
    background-color: #D90D29;
    color: white;
}

.topnav a.active {
    background-color: #4CAF50;
    color: white;
}

I'm unable to show a red line when the mouse is hovered on the menu and put separators among the menu content as on the website I linked. 当鼠标悬停在菜单上并将分隔符放在菜单内容之间时,我无法显示红线,就像我链接的网站一样。

Can anyone help me tweak my css code to look more the menu on the other website? 谁能帮助我调整CSS代码,以在其他网站上查看更多菜单?

Here you can just use css pseudo elements to show the border on top: Here is you updated fiddle code: https://jsfiddle.net/yny2u85j/11/ and also remove border property to anchor. 在这里,您可以仅使用css伪元素在顶部显示边框:在这里,您更新了小提琴代码: https://jsfiddle.net/yny2u85j/11/https://jsfiddle.net/yny2u85j/11/ ,还删除了border属性以进行锚定。

 .menu { margin: 0; font-family: Arial, Helvetica, sans-serif; } .topnav { overflow: hidden; background-color: #2C4059; } .topnav a { float: left; color: white; text-align: center; padding: 14px 16px; text-decoration: none; font-size: 17px; position: relative; } .topnav a:before { content: ''; width: 100%; opacity: 0; transition: all ease .3s; background: #D90D29; position: absolute; top: 0; left: 0; height: 3px; } .topnav a:hover:before { transition: all ease .3s; opacity: 1; } .topnav a.active { background-color: #4CAF50; color: white; } 
 <div class="menu"> <div class="topnav"> <a href="#">&nbsp;</a> <a href="http://www.ibta-arabia.com/"><strong>Home</strong></a> <a href="http://www.ibta-arabia.com/contact-us/"><strong>Contact Us</strong></a> </div> </div> 

在.topnav a中添加border-top:2px纯透明,然后在.topnav a:hover和.topnav a:active中添加border-top-color:#D90D29

Check updated code with simple border style 使用简单的边框样式检查更新的代码

 .menu { margin: 0; font-family: Arial, Helvetica, sans-serif; } .topnav { overflow: hidden; background-color: #2C4059; } .topnav a { float: left; color: white; text-align: center; padding: 14px 16px; text-decoration: none; font-size: 17px; border-top: 4px solid transparent; border-bottom: 4px solid transparent; } .topnav a:hover { /*background-color: #D90D29; color: white; */ border-top: 4px solid #d90d29; } .topnav a.active { background-color: #4CAF50; color: white; } 
 <div class="menu"> <div class="topnav"> <a href="#">&nbsp;</a> <a href="http://www.ibta-arabia.com/"><strong>Home</strong></a> <a href="http://www.ibta-arabia.com/contact-us/"><strong>Contact Us</strong></a> </div> </div> 

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

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