简体   繁体   English

仅 CSS 选项卡 - 如何仅在选项卡 2、3 和 4 被激活时向选项卡内容添加边框左上角半径?

[英]CSS only tabs - How can I add a border-top-left-radius to the tab content only when tab 2, 3 & 4 are activated?

CSS only!仅限 CSS! Does anyone know how to trigger add an 8px radius to the top left of the .tab-content container only when tab 2, 3, or 4 are pressed and leave it without a radius when tab-1 is selected?有谁知道如何仅在按下选项卡 2、3 或 4 时触发将 8px 半径添加到 .tab-content 容器的左上角,并在选择选项卡 1 时使其没有半径?

'border-top-left-radius: 8px;' 'border-top-left-radius: 8px;' is the code I need to execute, only when these mentioned tabs are selected and not the 1st tab.是我需要执行的代码,只有当这些提到的选项卡被选中而不是第一个选项卡时。

I have tried many different approaches here relating to .tab-switch:checked and the same with .tab-content but cant get anything to fire.我在这里尝试了许多与 .tab-switch:checked 相关的不同方法,与 .tab-content 相同,但无法触发任何东西。

 :root { --primary: #0062a4; --primary_med: #5084a7; --primary_dark: #24435c; --light: #ffffff; --dark: #000000; --shadow: 2px 4px 8px rgba(104, 104, 104, 0.8); } .feedback { box-sizing: border-box; padding: 10px; font-size: 12px; border-radius: 10px; background-image: linear-gradient(to bottom right, rgb(23, 62, 136), rgb(0, 140, 255)); border: 1px solid #000000; box-shadow: 2px 4px 8px; } .tabs { position: relative; margin: 0; } .tabs::before, .tabs::after { content: ""; display: table; } .tabs::after { clear: both; } .tab { float: left; Padding-top: 5px; padding-left: 10px; } .tab-switch { display: none; } .tab-label { position: relative; display: block; height: 34px; text-align: center; background: var(--primary_dark); color: #fff; cursor: pointer; padding: 5px 20px; font-size: 14px; border-top-left-radius: 8px; border-top-right-radius: 8px; } .tab-switch:checked+.tab-label { background: var(--primary_med); color: var(--light); border-bottom: 0; z-index: 1; top: -0.0625rem; font-size: 16px; font-weight: 700; } .tab-content { height: 12rem; position: absolute; border-top-right-radius: 8px; border-bottom-right-radius: 8px; border-bottom-left-radius: 8px; z-index: 1; top: 3.1em; left: 0; padding: 1.618rem; background: var(--primary_med); opacity: 0; height: 422px; width: 100%; } .tab-switch:checked+label+.tab-content { z-index: 2; opacity: 1; } .base-footer { gap: 10px; background-image: linear-gradient(to bottom right, rgb(23, 62, 136), rgb(0, 140, 255)); border-radius: 10px; border: 1px solid #000000; box-shadow: 2px 4px 8px; }
 <div class="container"> <div class="tabs"> <div class="tab"> <input type="radio" name="css-tabs" id="tab-1" checked class="tab-switch"> <label for="tab-1" class="tab-label">Tab 1</label> <div class="tab-content">Tab 1</div> </div> <div class="tab"> <input type="radio" name="css-tabs" id="tab-2" class="tab-switch"> <label for="tab-2" class="tab-label">Tab 2</label> <div class="tab-content">Tab 2</div> </div> <div class="tab"> <input type="radio" name="css-tabs" id="tab-3" class="tab-switch"> <label for="tab-3" class="tab-label">Tab 3</label> <div class="tab-content">Tab 3</div> </div> <div class="tab"> <input type="radio" name="css-tabs" id="tab-4" class="tab-switch"> <label for="tab-4" class="tab-label">Tab 4</label> <div class="tab-content">Tab 4</div> </div> </div> </div>

I need a solution in CSS only please.我只需要 CSS 中的解决方案。

You could use the :not selector - what you want to select are the tabs that are checked but are not the first-child (of the .tabs element).您可以使用 :not 选择器 - 您要选择的是已检查但不是第一个子项( .tabs 元素的)的选项卡。

 :root { --primary: #0062a4; --primary_med: #5084a7; --primary_dark: #24435c; --light: #ffffff; --dark: #000000; --shadow: 2px 4px 8px rgba(104, 104, 104, 0.8); } .feedback { box-sizing: border-box; padding: 10px; font-size: 12px; border-radius: 10px; background-image: linear-gradient(to bottom right, rgb(23, 62, 136), rgb(0, 140, 255)); border: 1px solid #000000; box-shadow: 2px 4px 8px; } .tabs { position: relative; margin: 0; } .tabs::before, .tabs::after { content: ""; display: table; } .tabs::after { clear: both; } .tab { float: left; Padding-top: 5px; padding-left: 10px; } .tab-switch { display: none; } .tab-label { position: relative; display: block; height: 34px; text-align: center; background: var(--primary_dark); color: #fff; cursor: pointer; padding: 5px 20px; font-size: 14px; border-top-left-radius: 8px; border-top-right-radius: 8px; } .tab-switch:checked+.tab-label { background: var(--primary_med); color: var(--light); border-bottom: 0; z-index: 1; top: -0.0625rem; font-size: 16px; font-weight: 700; } .tab-content { height: 12rem; position: absolute; border-top-right-radius: 8px; border-bottom-right-radius: 8px; border-bottom-left-radius: 8px; z-index: 1; top: 3.1em; left: 0; padding: 1.618rem; background: var(--primary_med); opacity: 0; height: 422px; width: 100%; } .tab-switch:checked+label+.tab-content { z-index: 2; opacity: 1; } .tab:not(:first-child) .tab-switch:checked+label+.tab-content { border-top-left-radius: 8px; } .base-footer { gap: 10px; background-image: linear-gradient(to bottom right, rgb(23, 62, 136), rgb(0, 140, 255)); border-radius: 10px; border: 1px solid #000000; box-shadow: 2px 4px 8px; }
 <div class="container"> <div class="tabs"> <div class="tab"> <input type="radio" name="css-tabs" id="tab-1" checked class="tab-switch"> <label for="tab-1" class="tab-label">Tab 1</label> <div class="tab-content">Tab 1</div> </div> <div class="tab"> <input type="radio" name="css-tabs" id="tab-2" class="tab-switch"> <label for="tab-2" class="tab-label">Tab 2</label> <div class="tab-content">Tab 2</div> </div> <div class="tab"> <input type="radio" name="css-tabs" id="tab-3" class="tab-switch"> <label for="tab-3" class="tab-label">Tab 3</label> <div class="tab-content">Tab 3</div> </div> <div class="tab"> <input type="radio" name="css-tabs" id="tab-4" class="tab-switch"> <label for="tab-4" class="tab-label">Tab 4</label> <div class="tab-content">Tab 4</div> </div> </div> </div>

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

相关问题 CSS“仅”选项卡:如何为活动状态添加选项卡突出显示? - CSS 'only' Tabs: How can i add tab highlight for the active state? 仅 CSS 标签:如何将内容与标签匹配? - CSS-only tabs: how to match content to tab? 无法在具有border-top-left-radius和border-width的三角形对象中创建圆形的左上角 - Cannot create rounded top left in triangle object with border-top-left-radius and border-width jQuery ui选项卡仅在单击选项卡时才加载选项卡内容 - Jquery ui tabs load tab content only when tab is clicked 仅当激活滚动条时,如何为具有style =&#39;overflow:auto&#39;的div添加边框? - How do I add a border to a div that has the style='overflow:auto' only when the scrollbar is activated? 仅在活动状态下如何加载Bootstrap选项卡内容? - How do I load Bootstrap tab content only when it is active? 多个选项卡列表:如何仅显示单击的选项卡列表的内容? - Multiple tabs lists: How to show only the content of the clicked tab list? 我怎样才能做到只加载选项卡区域而不是单击选项卡后页面跳转到顶部? - How can I make it so only the tab area loads instead of the page jumping to the top after clicking on tab? 仅css3选项卡预选选项卡 - css3 only tabs preselect tab 边界半径使用CSS在三角形的左上角 - border radius top left on triangle using CSS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM