css 문의드립니다...ㅜㅜ 채택완료
구현하려고하는것은 메뉴와 메뉴사이에 작은 선을 넣으려고 하는데 안되네요...
border-right 로 넣으면 위아래 선이 너무 꽉차서 안이뻐서
after { content: ""; width: 5px; height: 16px;..........이걸 이용해서 넣으려고하는데
메뉴와 메뉴사이에 안들어가고 저렇게 글씨 옆에만 붙어버리네요..
이런저런 방법을 다 시도하고 있는데 안되서 문의드립니다..ㅜㅜ
http://sir.kr/data/editor/2503/974992987_1742292034.428.jpg" width="100%" />
소스---------------------
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js'></script>
<title>Sticky Slider Navigation (Responsive)</title>
<style>
body {
font-family: "Century Gothic", "Lato", sans-serif;
}
a {
text-decoration: none;
}
.et-hero-tabs,
.et-slide {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
position: relative;
background: #eee;
text-align: center;
padding: 0 2em;
}
.et-hero-tabs h1,
.et-slide h1 {
font-size: 2rem;
margin: 0;
letter-spacing: 1rem;
}
.et-hero-tabs h3,
.et-slide h3 {
font-size: 1rem;
letter-spacing: 0.3rem;
opacity: 0.6;
}
.et-hero-tabs-container {
display: flex;
flex-direction: row;
position: absolute;
bottom: 0;
width: 100%;
height: 70px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
background: #fff;
z-index: 10;
}
.et-hero-tabs-container--top {
position: fixed;
top: 0;
}
.et-hero-tab {
display: flex;
justify-content: center;
align-items: center;
flex: 1;
color: #000;
letter-spacing: 0.1rem;
transition: all 0.5s ease;
font-size: 0.8rem;
}
.et-hero-tab:hover {
color: white;
background: rgba(102, 177, 241, 0.8);
transition: all 0.5s ease;
}
.et-hero-tab-slider {
position: absolute;
bottom: 0;
width: 0;
height: 6px;
background: #66B1F1;
transition: left 0.3s ease;
}
@media (min-width: 800px) {
.et-hero-tabs h1,
.et-slide h1 {
font-size: 3rem;
}
.et-hero-tabs h3,
.et-slide h3 {
font-size: 1rem;
}
.et-hero-tab {
font-size: 1rem;
}
}
.et-hero-tab:after { content: ""; width: 5px; height: 16px; background: #000; left: 10; right: 10; top: 40%; transform: translateY(-50%); }
</style>
</head>
<body translate="no">
<!-- Hero -->
<section class="et-hero-tabs">
<h1>STICKY SLIDER NAV</h1>
<h3>Sliding content with sticky tab nav</h3>
<div class="et-hero-tabs-container">
<a class="et-hero-tab" href="#tab-es6">ES6</a>
<a class="et-hero-tab" href="#tab-flexbox">Flexbox</a>
<a class="et-hero-tab" href="#tab-react">React</a>
<a class="et-hero-tab" href="#tab-angular">Angular</a>
<a class="et-hero-tab" href="#tab-other">Other</a>
<span class="et-hero-tab-slider"></span>
</div>
</section>
<!-- Main -->
<main class="et-main">
<section class="et-slide" id="tab-es6">
<h1>ES6</h1>
<h3>something about es6</h3>
</section>
<section class="et-slide" id="tab-flexbox">
<h1>Flexbox</h1>
<h3>something about flexbox</h3>
</section>
<section class="et-slide" id="tab-react">
<h1>React</h1>
<h3>something about react</h3>
</section>
<section class="et-slide" id="tab-angular">
<h1>Angular</h1>
<h3>something about angular</h3>
</section>
<section class="et-slide" id="tab-other">
<h1>Other</h1>
<h3>something about other</h3>
</section>
</main>
<script id="rendered-js" >
class StickyNavigation {
constructor() {
this.currentId = null;
this.currentTab = null;
this.tabContainerHeight = 70;
let self = this;
$('.et-hero-tab').click(function () {
self.onTabClick(event, $(this));
});
$(window).scroll(() => {this.onScroll();});
$(window).resize(() => {this.onResize();});
}
onTabClick(event, element) {
event.preventDefault();
let scrollTop = $(element.attr('href')).offset().top - this.tabContainerHeight + 1;
$('html, body').animate({ scrollTop: scrollTop }, 600);
}
onScroll() {
this.checkTabContainerPosition();
this.findCurrentTabSelector();
}
onResize() {
if (this.currentId) {
this.setSliderCss();
}
}
checkTabContainerPosition() {
let offset = $('.et-hero-tabs').offset().top + $('.et-hero-tabs').height() - this.tabContainerHeight;
if ($(window).scrollTop() > offset) {
$('.et-hero-tabs-container').addClass('et-hero-tabs-container--top');
} else
{
$('.et-hero-tabs-container').removeClass('et-hero-tabs-container--top');
}
}
findCurrentTabSelector(element) {
let newCurrentId;
let newCurrentTab;
let self = this;
$('.et-hero-tab').each(function () {
let id = $(this).attr('href');
let offsetTop = $(id).offset().top - self.tabContainerHeight;
let offsetBottom = $(id).offset().top + $(id).height() - self.tabContainerHeight;
if ($(window).scrollTop() > offsetTop && $(window).scrollTop() < offsetBottom) {
newCurrentId = id;
newCurrentTab = $(this);
}
});
if (this.currentId != newCurrentId || this.currentId === null) {
this.currentId = newCurrentId;
this.currentTab = newCurrentTab;
this.setSliderCss();
}
}
setSliderCss() {
let width = 0;
let left = 0;
if (this.currentTab) {
width = this.currentTab.css('width');
left = this.currentTab.offset().left;
}
$('.et-hero-tab-slider').css('width', width);
$('.et-hero-tab-slider').css('left', left);
}}
new StickyNavigation();
//# sourceURL=pen.js
</script>
</body>
</html>
답변 3개
메뉴 간 작은 선을 넣으려 할 때,
현재 방식(::after)으로는 각 메뉴 항목의 뒤쪽에만 선이 붙기 때문에
정확한 가운데 정렬이 어려우니 각 메뉴 항목을 감싸는 컨테이너에
display: flex;, align-items: center;, justify-content: center;를 설정한 후,
각 메뉴 항목(.et-hero-tab)에 좌우 padding을 추가하여 충분한 공간을 확보한 다음,
각 항목의 오른쪽에만 가상 요소(::after)를 두어 선을 삽입하면
메뉴 간 구분선이 정확히 중앙에 배치되지 않나 싶습니다.
.et-hero-tab {
position: relative; /* 메뉴 항목의 상대적 위치 기준점 설정 */
}
.et-hero-tab::after {
content: "";
position: absolute;
top: 50%; /* 메뉴 항목 높이의 중간 지점에 배치 */
right: 0; /* 메뉴 항목의 우측 끝에 배치 */
transform: translateY(-50%); /* 세로 중앙 정렬 */
width: 1px; /* 구분선 두께 */
height: 16px; /* 구분선 높이 */
background-color: #000; /* 구분선 색상 */
opacity: 0.5; /* 구분선 투명도 */
}
/* 마지막 메뉴 뒤의 구분선 제거 */
.et-hero-tab:last-child::after {
display: none;
}
답변에 대한 댓글 2개
댓글을 작성하려면 로그인이 필요합니다.
after에
position: absolute;
top: 50%;
transform: translateY(-50%):
그리고 left 또는 right 로 위치 조정
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
많이 배웁니다!!!