This question already has answers here:
Hover and click on CSS triangle
(4 answers)
Closed 7 years ago.
I am in quite the quandary! I would like to add cursor: pointer to my CSS, but the problem is it is a triangle. If I used the following:
#triangleholder {
width: 100px;
height: 100px;
border: 1px solid red;
}
#triangle {
width: 0;
height: 0;
border-right: 50px solid transparent;
border-left: 50px solid transparent;
border-bottom: 50px solid blue;
cursor: pointer;
}
<div id="triangleholder">
<div id="triangle">
</div>
</div>
The whole triangle and everything around it has the "Cursor" affect, how can I make only the triangle have the hover affect?
This can be done with pure CSS if we construct the triangle using transforms and overflow:hidden
FIDDLE
#triangleholder {
width: 100px;
height: 100px;
border: 1px solid red;
}
#triangle {
position: relative;
height: 50px;
overflow: hidden;
}
#triangle:before {
content: '';
position: absolute;
width: 71px; /*using pythagorus: sqrt( (100^2) /2 ) */
height: 71px;
background: blue;
transform: rotate(45deg)translateX(29%);
cursor: pointer;
}
<div id="triangleholder">
<div id="triangle">
</div>
</div>
NB: The code: translateX(29%) is used to place the rotated blue square back into the center of the container after it is rotated. This value seems to be constant even if we change the dimensions of the container (FIDDLE)
Use SVG or CSS3 to draw the arrow. Give that element cursor: pointer give the div wrapper non-cursor
Relevant article to implement this: http://www.smashingmagazine.com/2014/11/03/styling-and-animating-svgs-with-css/
You could mask the non-triangle areas with pseudo elements, with cursor: default set on them. You'd need to add overflow: hidden to the wrapping element to contain the masks, and of course it relies on the background being a flat colour and the shape you want to mask being a perfect triangle. Not massively extensible and a bit hacky, but it gets the specific result you're after.
#triangleholder {
// ..
overflow: hidden;
}
#triangle {
// ..
position: relative;
}
#triangle:before, #triangle:after {
content: "";
display: block;
position: absolute;
background: white;
width: 100px;
height: 50px;
top: -10px;
cursor: default;
}
#triangle:before {
transform: rotate(-45deg);
right: 0;
}
#triangle:after {
transform: rotate(45deg);
left: 0;
}
Related
This question already has answers here:
Tooltip with a triangle [duplicate]
(3 answers)
Why do the :before and :after pseudo-elements require a 'content' property?
(5 answers)
Closed 3 years ago.
I am trying to make a tooltip using html and css. The tooltip would be a rectangle that has a triangle on either the left or right hand sides. A visual example of this is seen below (I'm not concerned about the color or shadow, just that the triangle appears.
While I have been successful making a triangle using:
#triangle-left {
width: 0;
height: 0;
border-top: 50px solid transparent;
border-right: 100px solid red;
border-bottom: 50px solid transparent;
}
When I attempt to append this using a pseudo-element to a div nothing happens. For example, I have tried:
.triangleTest {
height: 100px;
width: 100px;
}
.triangleTest:after {
width: 0;
height: 0;
border-top: 50px solid transparent;
border-right: 100px solid red;
border-bottom: 50px solid transparent;
}
<div class="triangleTest"></div>
But nothing expect the square div appears on the screen. How can I create add a triangle to a div like in the image?
.triangleTest {
position: relative;
background: lightgray;
border-radius: .4em;
height: 100px;
width: 100px;
text-align: center;
}
.triangleTest h1 {
padding-top: 25px;
}
.triangleTest:after {
content: '';
position: absolute;
left: 0;
top: 50%;
width: 0;
height: 0;
border: 0.563em solid transparent;
border-right-color: lightgray;
border-left: 0;
margin-top: -0.562em;
margin-left: -0.562em;
}
<div class="triangleTest">
<h1>Hello</h1>
</div>
I would like to add a white border over all my images in my content div using css. Images in the header and footer div areas should not be affected. how do I achieve this? See example image below. There are images of different sizes on the web pages.
See image:
You can do this without having an extra element or pseudo element:
http://cssdeck.com/labs/t6nd0h9p
img {
outline: 1px solid white;
outline-offset: -4px;
}
IE9&10 do not support the outline-offset property, but otherwise support is good: http://caniuse.com/#search=outline
Alternate solution that doesn't require knowing the dimensions of the image:
http://cssdeck.com/labs/aajakwnl
<div class="ie-container"><img src="http://placekitten.com/200/200" /></div>
div.ie-container {
display: inline-block;
position: relative;
}
div.ie-container:before {
display: block;
content: '';
position: absolute;
top: 4px;
right: 4px;
bottom: 4px;
left: 4px;
border: 1px solid white;
}
img {
vertical-align: middle; /* optional */
}
You could try this:
Html:
<div class="image">
<div class="innerdiv">
</div>
</div>
Css:
.image
{
width: 325px;
height: 239px;
background: url("https://i.picsum.photos/id/214/325/239.jpg?hmac=7XH4Bp-G9XhpuKz5vkgES71GyXKS3ytp-pXCt_zpzE4") 0 0 no-repeat;
background-size: cover;
padding: 10px;
}
.innerdiv
{
border: 1px solid white;
height:100%;
width: 100%;
}
jsFiddle
Hope this is what you meant :)
I solved this with box-shadow: inset and it works with IE11 and up. I wanted a border in the corners around the image but this examples have the border 10px inset. It requires a parent div with :before or :after element but handles it very well.
.image {
width: 100%;
height: auto;
}
.image__wrapper {
position: relative;
}
.image__wrapper:before {
content: '';
position: absolute;
top: 10px;
bottom: 10px;
left: 10px;
right: 10px;
box-shadow: inset 0 0 0 3px red;
}
CodePen Demo
Whatever the div ID or class is you can simply add
#yourDivIDExample {
...
}
#yourDivIDExample img{
border:1px solid #ffffff;
}
This will create a border around the images in the div itself.. same works for classes or global rule also ..
img {
border:1px solid #ffffff;
}
You can do something like this DEMO
HTMl
<div class="imgborder">
<div class="in-imgborder">
</div>
</div>
CSS
.imgborder {
width: 300px;
height: 300px;
position: relative;
background: url(http://placekitten.com/300/300) no-repeat;
}
.in-imgborder {
width: 290px;
height: 290px;
position: absolute;
top: 4px;
left: 4px;
border: 1px solid red;
}
Ok. I have an Angular2 application. Im using an angular component called flex-layout (that let me work with flexbox through directives, thats all). Then, i have a div with class="row" and a dynamic amount of divs inside it. Each dynamic div have an image inside of it.
I need to mark one of those divs as selected, and then add an specific class to it. That class has to put a border-bottom and a background color (already do that), but i need to add a little triangle at the middle of the border-botom on selected div.
Work already done
Fail when selecting another div
As you see on the above images, i managed to put that triangle on the middle of all row (no matter what div i selected)
But, when i change the selected div, triangle doesnt move at all. It always stays at center of the row, and i need the triangle be at the center of selected div instead.
changeSelectedBrand(brandId: number) {
this.selectedBrand = brandId;
}
div.image-row {
height: 90px;
max-height: 90px;
width: 100%;
max-width: 100%;
margin: 0px;
padding: 20px;
background-color: #EEEEEE;
}
.div-image-row-selected {
background-color: #DDDDDD !important;
border-bottom: 3px solid mat-color($primary,400);
}
.div-image-row-selected:after {
content: '';
position: absolute;
top: 100%;
left: 0;
right: 0;
width: 0;
height: 0;
border-top: solid 10px mat-color($primary,400);
border-left: solid 10px transparent;
border-right: solid 10px transparent;
}
div.image-row > img {
height: 65px;
}
<div fxLayout="row">
<div fxFlex="100%" fxLayoutAlign="center center" class="image-row" *ngFor="let brand of brands" [ngClass]="{'div-image-row-selected': brand.id === selectedBrand}" (click)="changeSelectedBrand(brand.id)">
<img src="{{brand.url}}" />
</div>
</div>
The snippet is not functional, i know... is just to show you how things are done right now.
So, repeat the question: How can i make that triangle to move to the center of the bottom border of a selected div?
Thank you
put a position relative wrapper for div.image-row and then update the triangle style(.div-image-row-selected:after) with required left.
div.image-row {
height: 90px;
max-height: 90px;
width: 100px;
max-width: 100%;
margin: 0px;
padding: 20px;
background-color: #EEEEEE;
position: relative;
}
.div-image-row-selected:after {
content: '';
position: absolute;
top: 100%;
left: calc(50% - 10px);
right: 0;
width: 0;
height: 0;
border-top: solid 10px #ff0000;
border-left: solid 10px transparent;
border-right: solid 10px transparent;
}
I've seen all kinds of shapes from tvs to eggs to simple triangles. But how would one make a hyperbolic shape, filled in similar to this nuclear tower shape?
How about using a border-radius with :before and :after pseudo elements?
Demo
Here am using a wrapper element with a class - .wrap and than am nesting a child element with a class - .object, now I will break up the selectors explanation for you, first, am assigning position: relative; for the parent element so that the absolute positioned child elements don't fly out in the wild.. second is I am using an element with overflow: hidden; which is important so that the rounded pseudo elements are hidden..
And at last, I use :before and :after pseudo elements and position them using absolute, and than we have to set it correctly using top, left, right properties respectively.
<div class="wrap">
<div class="object"></div>
</div>
.wrap {
position:relative;
}
.object {
margin: 100px;
position: relative;
overflow: hidden;
background: #fafafa;
width: 180px;
height: 215px;
border-top: 1px solid #aaa;
border-bottom: 1px solid #aaa;
}
.object:before,
.object:after {
content: "";
background: #fff;
position: absolute;
top: -53px;
width: 300px;
height: 320px;
border-radius: 300px;
}
.object:before {
left: -263px;
border-right: 1px solid #aaa;
}
.object:after {
right: -263px;
border-left: 1px solid #aaa;
}
I want to create two trapezoids in css.I can not use the border color because I want to give shapes background-image. Everything should explain the picture. In both div will put i some text.
Can I use html, css, js, svg just do not know how.
http://iv.pl/images/82062332573614452824.jpg http://iv.pl/images/32788252576166741527.jpg
You can achieve this in pure CSS through the usage of the :after pseudo element.
Basically, I created two rectangles. Then I overlayed a triangle on the right rectangle which was added via the :after pseudo element.
jsFiddle example - looks the same
HTML
<div id="wrap">
<div id="one"></div>
<div id="two"></div>
</div>
CSS
div {
float: left;
position: relative;
height: 100px;
}
#one {
background: green;
width: 130px;
}
#two {
background: red;
width: 70px;
}
#two:after {
content: "\A";
border-top: 100px solid transparent;
border-bottom: 60px solid transparent;
border-right: 45px solid red;
position: absolute;
left: -45px;
}
#wrap {
overflow: hidden;
}