Is there a way to create a border on hover for only edges of the div. Here is the basic layout of my grid created using bootstrap. here is my codepen http://codepen.io/anon/pen/zvxEYw
<div class="product-grid col-md-4">
<a class="preview" href="#">PREVIEW</a>
</div>
.product-grid{
margin:30px 0 0 30px;
border:1px solid #ccc;
height:300px;
display:block;
}
.product-grid:hover{
border:1px solid #000;
}
/* Preview */
.preview {
opacity: 0;
position: absolute;
left: 40px;
right: 40px;
top: 0;
height: 30px;
line-height: 32px;
background-color: #fe3;
text-align: center;
text-decoration: none;
color: #000;
transition: .2s;
}
.product-grid:hover .preview {
opacity: 1;
top: 80px;
}
For clear understand I have attached a sample image below
Achieving that kind of effect, is best possible if you use CSS3, and I've done it by using <svg> as:
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%">
<line class="top" x1="0" y1="0" x2="900" y2="0" />
<line class="left" x1="0" y1="460" x2="0" y2="-920" />
<line class="bottom" x1="300" y1="460" x2="-600" y2="460" />
<line class="right" x1="300" y1="0" x2="300" y2="1380" />
</svg>
Here look into my JSFiddle, Hope you're looking something like this.
And it will do the trick for you.
Further customization is no big deal, just look into its CSS and you can changes it as per your requirement.
Source: tympanus
please try this one sir:
#div1 {
position: relative;
height: 100px;
width: 100px;
background-color: white;
border: 1px solid transparent;
}
#div2 {
position: absolute;
top: -2px;
left: -2px;
height: 84px;
width: 84px;
background-color: #FFF;
border-radius: 15px;
padding: 10px;
}
#div1:hover {
border: 1px solid red;
}
DEMO
Related
I'm trying to improve my css skills, and wanted to draw like a moon and outline it. I mad this by using 2 circles and the second one has the same color as the background so it look like a moon. However now i want to outline/ give it a border but i don't know how to do this, because the other parts are overlapped with the secon circle.
body{
position: relative;
background-color: white;
padding-left: 40%;
}
#div1{
position: absolute;
height: 400px;
width: 400px;
border-radius: 100%;
background-image: linear-gradient(45deg, #050182, #51bfdb);
border: 3px solid black;
}
#div2{
position: absolute;
height: 350px;
width: 350px;
background-color: white;
border-radius: 50%;
margin-left: 110px;
margin-top: 25px;
z-index: 2;
}
<div class="container">
<div id="div1"></div>
<div id="div2"></div>
</div>
I would simplify your code using mask then I will rely on drop-shadow filter for the outline
#div1{
filter:drop-shadow(0 0 1px #000) drop-shadow(0 0 0 #000) drop-shadow(0 0 0 #000);
}
#div1:before {
content:"";
display:block;
height: 200px;
width: 200px;
border-radius: 50%;
background-image: linear-gradient(45deg, #050182, #51bfdb);
-webkit-mask: radial-gradient(circle 100px at 80% 50%,#0000 98%,#000);
}
<div id="div1"></div>
You can add border left property to div2 for desired result.
body{
position: relative;
background-color: white;
padding-left: 40%;
}
#div1{
position: absolute;
height: 400px;
width: 400px;
border-radius: 100%;
background-image: linear-gradient(45deg, #050182, #51bfdb);
border: 3px solid black;
}
#div2{
position: absolute;
height: 350px;
width: 350px;
background-color: white;
border-radius: 50%;
margin-left: 110px;
margin-top: 25px;
z-index: 2;
border-left: 3px solid black;
}
<div class="container">
<div id="div1"></div>
<div id="div2"></div>
</div>
Like Justinas already commented, you're kind of trying to do SVG's job in CSS here, which is pretty clunky and inefficient.
If you know a little HTML and CSS, which it seems you do, then SVG will feel like just more of the same.
SVG will just look like a couple new HTML elements to you, and you just sprinkle it right into your HTML; It also just uses the same CSS stylesheet that as your HTML already uses.
To illustrate, run this snippet here; just a couple lines of CSS and some SVG, i'm sure you can tell what 90% of it means instantly.
body { background-color: #FFF; }
svg { background-color: #CCC; }
.gradient_start { stop-color:rgb(255, 255, 0); stop-opacity: 1; }
.gradient_end { stop-color:rgb(255, 0, 0); stop-opacity: 1; }
text { font-family: "Verdana"; font-size: 32pt; }
<html>
<body>
<svg width="400" height="200">
<defs>
<linearGradient id="mygradient" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" class="gradient_start" />
<stop offset="100%" class="gradient_end" />
</linearGradient>
</defs>
<ellipse cx="200" cy="70" rx="85" ry="55" fill="url(#mygradient)" />
<text x="150" y="86" fill="#ffffff">
Turtles !
</text>
</svg>
</body>
</html>
In SVG you have access to a lot more drawing elements, such as the <ellipse> used in this example.
Look at the result, using the border-left property.
body{
position: relative;
background-color: white;
padding-left: 40%;
}
#div1{
position: absolute;
height: 400px;
width: 400px;
border-radius: 100%;
background-image: linear-gradient(45deg, #050182, #51bfdb);
border: 3px solid black;
}
#div2{
position: absolute;
height: 350px;
width: 350px;
background-color: white;
border-radius: 50%;
margin-left: 110px;
margin-top: 25px;
z-index: 2;
border-left: 2px solid black;
}
<div class="container">
<div id="div1"></div>
<div id="div2"></div>
</div>
I am trying to create a ban icon (created from html & css) over an image but I am having a hard time creating it. I have created somewhat static-looking ban icon but it seems perfect and not responsive. Can anyone please guide me on how this can be built?
What i have done so far:
.ban-icon-container{
position: absolute;
top: -10px;
left: 20%;
}
.ban-icon-circle{
width: 290px;
border: 8px solid red;
background: transparent;
height: 290px;
border-radius: 100%;
}
.ban-icon-bar{
height: 1px;
border: 7px solid red;
transform: translate(-1px, -151px) rotate(50deg);
width: 290px;
}
<div class="mt-2 flex align-center">
<div class="m-5 mt-16 mx-auto">
<div class="relative">
<img class="object-contain ban-icon-imgg" src="/img.jpg" alt="img" />
<div class="ban-icon-container">
<div class="ban-icon-circle">
</div>
<div class="ban-icon-bar">
</div>
</div>
</div>
</div>
</div>
Why have you used an attribute named className?
Change the attribute to class and also tweak the marked styles a bit.
Method 1
<style type="text/css">
.ban-icon-container{
position: absolute;
top: -10px;
left: 20%;
}
.ban-icon-circle{
width: 290px;
border: 8px solid red;
background: transparent;
height: 290px;
border-radius: 100%;
}
.ban-icon-bar{
//Change the height to 0px
height: 0px;
border: 7px solid red;
transform: translate(-1px, -151px) rotate(50deg);
//And the width to 240px
width: 240px;
}
</style>
<div class="mt-2 flex align-center">
<div class="m-5 mt-16 mx-auto">
<div class="relative">
<img class="object-contain ban-icon-imgg" src="jpg" alt="img" />
<div class="ban-icon-container">
<div class="ban-icon-circle">
</div>
<div class="ban-icon-bar">
</div>
</div>
</div>
</div>
</div>
Method 2 recommended
You can try using Font Awesome ban icon
I think the best way to create vector icon is SVG. Look at my code this way you can create any icon and this icon will behave like and image. You can scale it accordingly.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Ban Icon</title>
<style>
.ban-icon-container {
position: absolute;
top: 10px;
left: 20%;
}
.ban-icon-circle {
width: 290px;
border: 8px solid red;
background: transparent;
height: 290px;
border-radius: 100%;
}
.ban-icon-bar {
border: 7px solid red;
transform: translate(-1px, -151px) rotate(50deg);
}
</style>
</head>
<body>
<div class="mt-2 flex align-center">
<div class="m-5 mt-16 mx-auto">
<div class="relative">
<img class="object-contain ban-icon-imgg" src="/img.jpg" alt="img" />
<div class="ban-icon-container">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="101" height="101" viewBox="0 0 101 101" preserveAspectRatio="xMidYMid meet">
<circle cx="51" cy="51" r="48" stroke="black" stroke-width="3" fill="none" />
<line x1="17" y1="84" x2="84" y2="17" stroke="black" stroke-width="3" />
</svg>
</div>
</div>
</div>
</div>
</body>
</html>
This is the only code that is creating your ban icon. You can change colors and stroke width
<svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="101" height="101" viewBox="0 0 101 101" preserveAspectRatio="xMidYMid meet">
<circle cx="51" cy="51" r="48" stroke="black" stroke-width="3" fill="none" />
<line x1="17" y1="84" x2="84" y2="17" stroke="black" stroke-width="3" />
</svg>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.wrapper {
position: relative;
width: 220px;
height: 220px;
}
img {
width: 100%;
height: 100%;
border-radius: 6px;
}
.ban-icon::before,
.ban-icon::after {
position: absolute;
display: block;
content: '';
width: 70%;
height: 35%;
border-top-left-radius: 100px;
border-top-right-radius: 100px;
border: 10px solid red;
z-index: 1;
}
.ban-icon::before {
top: 15%;
right: -8px;
transform: rotate(45deg);
border-bottom: 10px solid red;
}
.ban-icon::after {
bottom: 15%;
left: -8px;
transform: rotate(-135deg);
border-bottom: 0;
}
<div class="wrapper">
<div class="ban-icon"></div>
<img src="https://www.w3schools.com/html/img_chania.jpg">
</div>
I have a schematic as follows:
How can I use css and html to draw out such a thing?
I tried some of the ways, but it can not create the border for the triangle, I want the triangles to have borders, and I can set the border to two sides or one edge or all the edges of those triangles. .
Here is the code that I tried with the first pentagon:
<style type="text/css">
div {
position: relative;
width: 200px;
height: 150px;
background: #4275FF;
}
div:after {
content: '';
position: absolute;
width: 0;
height: 0;
border-top: 75px solid transparent;
border-bottom: 75px solid transparent;
border-left: 25px solid #4275FF;
right: -25px;
}
</style>
<div></div>
Another alternative
div {
position: relative;
width: 200px;
height: 150px;
background: #EEE;
border: 1px dashed #777;
position: relative;
}
div.v2 {
border-right: 0px;
}
div:after {
content: '';
z-index: -1;
transform: rotate(135deg);
background: inherit;
border: inherit;
width: 106px;
height: 106px;
top: 21px;
right: -53px;
position: absolute;
}
<div></div>
<div class="v2"></div>
I think the SVG is the best way to create the border for the triangle.
See the code, 'polyline' create a triangle. three 'line' are the border of the triangle, and you can change the color of these lines through the style-stroke-color.
<svg>
<polyline points="10,10 50,50 10,90" style="fill:#006600;stroke:#fff;" />
<line x1="10" y1="10" x2="50" y2="50" style="stroke:#ff0000;" stroke-width="2" />
<line x1="50" y1="50" x2="10" y2="90" style="stroke:#00ff00;" stroke-width="2" />
<line x1="10" y1="10" x2="10" y2="90" style="stroke:#0000ff;" stroke-width="2" />
</svg>
This question already has answers here:
Wave (or shape?) with border on CSS3
(5 answers)
Closed 6 years ago.
How to design This Image
I want to design this type image.
.container {
background: #fff;
padding: 20px;
}
.round {
width: 100px;
height: 100px;
border: solid 2px #000;
position: relative;
}
.round:before {
content: '';
width: 20px;
height: 20px;
background: #fff;
border-bottom: solid 2px #000;
position: absolute;
top: -12px;
left: -11px;
transform: rotate(315deg);
}
.round:after {
content: '';
width: 20px;
height: 20px;
background: #fff;
border-top: solid 2px #000;
position: absolute;
bottom: -12px;
right: -11px;
transform: rotate(315deg);
}
<div class="container">
<div class="round"></div>
</div>
hat do you think?
Perhaps look at using an inline svg image, this would give you control over background image, and would allow for the shape to "scale", and if you like, change the background color (fill) when you like.
HTML
<div class="cornered-box">
<div class="svg-cont">
<svg width="200px" height="200px" viewBox="635 375 202 202" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<polygon id="path-1" points="675.163277 376 836 376 836 535.221624 796.221624 575 636 575 636 414.163277"></polygon>
</defs>
<use stroke="#000000" stroke-width="2" fill="transparent" xlink:href="#path-1"></use>
</svg>
</div>
<div class="cornered-box-content">
<p>
Some content for the box
</p>
</div>
</div>
CSS
.cornered-box{
height:200px;
width:200px;
position: relative;
padding:20px 5px;
box-sizing:border-box;
}
.cornered-box .svg-cont{
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
z-index:-1;
}
.cornered-box .svg-cont svg{
height:100%;
width:100%;
}
.cornered-box .svg-cont svg use{
fill:transparent;
transition: fill 0.2s ease-in-out;
}
.cornered-box:hover .svg-cont svg use{
fill:#F00;
}
JSFIDDLE
Link to SVG
I want to have a design where my main div(box) will be looking something like below, where i don't want my right top border to be chucked off. Can you please help me in designing the same.
You could use :after pseudo element
div {
width: 250px;
height: 150px;
border: 2px solid #677D50;
border-bottom: 20px solid #677D50;
margin: 50px;
background: white;
position: relative;
}
div:after {
content: '';
position: absolute;
right: 0;
top: 0;
width: 70px;
height: 70px;
background: white;
border-bottom: 2px solid #677D50;
transform: rotate(46deg) translateY(-52px);
}
<div></div>
Or SVG
rect {
fill: #677D50;
}
polygon {
fill: none;
stroke: #677D50;
stroke-width: 2;
stroke-miterlimit: 10;
}
<svg x="0px" y="0px" width="400px" height="250px" viewBox="0 0 400 250">
<polygon points="378,230 24.5,230 24.5,20.5 339,20.5 378,52.5 " />
<rect x="24.5" y="203" width="353.5" height="27" />
</svg>