Weird behavior in Firefox with outlines and pseudo-elements - css

Firefox behaves differently than Chrome and Safari (I haven't tested others browsers) when you combine outline and pseudo-elements.
Is there a way to fix it or is this a bug?
.main {
position: relative;
width: 100px;
height: 100px;
margin: 10px auto;
border: 2px solid #f00;
outline: 2px solid #00f;
}
.main:after {
content: 'Hello';
position: absolute;
width: 100px;
text-align: center;
bottom: -50px;
}
.wtf {
width: 400px;
margin: 90px auto;
}
<div class="main"></div>
<div class="wtf">
<p>In Chrome and Safari the 'Hello' is outside of the outline.</p>
<p>In firefox the outline is extended and the 'Hello' is inside the outline. Bug from Firefox or is there a way to fix this?</p>
</div>
Demo: http://codepen.io/romainberger/pen/nuxlh
Edit:
Tested in Firefox 20.0, Chrome 28 and Safari 5.1

Now used to
box shadow
as like this
.main {
position: relative;
width: 100px;
z-index:1;
height: 100px;
margin: 10px auto;
border: 2px solid #f00;
box-shadow:0px 0px 0px 3px #00f;
}
.main:after {
content: 'Hello';
position: absolute;
text-align: center;
bottom: -50px;
left:0;
right:0;
z-index:2;
}
.wtf {
width: 400px;
margin: 90px auto;
}
Demo

No need to use z-index.
.main {
position: relative;
width: 100px;
height: 100px;
margin: 10px auto;
border: 2px solid #f00;
box-shadow:0px 0px 0px 3px #00f;
}
.main:after {
content: 'Hello';
position: absolute;
text-align: center;
bottom: -50px;
left:0;
right:0;
}
.wtf {
width: 400px;
margin: 90px auto;
}

Related

sticky position not working in the nav bar

My css:
*{
margin: 0;
padding: 0;
}
body{
height: 2000px;
}
nav{
width: 80vw;
height: 10vw;
background-color: black;
border: 2px red solid;
position: sticky;
top: 0;
}
li{
color: white;
padding: 2vh;
display: inline-block;
font-size: 5vw;
}
.nothing{
height: 100px;
width: 100px;
border: 2px brown solid;
}
My navbar isnt sticking to the top even though there is no overflow element anywhere (which causes problems in this case i think) and top: 0 is also mentioned. Why is this?

How to give border to a shape?

I am building a testimonial component in react and I have to make a shape direction towards pic, I have done the shape exactly how I want but the testimonial div has border color when I apply the div gets a border but the shape is left outside I have tried several ways but couldn't find a solution, I have attached the picture of what I want and how it is right now.
How I want it
What I have achieved till now
Below is my CSS
#page {
background-color: lightgray;
padding: 40px;
}
.container {
position: relative;
background-color: #FFFFFF;
max-width: 600px;
height: auto;
border: 1px solid #E7E7E7;
padding: 30px;
box-sizing: border-box;
}
.container:after {
position: absolute;
width: 0;
height: 0;
border-top: 50px solid white;
border-right: 40px solid transparent;
top:101%;
left: 40%;
content: '';
transform: rotate(14deg);
margin-top: -10px;
}
<div id="page">
<div class="container">This is a test</div>
</div>
You may use a filter , choice: drop-shadow.
support ? , don't be afraid : https://caniuse.com/?search=drop-shadow All but IE 6-11 and Opera mini
here is an exemple to run:
#page {
background-color: lightgray;
padding: 40px;
}
.container {
position: relative;
background-color: #FFFFFF;
max-width: 600px;
height: auto;
filter:
/* draw borders without blur*/
drop-shadow(0 1px )
drop-shadow(1px 0px )
drop-shadow(0 -1px )
drop-shadow(-1px 0px )
/* add eventually a shadow */
drop-shadow(0 0 3px )
/*and another for demo purpose */
drop-shadow(30px 30px 3px gray );
padding: 30px;
box-sizing: border-box;
}
.container:after {
position: absolute;
width: 0;
height: 0;
border-top: 50px solid white;
border-right: 40px solid transparent;
top:101%;
left: 40%;
content: '';
transform: rotate(14deg);
margin-top: -10px;
}
<div id="page">
<div class="container">This is a test</div>
</div>
You can use a :before that's 1px bigger than your :after which uses the border colour instead and then it will be mostly covered by the :after, giving you your "fake" border. Just makes sure your z-indexing is correct so it doesn't show inside your bubble.
EDIT: Adding in example css.
I modified some colours and spacing for illustrative purposes:
#page {
background: #ffc;
padding: 40px 40px 60px;
position: relative;
z-index: 0;
}
.container {
position: relative;
background: #fff;
max-width: 600px;
height: auto;
border: 1px solid #000;
padding: 30px;
box-sizing: border-box;
}
.container:after,
.container:before {
position: absolute;
width: 0;
height: 0;
top: 101%;
left: 40%;
content: "";
transform: rotate(14deg);
margin-top: -10px;
}
.container:after {
border-top: 50px solid #fff;
border-right: 40px solid transparent;
}
.container:before {
border-top: 52px solid #000;
border-right: 42px solid transparent;
margin-left: -1px;
z-index: -1;
}
<div id="page">
<div class="container">This is a test</div>
</div>
Adding both a :before and :after is a good idea to get the effect you want. Using a CSS box-shadow or outline won't work because it actually renders a complete square around your arrow/triangle shape. A z-index is added to the before to push it to the background. In that way it's not overlapping the other objects.
Here's an example of what you might want. You can adjust the border sizes to finetune it.
.container {
position: relative;
background-color: #FFFFFF;
max-width: 600px;
height: auto;
border: 1px solid #E7E7E7;
padding: 30px;
box-sizing: border-box;
}
.container:before {
position: absolute;
width: 0;
height: 0;
border-top: 53px solid #e7e7e7;
border-right: 43px solid transparent;
top: 100%;
left: 40%;
content: '';
transform: rotate(14deg);
margin-top: -10px;
z-index: -1;
}
.container:after {
position: absolute;
width: 0;
height: 0;
border-top: 50px solid white;
border-right: 40px solid transparent;
top:101%;
left: 40%;
content: '';
transform: rotate(14deg);
margin-top: -10px;
}
<div class="container"></div>

overflow-y auto and arrow not working together

I have a div with an arrow before it.
the problem is, when I add:
overflow-y: auto;
the arrow disappears.
https://jsfiddle.net/z95frkuv/
#n {
position: fixed;
min-width: 140px;
min-height:100px;
max-height:400px;
//overflow-y: auto; // need to remove this to see arrow
border:1px solid #000;
z-index:3000;
}
#n:before {
content: "";
vertical-align: middle;
margin: auto;
position: absolute;
left: 0;
right: 0;
bottom: 100%;
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-bottom: 10px solid #000;
}
why?
overflow:auto works like overflow:hidden when it comes to absolute positioned elements.
In order to overcome it, add a wrapper div:
<div class="wrapper">
<div id=n>content<br>content<br>content<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br></div>
</div>
And update the css:
.wrapper {
position: fixed;
z-index:3000;
}
.wrapper:before {
content: "";
vertical-align: middle;
margin: auto;
position: absolute;
left: 0;
right: 0;
bottom: 100%;
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-bottom: 10px solid #000;
}
#n{
min-width: 140px;
min-height:100px;
max-height:400px;
overflow-y: auto;
border:1px solid #000;
}
fiddle: https://jsfiddle.net/yow7wm7r/1/
That's exactly what overflow is doing, if an element is defined inside the box, but with css it sticks outside, the overflow will clip it out.
http://www.w3schools.com/cssref/pr_pos_overflow.asp

Responsive triangles with hover effect

I recently came across an article detailing how to create responsive triangles with pure CSS. I was wanting to take this a step further to incorporate it into a current design.
I was able to get four triangles placed within a square div perfectly (creating an origami-type effect) and they are responsive.
However when I try to incorporate a hover effect, it does not change the color of the triangle - only the empty space around it.
Also, when my square's width changes (keeping with the responsiveness) the bottom triangle separates from the others - because I used absolute positioning and bottom: 0; to place the triangles within the square.
Does anyone know a way around this to achieve my desired effect in pure CSS? Here is the relevant code : JSFiddle
HTML:
<body>
<div class="container">
<div class="box">
<div class="triSectionTop"></div>
<div class="triSectionRight"></div>
<div class="triSectionBottom"></div>
<div class="triSectionLeft"></div>
</div>
</div>
</body>
SCSS:
.container {
box-sizing: border-box;
height: 400px;
width: 400px;
}
.box {
position: relative;
box-sizing: border-box;
height: 400px;
width: 100%;
}
.triSectionTop {
position: absolute;
top: 0;
width: 100%;
height: 0;
padding-left: 50%;
padding-top: 50%;
overflow: hidden;
&:after {
content: "";
display: block;
width: 0;
height: 0;
margin-left: -200px;
margin-top: -200px;
border-left: 200px solid transparent;
border-right: 200px solid transparent;
border-top: 200px solid #41a5e8;
}
}
.triSectionRight {
position: absolute;
right: 0;
width: 50%;
height: 0;
padding-top: 50%;
padding-bottom: 50%;
overflow: hidden;
&:after {
content: "";
display: block;
width: 0;
height: 0;
margin-top: -200px;
border-top: 200px solid transparent;
border-bottom: 200px solid transparent;
border-right: 200px solid #4eb2f5;
}
}
.triSectionBottom {
position: absolute;
bottom: 0;
width: 100%;
height: 0;
padding-left: 50%;
padding-bottom: 50%;
overflow: hidden;
&:after {
content: "";
display: block;
width: 0;
height: 0;
margin-left: -200px;
border-left: 200px solid transparent;
border-right: 200px solid transparent;
border-bottom: 200px solid #5abeff;
}
}
.triSectionLeft {
position: absolute;
left: 0;
width: 0;
height: 0;
padding-top: 50%;
padding-bottom: 50%;
padding-left: 50%;
overflow: hidden;
&:after {
content: "";
display: block;
width: 0;
height: 0;
margin-top: -200px;
margin-left: -200px;
border-top: 200px solid transparent;
border-bottom: 200px solid transparent;
border-left: 200px solid #67cbff;
}
}
You can achieve the hover effect (background-color change and outside box-shadow) by making the triangles with transform-rotate.
This will allow you to triger the hover event only when the shape is actualy hovered :
DEMO
.box{
width:500px;
height:500px;
position:relative;
overflow:hidden;
}
.box > div{
position:absolute;
bottom:50%; left:50%;
width:75%; height:75%;
transform-origin:0 100%;
z-index:1;
}
.triSectionTop{
-webkit-transform:rotate(-45deg);
-ms-transform:rotate(-45deg);
transform:rotate(-45deg);
background:#41A5E8;
}
.triSectionRight{
-webkit-transform:rotate(45deg);
-ms-transform:rotate(45deg);
transform:rotate(45deg);
background:#4EB2F5;
}
.triSectionBottom{
-webkit-transform:rotate(135deg);
-ms-transform:rotate(135deg);
transform:rotate(135deg);
background:#5ABEFF;
}
.triSectionLeft{
-webkit-transform:rotate(225deg);
-ms-transform:rotate(225deg);
transform:rotate(225deg);
background:#67CBFF;
}
.box > div:hover{
background:teal;
box-shadow: 0 0 10px 0 #656565;
z-index:2;
}
<div class="box">
<div class="triSectionTop"></div>
<div class="triSectionRight"></div>
<div class="triSectionBottom"></div>
<div class="triSectionLeft"></div>
</div>
This will work try this
Here is the Html
<div class="arrow-up"></div>
<div class="arrow-down"></div>
<div class="arrow-left"></div>
<div class="arrow-right"></div>
Here is the CSS
.arrow-up {
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-bottom: 5px solid black;
}
.arrow-down {
width: 0;
height: 0;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-top: 20px solid #f00;
}
.arrow-right {
width: 0;
height: 0;
border-top: 60px solid transparent;
border-bottom: 60px solid transparent;
border-left: 60px solid green;
}
.arrow-left {
width: 0;
height: 0;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-right:10px solid blue;
}
here is the source

Overlapping Div Positioning

I would Like to have a banner across an image. Both the image and banner (banner-snippet) are in the same parent element so the the black banner is pushed out of view. How can I fix this.
You can see my source here:
<div id="slide-banner">
<img src="http://upload.wikimedia.org/wikipedia/commons/0/0c/GoldenGateBridge-001.jpg"/>
<div id="slide-banner-snippet">
</div>
</div>​
#slide-banner {
margin-top: 70px;
margin-right: auto;
margin-left: auto;
padding: 0px 0px 0px 0px;
height: 350px;
width: 916px;
border: 1px solid #ccc;
border-radius: 3px 3px 3px 3px;
overflow: hidden;
}
#slide-banner img {
height: auto;
width: 916px;
}
#slide-banner-snippet {
height: 55px;
width: 916px;
background-color: #000;
}
http://jsfiddle.net/uSw8S/
Absolutely position the element you want to float, ie:
position:absolute;
top:0;
z-index:1;
You can make #slide-banner relatively positioned and make slide-banner-snippet absolutely positioned and add bottom:0;
#slide-banner {
margin-top: 70px;
margin-right: auto;
margin-left: auto;
padding: 0px 0px 0px 0px;
height: 350px;
width: 916px;
border: 1px solid #ccc;
border-radius: 3px 3px 3px 3px;
overflow: hidden;
position:relative;
}
#slide-banner img {
height: auto;
width: 916px;
}
#slide-banner-snippet {
height: 55px;
width: 916px;
background-color: #000;
position:absolute;
bottom:0;
}
http://jsfiddle.net/uSw8S/2/
You can just put
<div id="slide-banner-snippet">
</div>
before
<img src="http://upload.wikimedia.org/wikipedia/commons/0/0c/GoldenGateBridge-001.jpg"/>
Example Here

Resources