I have been trying to achieve the same result as shown in the image with plain CSS.
I have tried using a background image (cover...), but it's not responsive (cuts the shape)
I managed to get a similar result with clip-path but not the round corners, and also is not supported with all browsers.
.shape {
background:#16489F;
clip-path: polygon(5% 0, 95% 0, 100% 50%, 95% 100%, 5% 100%, 0% 50%);
}
What I'm aiming for:
Thank you very much
Here is an idea based on this previous answer:
.box {
margin:20px auto;
font-size:22px;
min-width:200px;
display:table;
padding:10px 30px;
box-sizing: border-box;
text-align:center;
color:#fff;
position:relative;
z-index:0;
}
.box::before,
.box::after,
.box span::before,
.box span::after{
content:"";
position:absolute;
z-index:-1;
top:0;
left:0;
right:50%;
bottom:50%;
background:#16489F;
border-radius:10px 0 0 0;
transform:var(--s,scaleX(1)) skew(-35deg);
transform-origin:right bottom;
}
.box::after {
--s:scalex(-1);
}
.box span::before {
--s:scaleY(-1);
}
.box span::after {
--s:scale(-1);
}
<div class="box"><span></span> some text here</div>
<div class="box"><span></span> more and more <br> text here</div>
<div class="box"><span></span> even more <br> and more <br> text here</div>
<div class="box"><span></span> long long loooooonooooog text <br> and more <br> text here</div>
Like below if you want the radius on the edges:
.box {
margin:20px auto;
font-size:22px;
min-width:200px;
display:table;
padding:10px 30px;
box-sizing: border-box;
text-align:center;
color:#fff;
position:relative;
z-index:0;
}
.box::before,
.box::after,
.box span::before,
.box span::after{
content:"";
position:absolute;
z-index:-1;
top:0;
left:0;
right:50%;
bottom:calc(50% - 5px);
background:#16489F;
border-radius:10px 0 0 11px;
transform:var(--s,scaleX(1)) skew(-35deg);
transform-origin:100% calc(100% - 5px);
}
.box::after {
--s:scalex(-1);
}
.box span::before {
--s:scaleY(-1);
}
.box span::after {
--s:scale(-1);
}
<div class="box"><span></span> some text here</div>
<div class="box"><span></span> more and more <br> text here</div>
<div class="box"><span></span> even more <br> and more <br> text here</div>
<div class="box"><span></span> long long loooooonooooog text <br> and more <br> text here</div>
An element can have multiple background images so you could use images for the end caps and a matching color fill for the actual content area.
This demo is rough but it demonstrates the idea. I've left the fill an obviously different color to make it easier to see what's what. I'm using quick screenshots of your sample image and I caught a bit of the edge, causing the lines extending from the caps. But you get the idea.
.demo {
padding: 24px 72px;
color: white;
background-color: skyblue;
background-image:
url(https://i.imgur.com/LocAlN0.png),
url(https://i.imgur.com/zXDA91q.png);
background-repeat: no-repeat;
background-size: contain;
background-position: 0 center, center right;
}
<div class="demo">
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots.
</div>
I would use 3 divs, first and last with background-images (the irregular shape) and the one in the middle with background-color instead.
Related
Need to achieve the following screenshot design with CSS. Have attached fiddle link with whatever tried.
<div class="outer">
<div class="inner">
</div>
</div>
.outer{
position:relative;
}
.inner{
position:absolute;
right:0;
bottom:2;
width: 200px;
height: 200px;
background: linear-gradient(to bottom right,transparent 50%,#374073 -63.76%,#26D0CE 100%);
}
https://jsfiddle.net/antoclintonasr/djtcLh8e/1/
I made some changes as you can in the code snippet.
The border radius to make the triangle edge smooth and the transform to rotate the triangle. You can adjust the width and height of the inner rectangle to make the final shape thinner and longer if you want, and you can change the rotate angle to change the angle of the triangle.
.outer{
position:relative;
}
.inner{
position:absolute;
right:0;
bottom:2;
width: 200px;
height: 200px;
background: linear-gradient(to bottom right,transparent 50%,#374073 -63.76%,#26D0CE 100%);
/* new code */
border-radius: 0 0 20px 0;
transform: rotate(135deg);
}
<div class="outer">
<div class="inner">
</div>
</div>
I have a div and I would like half of the div to be covered in a gradient and the other half to be a normal image but with the same effect as background-size:cover; and have it fill up the remaining space to the right of the gradient. Is this possible?
div {
width:100%;
height:400px;
background-image:url(http://placehold.it/100x100);
background-size: 50% cover;
background-position: 100% center;
background-repeat:no-repeat;
}
div:before {
content:"";
display:block;
width:50%;
height:100%;
background-image: linear-gradient(red, yellow);
}
<div></div>
Unfortunately this doesn't seem to work. I can use background-size: 50% auto; but that doesn't give me quite what I am looking for. I realize I could just split this into two divs, but I just wanted to see if it was possible to do it with one.
Use multiple background and some padding, background-origin trick. The idea is to define padding as half the width and put the image on the content-box which will be the other half.
You have to use vw unit but there is a small drawback as it consider the width of the scroll. It can also be an issue if the div is not meant to be a full width div.
.box {
padding-left:50vw;
height:300px;
background:
linear-gradient(red, yellow) left/50vw 100%,
url(http://placehold.it/400x400) center/cover content-box;
background-repeat:no-repeat;
}
body {
margin:0;
}
<div class="box"></div>
Or simply use both pseudo element:
.box {
height:300px;
position:relative;
}
div::before,
div::after {
content:"";
position:absolute;
top:0;
bottom:0;
width:50%;
}
div::before {
left:0;
background:linear-gradient(red, yellow);
}
div::after {
right:0;
background:url(http://placehold.it/400x400) center/cover;
}
body {
margin:0;
}
<div class="box"></div>
Two images each 50% width. I want to hover on the left image and it should widen to 52% over the right image. The right image should not move. Hover the right image and it should widen to 52% over the left image and the left image should not move.
Two issues...
1. The hover over the left image works but moving off it, it doesn't transform gracefully back to 50% but instead, it jumps back as if no transition effect is applied.
2. hovering the right image moves the right image to the left instead of expanding it.
CSS is shown here and I can't seem to identify what part(s) is/are incorrect so I am asking for help.
<style>
body{
box-content: border-box;
}
.photo_section_new {
display:flex;
}
.photo_section_new > div {
height:800px;
flex-grow:1;
transition:0.5s;
background-size:cover;
background-position:center;
background-repeat: no-repeat;
}
.photo_section_new > div:nth-child(1) {
border-bottom: 20px solid #c54985;
border-top: 20px solid #c54985;
background:#000 url(https://picsum.photos/id/1003/600/600);
background-size: cover;
}
.photo_section_new > div:nth-child(2) {
border-bottom: 20px solid #005d99;
border-top: 20px solid #005d99;
background:#000 url(https://picsum.photos/id/103/600/600);
background-size: cover;
}
.photo_section_new > div:nth-child(3) {
display:none;
}
.photo_section_new > div:hover {
flex-grow:1.1;
}
</style>
<div class='photo_section_new'>
<div id='main_photo'>
</div>
<div id='second_photo'>
</div>
<div class='clear'></div>
</div>
Neither image should move/change position. They should each just expand over the other when they are hovered over. I'd appreciate any suggestions you might have.
You are overcomplicating a simple task. Here is an easier idea using flexbox:
.container {
display:flex;
}
.container > div {
height:200px;
border-bottom:5px solid;
flex-grow:1;
transition:0.5s;
background-size:cover;
background-position:center;
}
.container > div:first-child {
background-image:url(https://picsum.photos/id/1003/600/600)
}
.container > div:last-child {
background-image:url(https://picsum.photos/id/103/600/600)
}
.container > div:hover {
flex-grow:1.1;
}
<div class="container">
<div></div>
<div></div>
</div>
I have a div and im trying to scale it(just the Y) on hover.The problem is that it works well without transition.When i use transition,the div scales at top a bit and then goes down,check the fiddle.The question is how to prevent div from scalling like that?I want it to scale straight down,without this bouncing to top.
http://jsfiddle.net/q9akawr6/21/
HTML
<div></div>
CSS
div{
width:100px;
height:100px;
margin:100px;
background-color:red;
transition:.2s;
}
div:hover
{
transition:.2s;
transform-origin:top;
transform:scaleY(2.0);
}
As Niet says, or just put this in the div{} rule, rather than div:hover{}:
transition:.2s;
transform-origin:top;
for the same reason (to avoid a transition on transform-origin at the wrong time).
the div bouncing due to you margin area. I try to change your code. check the following
HTML:
<div class="container">
<div class="demo"></div>
</div>
CSS:
div.container
{
width:300px;
height:300px;
border:1px solid gray;
}
div.demo{
width:100px;
height:50px;
margin: 100px auto;
background-color:red;
transition:.2s;
transform-origin: left top;
}
div.demo:hover
{
transition:all .2s linear;
transform-origin: top;
transform:scaleY(2.0);
}
I am attempting to display a background non-repeated picture on the top right corner of my div. I am using the following code
<html>
<head>
<style>
.UseA
{
display:block;
/* Display image in the top left corner */
background-image:url('paper.gif');
*/--------------------------------------*/
text-indent:10px;
border-radius: 10px;
background: #BADA55;
min-height:50px;
width:300px;
}
.UseA .dta
{
display:block;
border-radius: 10px;
width:130px;
background-color:grey;
color:white;
position:relative; /*Relative to normal position*/
left:160px; /*Move away from left*/
}
</style>
</head>
<body>
<div class="UseA">
Hello , My name is Jim
<div class="dta">something here</div>
</div>
</body>
</html>
However The image is not being displayed.
I am trying this code out here Any suggestions on what I might be doing wrong ?
You declare background: #BADA55; after background-image, so it's overwriting it.
Try this instead:
UseA {
display:block;
text-indent:10px;
border-radius: 10px;
background: #BADA55 url('paper.gif') no-repeat top right;
min-height:50px;
width:300px;
}
You're overwriting background-image with background. Combine them:
http://jsfiddle.net/isherwood/ANr6K/
background: url('image.png') right top no-repeat #BADA55;
If your papaer.gif asset is correct, then remove your background color for .UseA
.UseA
{
display:block;
/* Display image in the top left corner */
background-image:url('paper.gif');
*/--------------------------------------*/
text-indent:10px;
border-radius: 10px;
background: #BADA55;
min-height:50px;
width:300px;
}
Change to
.UseA
{
display:block;
/* Display image in the top left corner */
background-image:url('paper.gif');
*/--------------------------------------*/
text-indent:10px;
border-radius: 10px;
min-height:50px;
width:300px;
}
Sample on Fiddle using Google image as a background: http://jsfiddle.net/C9qdL/