Transparent tab menu layout with CSS - html

What is the best way to make the following layout (where the grey area is a simple transparent background, i.e. with 60% color transparency and the corners are cut or rounded):
I tried several tutorials regarding tab menus, but i failed on the parts that i marked red. I can't figure out how to "hack" the stylesheets to make a line, that is interrupted below the active tab AND has a rounded corner on the right.
I made a solution with a simple colored background (not transparent) by adding a bottom-border on the active tab in the same color as the content and moving it -2 px to the bottom (overlay). But this does not work with transparency.
Please note: The tabs have to be flexible regarding their width (because it is a multi-language layout).

Proof of Concept
I am afraid to say that it can be done, but it is a bit of a mess and my
solution involves using absolute position of elements with specific dimensions,
and of course, extra markup.
The solution may not work too well in a flexible design, but I thought it would
be illustrative to post it.
The trick is to use the class .active to turn on the segments that draw the
lines before and after the tab element.
If you switch the .active class to the other tab, you will see the effect.
Note: There is a glitch towards the bottom of the tab, sometimes a white space
shows up on certain screen sizes in Firefox, but it could be an artifact of
the snippet tool of StackOverflow. If you look at the same code in jsFiddle.net, the layout seems to work.
jsfiddle: http://jsfiddle.net/audetwebdesign/hujhmLap/embedded/result/
#tab-list {
width: 400px;
height: 42px;
position: relative;
}
.tab-panel-1 {
width: 400px;
height: 42px;
position: absolute;
top: 0;
left: 0;
display: block;
}
.tab-panel-2 {
width: 400px;
height: 42px;
position: absolute;
top: 0;
left: 0;
display: block;
}
.tab {
background-color: rgba(125, 125, 125, 0.25);
border-top-left-radius: 5px;
border-top-right-radius: 5px;
border: solid 2px #000;
border-bottom: 0;
display: block;
text-align: center;
padding: 10px 0 0 0;
width: 80px;
height: 30px;
}
.t1 {
position: absolute;
left: 0px;
top: 0px;
}
.fill1 {
position: absolute;
left: 82px;
right: 0px;
bottom: -5px;
height: 5px;
border-top: 2px solid black;
border-right: 2px solid black;
border-top-right-radius: 5px;
}
.t2 {
position: absolute;
left: 100px;
top: 0px;
}
.pre2 {
position: absolute;
left: 0px;
right: calc(400px - 100px - 2px);
bottom: -5px;
height: 5px;
border-top: 2px solid black;
border-left: 2px solid black;
border-top-left-radius: 5px;
border-top-right-radius: 0px;
}
.fill2 {
position: absolute;
left: calc(100px + 80px + 2px);
right: 0px;
bottom: -5px;
height: 5px;
border-top: 2px solid black;
border-right: 2px solid black;
border-top-right-radius: 5px;
}
#content-box {
background-color: rgba(125, 125, 125, 0.25);
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
border-top-right-radius: 0px;
border: solid 2px #000;
border-top: none;
height: 200px;
padding: 20px;
width: 356px;
}
.t1, .fill1,
.pre2, .t2, .fill2
{
display: none;
}
.active .t1, .active .fill1,
.active .pre2, .active .t2, .active .fill2
{
display: block;
}
<div id="tab-list">
<div class="tab-panel-1 ">
<span class="tab t1">Tab 1</span><span class="fill1"></span>
</div>
<div class="tab-panel-2 active">
<span class="pre2"></span><span class="tab t2">Tab 2</span><span class="fill2"></span>
</div>
</div>
<div id="content-box">
Hello World!
</div>

Related

Adding a triangle in css under another element

I have been trying hard without success to add a little triangle under my square to act as a pointer like this:
My code by itself works, but whenever I try to add css to make this triangle nothing will appear. I think it has to do with before-after functions, but I'm not really getting it. Anyone can help me with that?
<div id="slider_outer1">
<div class="slider_segment"><img src="myurl.com" alt="Nature" style="width:100%;"></div>
<div id="slider_marker1"></div>
</div>
<style>
.container {width:400px;}
#slider_outer1 {width: 98%;border: 5px solid #8f89ff; position: relative;display: inline-block; border-radius: 5px;}
.slider_segment {width: 100%; float: left; display: inline;}
#slider_marker1 {
position: absolute;
border: 2px solid #574fff;
height: 30px;
width: 5%;
top: 120px;
left: 57.25%;
text-align: center;
Margin-left: -10%;
padding: 5px 0px;
background: #ffffff;
border-radius: 5px;
}
div#slider_marker1:after {
content: "5";
font-size: 20px;
padding: 5px;
line-height: 30px;
font-family: sans-serif;
}
</style>
edit: code of the triangle
<div class="triangle-down"></div>
<style>
.triangle-down {
width: 0;
height: 0;
border-left: 15px solid transparent;
border-right: 15px solid transparent;
border-top: 20px solid #555;
}
</style>
Generally in CSS triangles are made using borders, not before and after pseudo elements. To create a downward pointing triangle, you would create a top border of n number of pixels, and left and right borders of half that width and also transparent.
Example:
<div id="slider_outer1">
<div class="slider_segment"><img src="myurl.png" alt="Nature" style="width:100%;"></div>
<div id="slider_marker1"><div id='triangle-down'></div></div>
</div>
<style>
.container {width:400px;}
#slider_outer1 {width: 98%;border: 5px solid #8f89ff; position: relative;display: inline-block; border-radius: 5px;}
.slider_segment {width: 100%; float: left; display: inline;}
#slider_marker1 {
position: absolute;
border: 2px solid #574fff;
height: 30px;
width: 5%;
top: 120px;
left: 57.25%;
text-align: center;
Margin-left: -10%;
padding: 5px 0px;
background: #ffffff;
border-radius: 5px;
}
#triangle-down {
position: absolute;
top: 40px;
right: 50%;
transform: translateX(50%);
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-top: 20px solid blue;
}
div#slider_marker1:after {
content: "5";
font-size: 20px;
padding: 5px;
line-height: 30px;
font-family: sans-serif;
}
</style>
See my codepen here: https://codepen.io/anon/pen/bvXOab
You could add another div for the triangle like
<div id='triangle'></div>
Css For the triangle...
#triangle{
width: 0;
height: 0;
border-left: 40px solid transparent;
border-right: 40px solid transparent;
border-top: 80px solid blue;
}
However I feel that your problem is not that it just isnt appearing its that the positioning is messed up so its 'hidden' behind the sliders
I think I understand what you're trying to make. This should add a triangle above the marker. This solution should allow you to also remove anything related to triangle-down as it only requires the slider_marker1 div
#slider_marker1::before {
content: "";
width: 0;
height: 0;
position: absolute;
top: -6px;
left: 0;
right: 0;
margin: auto;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-bottom: 4px solid green;
z-index: 100;
}

CSS: triangle above an dialogue box disappears on setting overflow

I have a dialogue box or a arrow box which should be set to max height of 60%, and all the content inside the box overflows via scroll, this is the markup:
<div class="cart">
hello world
</div>
and here is the css to make a arrow-head on top:
.cart {
position: fixed;
background: #ffffff;
opacity: 1;
box-shadow: 1px 1px 10px;
border-radius: 5px;
margin-left: 74.8%;
width: 300px;
top: 70px;
padding: 13px;
z-index: 20;
text-align: center;
display: none;
max-height: 60%;
overflow: auto;
}
.cart:after, .cart:before {
top: -20px;
bottom: 100%;
left: 50%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
.cart:after {
border-color: rgba(255, 255, 255, 0);
border-bottom-color: #ffffff;
border-width: 10px;
margin-left: -10px;
}
.cart:before {
border-color: rgba(12, 143, 176, 0);
border-bottom-color: #999;
border-width: 11px;
margin-left: -11px;
}
if I remove the "overflow" property the arrow head shows up, but when I use it, which I have to It disappears, I want both, an arrow head and scrollable div, but I think the arrowhead just gets inside the scroll. is there any solution for this?
Thanks for the help

Triangle on the bottom border of an element

What I'm trying to do is to create a triangle on the bottom border of a block with CSS, and write some text in there like it's shown in this figure :
What I did so far, is :
Create the block element, with its its orange big bottom border.
Create the triangle using CSS.
All I need now is a way to place that triangle exactly in the middle of that exact place. I tried several ways to do that, but without any result.
Here's my code :
.content_block {
position: relative;
border: ridge;
border-width: 1px;
border-color: #969696;
background: #FFF;
}
.content_block.orange {
border-bottom: 40px solid #F59A3C;
}
.content_block > .image {
position: absolute;
display: block;
height: 110px;
width: auto;
top: 20%;
left: 15%;
}
.content_block > .text {
position: absolute;
color: #FFF;
font-weight: bold;
font-size: 12pt;
top: 105%;
left: 33%;
}
.content_block.size_3 {
height: 207px;
width: 240px;
}
.content_block.triangle {
width: 0;
height: 0;
border-style: solid;
border-width: 25px 0 0 25px;
border-color: transparent transparent transparent #FE992C;
}
<div class="content_block orange size_3">
<img src="http://upload.dinhosting.fr/c/D/B/demenage.PNG" class="image">
<div class="text">Je déménage</div>
</div>
You can notice that there's an HTML class called triangle that I don't show. I don't know how to show it exactly in that position.
EDIT :
I'm using the exact selector ( .content_block ) for showing other blocks; Like this block for instance :
So, a solution with after pseudo element will affect this block too. This is why I really need to avoid pseudo elements..
Edit
If you can't use a pseudo element for the triangle, you will need to add an element. You can add it as a child of the .content_block element. This uses the same approach described in the original answer :
.content_block {
position: relative;
border: ridge;
border-width: 1px;
border-color: #969696;
background: #FFF;
}
.content_block.orange {
border-bottom: 40px solid #F59A3C;
}
.content_block > .image {
position: absolute;
display: block;
height: 110px;
width: auto;
top: 20%;
left: 15%;
}
.content_block > .text {
position: absolute;
color: #FFF;
font-weight: bold;
font-size: 12pt;
top: 105%;
left: 33%;
}
.triangle {
position: absolute;
bottom: 0;
left: 50%;
border-right: 20px solid transparent;
border-bottom: 12px solid #F59A3C;
}
.content_block.size_3 {
height: 207px;
width: 240px;
}
<div class="content_block orange size_3">
<img src="http://upload.dinhosting.fr/c/D/B/demenage.PNG" class="image">
<div class="triangle"></div>
<div class="text">Je déménage</div>
</div>
Original answer:
You can make the triangle with the border technique and a pseudo element.
In the following example, I used the .content_block:after pseudo element with absolute positioning:
.content_block {
position: relative;
border: ridge;
border-width: 1px;
border-color: #969696;
background: #FFF;
}
.content_block.orange {
border-bottom: 40px solid #F59A3C;
}
.content_block > .image {
position: absolute;
display: block;
height: 110px;
width: auto;
top: 20%;
left: 15%;
}
.content_block > .text {
position: absolute;
color: #FFF;
font-weight: bold;
font-size: 12pt;
top: 105%;
left: 33%;
}
.content_block:after {
content: '';
position: absolute;
bottom: 0;
left: 50%;
border-right: 20px solid transparent;
border-bottom: 12px solid #F59A3C;
}
.content_block.size_3 {
height: 207px;
width: 240px;
}
<div class="content_block orange size_3">
<img src="http://upload.dinhosting.fr/c/D/B/demenage.PNG" class="image">
<div class="text">Je déménage</div>
</div>
User :after selector and position that absolutely
Here is updated fiddle:
https://jsfiddle.net/yod8Lvjt/1/

Chamfered border different container color CSS [duplicate]

This question already has answers here:
Div with cut out edges, border and transparent background
(6 answers)
Closed 7 years ago.
What I want to achieve :
What I did so far is to make the corners as if it had the same color with the container and then cover the unneeded area with the "fake" square rotated by 45 deg.
I don't like that much the result, especially the bottom right corner and I can't thing another way to do it. What is the best way to achieve it ? Is it possible to be done with gradients ?
First Step : http://jsfiddle.net/laxmana/wjaAs/
Final : http://jsfiddle.net/laxmana/j9NWC/
CSS :
.chamfered-box{
width: 100%;
position: relative;
background: white;
border: 1px solid #149E4B;
}
.chamfered-box::before, .chamfered-box::after{
width: 0px;
height: 0px;
background: #fff;
content: '';
position: absolute;
bottom: 0;
}
.chamfered-box::after{
right: -1px;
bottom: -1px;
border-top: 10px solid #149E4B;
border-right: 10px solid white;
border-left: 10px solid #149E4B;
border-bottom: 10px solid white;
}
.chamfered-box::before{
left: -1px;
top: -1px;
border-top: 10px solid #149E4B;
border-right: 10px solid white;
border-left: 10px solid #149E4B;
border-bottom: 10px solid white;
}
.ch-top, .ch-bottom{position: absolute;z-index: 5;}
.ch-top{
top: -16px;
left: -18px;
width: 30px;
height: 30px;
background: white;
-webkit-transform: rotate(45deg);
}
.ch-bottom{
bottom: 5px;
right: 6px;
width: 28px;
height: 28px;
background: white;
-webkit-transform: rotate(45deg);
}
.ch-content{
padding: 20px;
}
HTML :
<div class="chamfered-box">
<div class="ch-top"></div>
<div class="ch-bottom"></div>
<div class="ch-content">The text</div>
</div>
You may use the pseudo element and rotate them on top(over) of the container with a little difference from your method.
Draw an inset shadow instead a border to your container.
Draw squares with a white background (as container) with borders.
Rotate the square and hide part of them overflowing from container.
DEMO
.chamfered-box{
margin:1em auto;
width: 440px;
padding:5px;
position: relative;
overflow:hidden;
background: white;
box-shadow: inset 0 0 0 1px #149E4B;
}
.chamfered-box::before, .chamfered-box::after{
width: 20px;
height: 20px;
background: #fff;
content: '';
position: absolute;
bottom: 0;
border: 1px solid #149E4B;
transform:rotate(45deg);
}
.chamfered-box::after{
right: -11px;
bottom: -11px;
}
.chamfered-box::before{
left: -11px;
top: -11px;
}

Div box styling

I been playing with css around a div for sometime now, and still couldn't find a way to copy the picture below.
Anyone can help would be great. And it should be a div or something that I can put a text inside.
A bit tricky, but doable with pure CSS.
HTML:
<span class="hover-me">Mouse goes here</span>
<div class="tooltip">
<div class="tooltip-origin-border">
<div class="tooltip-origin-inner">
</div>
</div>
<div class="tooltip-content">
This is a tooltip.
</div>
</div>
CSS:
.tooltip {
position: absolute;
margin-top: -30px;
margin-left: 120px;
display: none;
}
.tooltip-content {
padding: 10px;
border-radius: 5px;
border: 1px solid #33c;
background: #ddf;
}
.tooltip-origin-border {
border: 10px solid transparent;
border-right-color: #33c;
margin-top: 10px;
margin-left: -19px;
position: absolute;
}
.tooltip-origin-inner {
border: 8px solid transparent;
border-right-color: #ddf;
margin-top: -8px;
margin-left: -6px;
position: absolute;
}
.hover-me {
cursor: pointer;
}
.hover-me:hover + .tooltip {
display: block;
}
You just need to play with the positions. The "arrow" is actually a box, with transparent left, top and bottom borders, leaving only the right one visible and because of the way they connect to each other, there's a triangle shape. Jsfiddle
I think CssArrowPlease is what you're looking for.
Try this ->http://jsfiddle.net/5amvG/
I Hope this is what you are looking for
CSS:
#popup{
overflow: visible;
position: relative;
border: 0;
padding: 40px;
height: 40px;
width: 110px;
color: #fff;
background: #d83c3c;
border-radius: 0 3px 3px 0;
}
#popup:before{
content: '';
position: absolute;
border-width: 8px 8px 8px 0;
border-style: solid solid solid none;
border-color: transparent #d83c3c transparent;
top: 12px;
left: -6px;
}
HTML :
<div id="popup">
Sell yourself and say what makes you,you !
</div>
I guess this can help you:
Pure CSS speech bubbles:
http://nicolasgallagher.com/pure-css-speech-bubbles/demo/