CSS Card Shape Masking - css

there is a problem that I can't solve in css, or rather, I can't solve it easily. I have a design like this and I couldn't figure out how to make the corners. The long and hard way I can mask with svg but this time corners creep when content gets longer.
image
I try thisaI tried saving this shape as svg and masking it to the card but when the size changes, there is creep.
And i try clip path but my corners is rounded like that
here

You can use a border-image that has the right corner shape. For border-image-slice, you give the relative size of the rounded corners as they are drawn in your image. The parts in the middle will then be stretched as needed.
I've used a SVG image that imitates your example, but you can easily exchange that for your own design. The only thing you need to do is define the color inside the data url. If you want to change it via CSS of the card during run tim, you need to exchange the whole url.
body {
background: grey;
}
.card {
border: 20px solid;
border-image-source: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path fill="white" d="M 60,0 Q 70,0 85,15 T 100,40 L 100,60 Q 100,70 85,85 T 60,100 L 40,100 Q 30,100 15,85 T 0,60 L 0,40 Q 0,30 15,15 T 40,0 Z" /></svg>');
border-image-slice: 40% fill;
border-image-width: 2;
padding: 0 30px;
}
<div class="card">Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>

What I think you are looking for is clip path possibly
clip-path: polygon(20% 0%, 80% 0%, 100% 20%, 100% 80%, 80% 100%, 20% 100%, 0% 80%, 0% 20%);

Related

CSS for box-shadow under text [duplicate]

This question already has answers here:
Thick underline behind text
(7 answers)
How to increase width of underline for the multiline text when on hover
(6 answers)
Closed 2 years ago.
I'm not very good at this and I'm basically just googling everything. I'm trying to figure out how I could do a box shadow at the bottom of a text. Kinda like the image below (screencapped from a random blog/site).
I've managed to add the border but it extends to the length of the site instead of just under the text. So I don't know where to go from here.
You can do this by setting the background-image of the element that contains your text with a linear-gradient.
For example:
.underlined {
background-image: linear-gradient(180deg, transparent 0 60%, #f0640780 0 100%);
}
<p>
<span class="underlined">Lorem ipsum dolor sit amet</span>, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
You can use this css code to do what you want box-shadow: 3px 15px 5px 0px rgba(50, 50, 50, 0.75);

Border vs. padding in CSS

I'm attempting to understand the exact relation between padding and border in CSS.
Would it be accurate to say that a solid border of transparent color is essentially the same thing as the same amount of padding, and can be expected to behave similarly- except insofar as they will coexist on the same element rather than overwriting each other?
In other words, is there any case in which:
#Square1{
padding: 50px;
}
, if replaced with:
#Square1{
border-style: solid;
border-width: 50px;
border-color: transparent;
}
would be expected to display different behavior in any meaningful way, except if there was something like this in the same CSS file:
.ClassThatSquare1HappensToHave{
border-style: solid;
border-width: 50px;
border-color: transparent;
}
, in which case you will effectively end up with twice the amount of border/padding/element-expanding space?
Maybe this is what you are looking for. Note how overflow behaves differently both in the content that is left displayed (which is clipped to the padding edge) and the position of the scrollbar, which sits outside padding, but inside border.
#Square1{
padding: 50px;
}
#Square2{
border-style: solid;
border-width: 50px;
border-color: transparent;
}
body {
width:400px;
}
div {
background-color:lightblue;
height:100px;
overflow:auto;
}
<div id="Square1">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
<hr>
<div id="Square2">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
They both belong to CSS box model but they serve different purposes.
In the box model :
The padding area, bounded by the padding edge, extends the content area to include the element's padding. Its dimensions are the padding-box width and the padding-box height.
(...)
The border area, bounded by the border edge, extends the padding area
to include the element's borders. Its dimensions are the border-box
width and the border-box height(...)
If the box-sizing property is set to border-box, the border area's
size can be explicitly defined with the width, min-width, max-width,
height, min-height, and max-height properties.
With that said, you should use padding whenever you want to give inner space and use border to give exactly what it states - a border - a line that if has padding will show after the padding area.

Keep the text from being cut off when using shape-inside with CSS div boxes

New to this. I checked out many resources, but I could not get this to work.
Objective: Keep the text from being cut off when using shape-inside with CSS div boxes.
Here is a link to the code that does not work.
http://jsfiddle.net/0u8tk7o5/
Thanks for helping me out.
.container {
-webkit-clip-path: polygon(50% 0%, 100% 100%, 0 100%);
shape-inside: polygon(50% 0%, 100% 100%, 0 100%);
height: 200px;
width: 400px;
background-color: crimson;
}
</style>
</head>
<body>
<div class="container">
<p>"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
</div>
shape-inside doesn't seem to be implemented yet so you'd need to use shape-outside to achieve the effect you want. In your case you could achieve a triangular shape by specifying left and right bounding shapes that effectively create a triangle like this:
.main {
width: 500px;
background-color: yellow;
}
.left,
.right {
width:50%;
height:200px;
}
.left {
-webkit-shape-outside: polygon(0% 0%, 100% 0%, 0% 100%);
shape-outside: polygon(0% 0%, 100% 0%, 0% 100%);
-webkit-clip-path: polygon(0% 0%, 100% 0%, 0% 100%);
float: left;
background-color: crimson;
}
.right {
-webkit-shape-outside: polygon(0% 0%, 100% 0%, 100% 100%);
shape-outside: polygon(0% 0%, 100% 0%, 100% 100%);
-webkit-clip-path: polygon(0% 0%, 100% 0%, 100% 100%);
float: right;
background-color: blue;
}
<div class="main">
<div class="left"></div>
<div class="right"></div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
This jsfiddle shows it: http://jsfiddle.net/g2rqa0uL/

IE reverses expected SVG's percentage background-position behaviour

I'm positioning a background SVG with CSS in a responsive element with the following code:
var theSVG = '<svg version="1.1" id="Layer_3" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 300 300" enable-background="new 0 0 300 300" xml:space="preserve" preserveAspectRatio="xMinYMin"><g><path fill="#888888" d="M218.7,272.5l-38.6-80.6c-0.4-1.1-1.6-1.1-2.8-0.7l-23.4,8.8h-7.8l-23.4-8.8c-1.1-0.4-2.4-0.1-2.8,1 l-38.6,80.4c-0.4,1.1,0.2,2.3,1.3,2.7l2.4,0.8c1.1,0.4,2.4-0.2,2.8-1.3l49.5-56.9l8.5,77.9c0,1.2,1,2.3,2.2,2.3h3.2 c1.2,0,2.2-1.1,2.2-2.3l8.6-79l50.2,58c0.4,1.1,1.6,1.7,2.8,1.3l2.4-0.8C218.5,274.8,219.1,273.6,218.7,272.5z"/><path fill="#555555" d="M184.2,2h-66.5C108.1,2,100,9.7,100,19.4v103c0,8,5.5,14.8,12.8,16.9c-1.3,1.2-2.2,2.8-2.2,4.7l7.8,52 c0,3.5,2.9,6.9,6.3,6.9h50.9c3.5,0,6.3-3.4,6.3-6.9l9.3-51.7c0-1.9-0.3-3.7-1.6-4.9c7.4-2.1,13.3-9.1,13.3-17.1v-103 C203,9.7,194,2,184.2,2z M192,112.9c0,3.4-2.7,6.1-6.1,6.1h-67.7c-3.4,0-6.1-2.7-6.1-6.1V19.1c0-3.4,2.7-6.1,6.1-6.1h67.7 c3.4,0,6.1,2.7,6.1,6.1V112.9z"/><path fill="#888888" d="M205.6,184.5H96.5c-1.3,0-2.3-1.1-2.3-2.3v-9c0-1.3,1.1-2.3,2.3-2.3h109.1c1.3,0,2.3,1.1,2.3,2.3v9 C207.9,183.5,206.8,184.5,205.6,184.5z"/><g><path fill="#AAAAAA" d="M119.9,151h-28c-2.9,0-5.2-2.3-5.2-5.2V31.4c0-2.9,2.3-5.2,5.2-5.2h28c2.9,0,5.2,2.3,5.2,5.2v114.5 C125.1,148.7,122.8,151,119.9,151z"/><path fill="#AAAAAA" d="M210.2,151h-28c-2.9,0-5.2-2.3-5.2-5.2V31.4c0-2.9,2.3-5.2,5.2-5.2h28c2.9,0,5.2,2.3,5.2,5.2v114.5 C215.3,148.7,213,151,210.2,151z"/><path fill="#AAAAAA" d="M151,91c-13.1,0-23.8-10.7-23.8-23.8s10.7-23.8,23.8-23.8s23.8,10.7,23.8,23.8S164.1,91,151,91z M151,52.1 c-8.3,0-15.1,6.8-15.1,15.1s6.8,15.1,15.1,15.1c8.3,0,15.1-6.8,15.1-15.1S159.4,52.1,151,52.1z"/></g></g></svg>';
var theSVG64 = window.btoa(theSVG);
document.getElementById('svgholder').style.backgroundImage = "url('data:image/svg+xml;base64,"+theSVG64+"')";
.svgholder {
background-color: #444;
/* background-image: url("path-to-my-svg.svg"); */
/* On the site the svg is specified above, but for this example I'm setting the data with JS so the contents can be seen un-base64 encoded */
background-size: auto 130%;
background-repeat: no-repeat;
background-position: left 10% top 20%;
width: 80%;
min-width:640px;
min-height:300px;
margin: auto;
padding: 1em;
color: whitesmoke;
}
<div class="svgholder" id="svgholder">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
<p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
If this is viewed in any modern browser other than IE, the background-position: left 10% top 20% property causes the SVG to shift right by 10%, and up by 20%. In IE(10/11) it shifts left by 10% and up by 20%.
If a negative percentage is set, i.e. background-position: left -10% top 20% the reverse happens. Note that the top 20% renders the same in all cases.
You'll see I'm using four-value syntax here, but the same happens if it's two-value. i.e. background-position: 10% 20%;
I wonder if this an IE bug, and if there is a workaround that would make IE behave like the others.
Bonus oddity: If preserveAspectRatio="none" is set in the SVG, the effect is reversed. IE 'adds' the percentage set, and others subtract it from the position.

How to make foreground image in div take up full width/height of screen

I need to make an image auto-fill the width and height of the viewer's screen, while keeping the correct aspect ratio. The ultimate goal is to display a jquery slideshow in the background of the page, while also making it fill the full width and height of the screen.
This jfiddle shows an approximation of what I am talking about: http://jsfiddle.net/hockey2112/s1d2peqh/1/
Here is the CSS from that jfiddle:
#slideshow {
height: auto;
position: fixed;
width: 100%;
z-index: -1;
}
.slide img {
height: auto;
width: 100%;
}
.contentbox {
background-color: #ffffff;
border:5px solid #000000;
margin: 0 auto;
width: 300px;
}
and the code:
<div id="slideshow">
<div class="slide">
<img src="http://www.iapics.org/images/3542-wallpaper-landscape-wallpapers-1920x1080.jpg">
</div>
</div>
<div id="content">
<div class="contentbox">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
</div>
I need the image to fit the height of the screen first, and then show as much of the width of the image as will fit in the screen. If you expand and contract the viewport of that jfiddle, you'll see that the image does not fill the height of the preview panel.
Thanks!
I'm not aware of a way to do this in CSS alone.
You can either have the image stretched to 100% horizontally and centered vertically OR you can stretch 100% vertically and center horizontally.
However, with a little but of js, you can switch between these two options pretty easily, and that should get you what you want.
Horizontal Stretch + Vertical Center:
.slide.horz{
height:100%;
width:100%;
}
.slide.horz img {
width: 100%;
height:auto;
display:block;
margin:auto;
position:absolute; /*trick for vertical center*/
top:0; /*trick for vertical center*/
bottom:0; /*trick for vertical center*/
}
Vertical Stretch + Horizontal Center:
.slide.vert{
height:100%;
width:300%; /* trick for 'zoomed' horizontal center */
margin-left:-100%; /* trick for 'zoomed' horizontal center */
}
.slide.vert img {
height: 100%;
width:auto;
display:block;
margin:auto;
}
Then some jquery will let you switch between the classes based on the aspect ratio of the window.
$(window).resize(function() {
setStyle();
});
function setStyle(){
var winRat=($(window).width() +0.0)/($(window).height() + 0.0);
var imgRat = 1920.0 / 1080.0;
//do vertical stretching
if( winRat < imgRat){
$(".slide").removeClass("horz");
$(".slide").addClass("vert");
}else{
//do horizontal stretching
$(".slide").removeClass("vert");
$(".slide").addClass("horz");
}
}
Have only tested this in latest chrome. I have reason to believe it may break in ie<=8.
http://jsfiddle.net/s1d2peqh/3/
This is the purpose of the VH (viewport height) and VW (viewport width)
body { width:100%;height:100%; }
#slideshow { height: 100vh;position: fixed;width: 100vw;z-index: -1; }
.slide img { height: 100vh;width: 100vw; }

Resources