Html slanted image? - javascript

Hello is it possible to make a image have a slanted right side border.
.fh {
border-right: 180px solid transparent;
}
<div class="fh"><img src="img/fh.jpg" style="max-height: 500px;"></div>
So what I basically want is this http://prntscr.com/glcq2l but with the image instead.

One possible solution is to have a div which you rotate and set overflow hidden. There is a wrap around it, just in case you want to use it it makes it easier to place the image.. fiddle to play around here (I left the borders just to help understand whats going on)
(The background image on the body is just there to show that the cut off corner is transparent and not a border or anything like that.)
body {
background-image: url(https://i.stack.imgur.com/xxGZk.jpg);
}
* { box-sizing: border-box; }
.wrap {
position: relative;
width: 400px;
height: 200px;
border: solid 2px black;
overflow:hidden;
}
.fh {
position: relative;
top: -5px;
left: -250px;
width: 600px;
height: 700px;
transform: rotate(45deg);
overflow: hidden;
border-top:solid 1px red;
border-bottom:solid 1px red;
border-left:solid 1px orange;
border-right:solid 1px lime;
}
.fh img {
position: absolute;
margin: -30px 0px 0 30px;
top: 0px;
left: 0px;
border:solid 2px green;
width: 400px;
height: 200px;
transform: rotate(-45deg);
}
<div class="wrap">
<div class="fh">
<img src="http://lorempixel.com/400/200/sports/1/" >
</div>
</div>
A lot of answers and possible solutions can also be found here: Cut Corners using CSS of course they need to be tweaked to your request.

Related

how to ovelap a image on other image by styling scss in reactjs?

I have a design. In this design, one is overlapping on another image. I have created some code to try as given in the design. but it's not working for me. Click here to find the design
Below is some line of code of components. that is tried by me
<div className="container">
<Image className="container-img1" src={img1}/>
<Image className="container-img2" src={img2}/>
</div>
below is a style in scss
.container{
text-align: center;
.container-img1{
position: inherit;
left: 0;
top: 0;
height: auto;
border-radius: 50%;
border: 3px solid grey;
margin-right: -5rem;
}
.container-img1{
position: inherit;
left: 0;
top: 0;
height: auto;
border-radius: 50%;
border: 3px solid grey;
margin-left: -5rem;
}
}
Click Here to check what I have designed. but it's not looking as given in design.
How can I style the same as given in Design? And should be responsive also.
To achieve the demo image you can eliminate the border with transparency for the img2 that has higher stack order in DOM.
.container-img1 {
position: inherit;
left: 0;
top: 0;
height: 7rem;
border-radius: 50%;
border: 3px solid grey;
/* Reduce the margin so that the border aligns properly */
margin-right: -1.1rem;
}
.container-img2 {
position: inherit;
left: 0;
top: 0;
height: 7rem;
border-radius: 50%;
border: 3px solid grey;
/* Reduce the margin so that the border aligns properly */
margin-left: -1.1rem;
/* make it transparent */
border-left-color: transparent;
}
To make it responsive, the image width seems very small but you need to adjust the width & margin according to the device size using media query.

Forcing other element's content to be moved by the same vertical amount

I have stumbled upon a frontend problem where I cannot figure out what the best approach is.
The simplified layout I need to achieve can be looked up here: https://jsfiddle.net/kw56sa84/
content-block {
min-height: 100px;
background: #aaa;
border: 1px solid;
}
.end-of-body-block {
width: 50%;
margin: 0 auto;
padding: 30px;
border: 1px solid #a00;
position: relative;
transform: translateY(50%);
text-shadow: 0 0 2px #fff;
background: rgba(250, 180, 180, 0.9)
}
.footer {
min-height: 300px;
background: #0A152B;
color: #fff;
}
<div class="wrapper">
<div class="content">
<div class="content-block">Some content</div>
<div class="content-block">Some content</div>
<div class="end-of-body-block">
Some text here that can have into a dynamic height, and responsively height increases.
</div>
</div>
<div class="footer">
Links and other information that should be visible
</div>
</div>
Basically what I have are content and footer and there is a block that should be 50% in the body and 50% in the footer, and have both element contents moved by a dynamic half-height of the connecting element. In the jsfiddle example, the footer content should have some sort of padding. The height of all elements is dynamic.
The main question I suppose here is - is it possible to achieve this with CSS (solution may include grids, flexboxes), or am I out of luck and should seek a JS solution?
EDIT Here you can see a simplified design that should be achieved:
Thanks in advance!
Based on your explication you want that class: "end-of-body-block" be positionned dynamicly between body and footer.
The basic idea is to remove the red box from the normal flow by using position: absolute; but by doing that, it is loosing basic position strucutre. So we fix it with parent with position: relative;. Which is classic move.
To do so, I added position:relative; in .content:
.content{
position:relative;
}
And then I postionned absolute your red block as followed:
.end-of-body-block{
position: absolute;
bottom: 0;
left: 50%;
transform: translate(-50%, 50%);
}
EDIT
JS to add dynamic padding on content and footer.
DEMO:
var heightRed = document.getElementsByClassName('end-of-body-block')[0].offsetHeight;
heightRed = (heightRed / 2) + 2 + 'px';
var content = document.getElementsByClassName('content')[0]
var footer = document.getElementsByClassName('footer')[0]
content.style.paddingBottom = heightRed;
footer.style.paddingTop = heightRed;
.content{
position:relative;
}
.content-block {
min-height: 100px;
background: #aaa;
border: 1px solid;
}
.end-of-body-block {
width: 50%;
margin: 0 auto;
padding: 30px;
border: 1px solid #a00;
/*position: relative;
transform: translateY(50%);*/
text-shadow: 0 0 2px #fff;
background: rgba(250, 180, 180, 0.9);
position: absolute;
bottom: 0;
left: 50%;
transform: translate(-50%, 50%);
}
.footer {
min-height: 300px;
background: #0A152B;
color: #fff;
}
<div class="wrapper">
<div class="content">
<div class="content-block">Some content</div>
<div class="content-block">Some content</div>
<div class="end-of-body-block">
Some text here that can have into a dynamic height, and responsively height increases.
</div>
</div>
<div class="footer">
Links and other information that should be visible
</div>
</div>
After a few hours of trial and error, I came up with an idea of how to solve this. It's a real hacky solution, but in my case it actually works, maybe someone else will find it useful.
So in my case the footer had an image background, thus making it more difficult to think of this, however.. solution here could be to simulate the same background as the other part where your element isn't.
To elaborate, instead of trying to move the other element's content, make it seem that it does so. I moved the red box to the footer instead, so it takes up the whole height it needs. Then add a pseudo (before) element as absolute to the red box's parent and make it full width and 50% of it's height. See here for example https://jsfiddle.net/co35svtd/4/
.content {
position: relative;
z-index: 0;
width: 100%;
display: inline-block;
}
.wrapper {
background: #eee;
}
.content-block {
min-height: 100px;
background: #aaa;
border: 1px solid;
}
.footer-block-wrapper {
position: relative;
}
.end-of-body-block {
width: 50%;
margin: 0 auto 0;
padding: 30px;
border: 1px solid #a00;
text-shadow: 0 0 2px #fff;
background: rgba(250, 180, 180, 0.9);
box-sizing: border-box;
z-index: 10;
}
.end-of-body-block:before {
content: '';
z-index: -1;
position: absolute;
height: 50%;
width: 100%;
top: 0;
left: 0;
right: 0;
background: #fff;
}
.footer {
min-height: 300px;
background: #0A152B;
color: #fff;
position: relative;
z-index: 100;
}
<div class="wrapper">
<div class="content">
<div class="content-block">Some content</div>
<div class="content-block">Some content</div>
</div>
<div class="footer">
<div class="footer-block-wrapper">
<div class="end-of-body-block">
Some text here that can have into a dynamic height, and responsively height increases.
</div>
</div>
Links and other information that should be visible
</div>
</div>
I know it's not the answer I was looking for, but this hack does the job for me.

Content appear outside the div

I recently tried out the div with different shape like triangle trapezoid etc.
HTML:
<div class="triangle">HI nice to meet you guys</div>
CSS
.triangle {
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 100px solid blue;
}
Previously, the content appears properly when the div is a square (height and width are 100px).
When I style the div to look like a triangle, then the content oveflows.
How can I make this one as proportional in order to appear properly inside the div.
See fiddle: http://jsfiddle.net/7qbGX/2/
Any suggestion would be great.
try this: LINK
.triangle{
width: 0px;
height: 0px;
border-style: inset;
border-width: 0 100px 173.2px 100px;
border-color: transparent transparent #007bff transparent;
float: left;
transform:rotate(360deg);
-ms-transform:rotate(360deg);
-moz-transform:rotate(360deg);
-webkit-transform:rotate(360deg);
-o-transform:rotate(360deg);
}
.triangle p {
text-align: center;
top: 80px;
left: -47px;
position: relative;
width: 93px;
height: 93px;
margin: 0px;
}
Your Height and width is 0. You won't fit any text into it. It will either overflow or you can set overflow to "hidden", but than you will not see anything cos the div have the size 0.
your div is invisible to see in your actual div try to give background-color to that div.
[see demo]http://jsfiddle.net/salwenikhil0724/7qbGX/6/
.triangle {
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 100px solid blue;
background-color:red;
}
.triangle p {
text-align: center;
top: 40px;
left: -47px;
position: relative;
width: 93px;
height: 93px;
margin: 0px;
}
This is for displayed text properly, you need to mentioned width property as follows:-
<div style="width: 10em; word-wrap: break-word;">
Some longer than expected text with antidisestablishmentarianism
</div>
for Horizontal scroll you can put overflow-x:hidden its up to you dear.

Create a trapezoid that has transparent borders and background?

I know with some border tricks, I could create trapezoid shape. I can also set its border-color to rgba(r,g,b,a) to make it transparent.
But is it possible to create trapezoid that has transparent borders and background ?
See below image for an example,
Currently, I use some png images to achieve this effect,but generating images of different sizes is really boring work,so I'm looking for a css soluation。
Personally, I think it's overkill, but it can be done like this:
demo
HTML:
<div class='outer'>
<div class='content'><!--stuff here--></div>
<div class='label l1'></div>
<div class='label l2'></div>
</div>
CSS:
.outer {
position: relative;
width: 500px; /* whole thing breaks if this is not a multiple of 100px */
border: solid .5em rgba(0,0,255,.5);
border-bottom: solid 0px transparent;
margin: 7em auto 0;
background: rgba(0,0,0,.5);
background-clip: padding-box;
}
.outer:before, .outer:after {
position: absolute;
top: 100%;
height: .5em;
background: rgba(0,0,255,.5);
content: ''
}
.outer:before { left: -.5em; width: 15%; border-left: solid .5em transparent; }
.outer:after { right: -.5em; width: 55%; border-right: solid .5em transparent; }
.content {
padding: .5em;
margin: 1.5em;
border-bottom: solid 1.5em transparent;
background: lightblue;
background-clip: padding-box;
}
.label {
overflow: hidden;
position: absolute;
top: 100%;
width: 15%;
height: 3em;
}
.l1 { left: 15%; }
.l2 { left: 30%; }
.label:before {
position: absolute;
top: -.5em;
width: 100%;
height: 2.5em;
border: solid .5em rgba(0,0,255,.5);
background: rgba(0,0,0,.5);
background-clip: padding-box;
content: '';
}
.l1:before { left: 9%; transform: skewX(30deg); }
.l2:before { right: 9%; transform: skewX(-30deg); }
It works in Firefox, Chrome, Opera and Safari (I was afraid to test it in IE9, though both transform and background-clip work) but only if the width for .outer has a value that's a multiple of 100px.
Unless using a width that's a multiple of 100px, it only works in Firefox and Chrome (there is a little glitch in Chrome - could be fixed by using a WebKit-only left to right linear gradient that sharply goes from transparent to that semitransparent blue really close to the start).
It breaks in Opera and Safari (if using a width that is not a multiple of 100px):
You can make the bg color and border colors transparent, but the borders will not follow the shape of the trapezoid:
http://jsfiddle.net/Kyle_Sevenoaks/UZbJh/1/
So your best bet is to stick with the pngs for now.

jquery ui slider. Help to correct please

help please to fix my problem. i am newby in jquery ui. And have tried to create jquery slider:
http://jsfiddle.net/InviS/LYE8B/4/
But it outstep my in right position (see example). how can i limit the slider?
Here you go: http://jsfiddle.net/NAC7b/10/.
It's a bit hacky, but I wrap the slider within a parent <div>, and give the slider a max-width of 93%. Here's my changed CSS:
#wrapper{
width: 100%;
height: 20px;
background-color: orange;
border-top: 1px solid black;
position: absolute;
left: 0;
top: 129px;
}
#scroll{
width: 93%;
height: 20px;
background-color: orange;
border-top: 1px solid black;
position: relative;
left: -1px;
top: -1px;
}
And JavaScript:
$('#scroll').slider({animate: true}).bind('slidestop',function(e,ui){
//alert(ui.value);
}).wrap('<div id="wrapper" />');

Categories

Resources