Добавление подчеркивания на панель навигации с помощью CSS - PullRequest
0 голосов
/ 26 мая 2020

Я бы хотел, чтобы получилось так: левая и правая желтые линии разделены на ширину контейнера

enter image description here

enter image description here

Я ошибаюсь Я сейчас

enter image description here

Это мой css и html что у меня

nav>a:nth-child(1) {
  width: 88px;
  color: #000000b8;
  font-size: 17px;
  font-weight: bold;
  padding: 0px 18px;
  text-decoration: none;
  pointer-events: initial;
  line-height: 25px;
  position: relative;
  display: inline-block;
}

nav>a:nth-child(2) {
  width: 88px;
  color: #000000b8;
  font-size: 17px;
  font-weight: bold;
  padding: 0px 18px;
  text-decoration: none;
  pointer-events: initial;
  line-height: 25px;
  position: relative;
  display: inline-block;
}

nav>a:nth-child(1):after {
  content: '';
  width: 100%;
  height: 3px;
  position: absolute;
  left: -16px;
  bottom: -12px;
  margin-left: 0px;
  background-color: #ffc107;
  display: block;
}
<nav class="navbar navbar-fixed-top">
  <a href="/popular" class="mapxr">Popular</a>
  <a href="/ect" class="mapxr">ect</a>
</nav>

Ответы [ 2 ]

1 голос
/ 26 мая 2020

Да, вам нужно сделать контейнер navbar с display: flex; и добавить ширину 50% к дочерним div. См. Здесь:

Также я добавил text-align:center; каждому дочернему элементу, чтобы он был центрирован.

nav > a:nth-child(1){
width: 88px;
color: #000000b8;
font-size: 17px;
font-weight: bold;
padding: 0px 18px;
text-decoration: none;
pointer-events: initial;
line-height: 25px;
position: relative;
display: inline-block;
width: 50%;
text-align: center;
}


nav > a:nth-child(2){
width: 88px;
color: #000000b8;
font-size: 17px;
font-weight: bold;
padding: 0px 18px;
text-decoration: none;
pointer-events: initial;
line-height: 25px;
position: relative;
display: inline-block;
width: 50%;
text-align: center;
}


nav > a:nth-child(1):after{
content: '';
width: 100%;
height: 3px;
position: absolute;
left: -16px;
bottom: -12px;
margin-left: 0px;
background-color: #ffc107;
display: block;
}

.navbar {
  display: flex;
  position: relative;
}
<nav class="navbar navbar-fixed-top">
<a href="/popular" class="mapxr">Popular</a>
<a href="/ect" class="mapxr">ect</a>
</nav>
0 голосов
/ 26 мая 2020

Правильно?

<style>
nav > a:nth-child(n){
width:88px;
color: #000000b8;
font-size: 17px;
font-weight: bold;
text-decoration: none;
pointer-events: initial;
line-height: 25px;
position: relative;
display: inline-block;
}

a{
  text-align:center;
}

nav > a:nth-child(1):after{
content: '';
width: 100%;
height: 3px;
position: absolute;
background-color: #ffc107;
display: block;
}

</style>

<nav class="navbar navbar-fixed-top">
<a href="/popular" onclick='return false' class="mapxr">Popular</a>
<a href="/ect" onclick='return false' class="mapxr">ect</a>
</nav>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...