Dynamic alteration of graphic/canvas/divs - php

I need to be able to have some kind of a canvas in which I can draw A and manipulate it dynamically towards B. (For A and B see example drawing)
The size of all rectacles must be adaptable
the skewing of the red rectangle
and the rotation of the whole set
I am unsure which is the right way to go. I tried simple HTML with CSS3 transformations and dont really get anywhere without extensive JS calculation since I would have to fake transform the red rectangles in 3D to get the expected impression - which then requires a "faked" positioning for A and B to connected they way they are supposed to.
Any other ideas? Draw it with imagemagick and PHP? SVG manipulation? I am relatively open towards the approach.
Would appreciate some input.
Example drawing: http://www.steffen-behn.de/m3/reifen.jpg

I think that transforms can give you everything that is needed
div {
transition: all 1s;
}
.base {
height: 200px;
width: 100px;
border: solid 1px black;
left: 50px;
top: 100px;
position: absolute;
perspective: 100px;
}
.side {
width: 100%;
height: 50px;
border: solid 1px red;
position: absolute;
}
#side1 {
bottom: 100%;
transform-origin: bottom center;
}
#side2 {
top: 100%;
transform-origin: top center;
}
.base:hover {
transform: scale(1.2) rotate(20deg);
}
.base:hover #side1 {
transform: scaleY(1.1) rotateX(-20deg);
;
}
.base:hover #side2 {
transform: scaleY(1.1) rotateX(20deg);
}
<div class="base">
<div class="side" id="side1"></div>
<div class="side" id="side2"></div>
</div>
Hover to see the transform
EDIT
Another idea. Not sure if it will suit you, but let's give it a try. Can not make the red zones border - only, only solid color.
// customize here
.base {
width: 80px;
height: 200px;
}
.side {
height: 42px;
}
.side:after, .side:before {
width: 10px;
}
// end of customization part
div {
box-sizing: content-box;
}
.base {
position: absolute;
left: 40px;
top: 100px;
width: 80px;
height: 200px;
border: solid black 1px;
}
.side {
width: 100%;
border: solid 1px red;
position: absolute;
left: -1px;
background-color: red;
}
#side1 {
top: 100%;
}
#side2 {
bottom: 100%;
}
.side:after, .side:before {
content: "";
position: absolute;
height: 100%;
}
.side:before {
right: 100%;
}
.side:after {
left: 100%;
}
#side1:before {
background: linear-gradient(to top left, red 50%, transparent 50%);
border-bottom: solid red 1px;
}
#side1:after {
background: linear-gradient(to top right, red 50%, transparent 50%);
border-bottom: solid red 1px;
}
#side2:before {
background: linear-gradient(to bottom left, red 50%, transparent 50%);
border-top: solid red 1px;
top: -1px;
}
#side2:after {
background: linear-gradient(to bottom right, red 50%, transparent 50%);
border-top: solid red 1px;
top: -1px;
}
<div class="base">
<div class="side" id="side1"></div>
<div class="side" id="side2"></div>
</div>

Related

CSS border not showing when background-coloris added

I have written a code that works great for me. So I have a (half) border around my picture. like the picture below. But when I add a background-color the line dissapears.
Now I want the oppiste colors but there for I need a background-color. So I did that but now the border isn't showing anymore. So I want a white line with an orange background. There are 3 files. The CSS file, The PHP file u can see here and a file where they get together.
My PHP/HTML
#about {
background-color: #EF7F19;
color: white;
}
#about .about {
flex-direction: column-reverse;
text-align: center;
max-width: 1200px;
margin: 0 auto;
padding: 100px 20px;
}
#about .col-left {
width: 250px;
height: 360px;
}
#about .col-right {
width: 100%;
}
#about .col-right h2 {
font-size: 1.5rem;
font-weight: 500;
letter-spacing: 0.2rem;
margin-bottom: 10px;
}
#about .col-right p {
margin-bottom: 20px;
}
#about .col-left .about-img {
height: 100%;
width: 100%;
position: relative;
border: 10px solid #EF7F19;
}
#about .col-left .about-img::after {
content: '';
position: absolute;
left: -33px;
top: 19px;
height: 98%;
width: 98%;
border: 7px solid white;
z-index: -1;
}
#media only screen
and (min-width:768px) {
#about .about {
flex-direction: row;
}
#about .col-left {
width: 600px;
height: 400px;
padding-left: 60px;
}
#about .about .col-left .about-img::after {
left: -45px;
top: 34px;
height: 98%;
width: 98%;
border: 10px solid white;
}
#about .col-right {
text-align: left;
padding: 30px;
}
#about .col-right h1 {
text-align: left;
}
}
echo ' <section id="about">';
echo ' <div class="about container">';
echo ' <div class="col-left">';
echo ' <div class="about-img">';
echo ' <img src="'. $row[" AboutLocation "].'"
alt="img">';
echo ' </div>';
echo ' </div>';
echo ' <div class="col-right">';
echo ' <h1 class="section-title"
style="color: white;">Over ons</h1>';
echo ' <h2>Adisol</h2>';
echo ' <p>'. $row["AboutUsText"].'</p> ';
echo ' </div>
</div>
</section>';
Like I said already in the comment. The use of box-shadow would be the easier approach to achieve the wanted design. That way you dont need pseudo elements. you can use 2 box shadows with a vertical and horizontal offset.
Lets go through the code and see how it actually works:
1st: you need a border aroudn your image. specifiy the border as white solid with a thickness of your liking.
2nd: We need an orange frame which we'll get by using the box-shadowattribute with 2 values that are seperated with a comma.
3rd: lets start with the second and last value: -30px 30px 0 0 orange the first number is the horizontal offset which will move the frame 30px to the left. The second number is the vertical offset which moves the frame 30px to the bottom. The third number is the blur value. With 0 it will be a solid color. The fourth and last number is the size. With 0 it has the exact same size as the picture.
4th: To prevent that the whole shadow displays as an orange block, we need to put another box shadow value in front of it. We give it the same offset and blur value. The fourth number we change however. We change it to a negative value of the intended "frame" thickness. In this case -10px which will make the "frame" 10px thick.
img {
width: 50%;
float: right;
border: 10px solid white;
box-shadow: -30px 30px 0 -10px white,
-30px 30px 0 0 orange;
}
/* for demonstration only */
img {
margin-bottom: 100px;
}
<img src="https://www.tacoshy.de/Images/Yoshi/IMAG0735.jpg">

Why is this overflow wrap breaking my alignment for post boxes? [duplicate]

When two inline-block divs have different heights, why does the shorter of the two not align to the top of the container? (DEMO):
.container {
border: 1px black solid;
width: 320px;
height: 120px;
}
.small {
display: inline-block;
width: 40%;
height: 30%;
border: 1px black solid;
background: aliceblue;
}
.big {
display: inline-block;
border: 1px black solid;
width: 40%;
height: 50%;
background: beige;
}
<div class="container">
<div class="small"></div>
<div class="big"></div>
</div>
How can I align the small div at the top of its container?
Because the vertical-align is set at baseline as default.
Use vertical-align:top instead:
.small{
display: inline-block;
width: 40%;
height: 30%;
border: 1px black solid;
background: aliceblue;
vertical-align:top; /* <---- this */
}
http://jsfiddle.net/Lighty_46/RHM5L/9/
Or as #f00644 said you could apply float to the child elements as well.
You need to add a vertical-align property to your two child div's.
If .small is always shorter, you need only apply the property to .small.
However, if either could be tallest then you should apply the property to both .small and .big.
.container{
border: 1px black solid;
width: 320px;
height: 120px;
}
.small{
display: inline-block;
width: 40%;
height: 30%;
border: 1px black solid;
background: aliceblue;
vertical-align: top;
}
.big {
display: inline-block;
border: 1px black solid;
width: 40%;
height: 50%;
background: beige;
vertical-align: top;
}
Vertical align affects inline or table-cell box's, and there are a large nubmer of different values for this property. Please see https://developer.mozilla.org/en-US/docs/Web/CSS/vertical-align for more details.
Use display: flex property for the parent div
The flexbox items are aligned at the start of the cross-axis.
By default, the cross-axis is vertical. This means the flexbox items will be aligned vertically at the top.
So when you apply the display: flex property to the parent div, it sets its child elements with vertical-align: top.
See the following code:
.container {
border: 1px black solid;
width: 320px;
height: 120px;
display: flex;
/** CSS flex */
}
.small {
display: inline-block;
width: 40%;
height: 30%;
border: 1px black solid;
background: aliceblue;
}
.big {
display: inline-block;
border: 1px black solid;
width: 40%;
height: 50%;
background: beige;
}
<div class="container">
<div class="small"></div>
<div class="big"></div>
</div>
Browser Compatibility: Flexbox is very well supported across modern browsers.
<style type="text/css">
div {
text-align: center;
}
.img1{
width: 150px;
height: 150px;
border-radius: 50%;
}
span{
display: block;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<input type='password' class='secondInput mt-4 mr-1' placeholder="Password">
<span class='dif'></span>
<br>
<button>ADD</button>
</div>
<script type="text/javascript">
$('button').click(function() {
$('.dif').html("<img/>");
})
Add overflow: auto to the container div.
http://www.quirksmode.org/css/clearing.html This website shows a few options when having this issue.

Is there a way to make an overlay with an arrow AND border like google?

I am working on my code to create a green circle with your name on it with an arrow and border just like the one that google use.
please find the sample image below.
I have already created a green circle and a name using css and html which you can see it here.
<div class="profileImage">
<span id="profilename" class="profilename"></span>
<div class="flex-container">
</div>
</div>
.profileImage {
-webkit-background-size: 32px 32px;
background-size: 32px 32px;
background-color: green;
-webkit-border-radius: 50%;
border-radius: 50%;
display: block;
float: right;
margin-right: 18px;
margin-top: 12px;
overflow: hidden;
position: relative;
height: 32px;
width: 32px;
z-index: 0;
}
.profilename {
text-align: center;
color: white;
font-size: 14px;
line-height: 32px;
margin-left: 5px;
font-weight: bold;
}
.flex-container {
padding: 0;
margin: 0;
list-style: none;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-flex-flow: row wrap;
justify-content: space-around;
}
$(document).ready(function() {
var firstName = 'Robert';
var lastName = 'Jones';
var intials = firstName.charAt(0)+""+lastName.charAt(0);
document.getElementById("profilename").innerHTML = intials;
});
When I click on a green circle, I want to display the overlay with a border but I have got no idea how to do this. I tried to find it on google but I couldn't find it.
Can you please show me an example how I can display the overlay with a grey border that come with my first name, last name, email address and a signout button?
Thank you.
Ok I'll get you started with an overlay that includes an arrow with a border around the whole thing.
Basically, you're doing a bit of "visual miss direction". We used CSS borders to generate a triangle of the SAME color as the box background. This gets positioned its (height - border width) above the box. This puts the triangle OVER the top of the border, effectively hiding it.
Then there's a second triangle with a color that matches the border of the box. We position this triangle BEHIND the first triangle (using z-index) and offset the second triangle the border width from the first. This makes for a "fake" border because only the border width of the second triangle shows.
body {
margin: 50px;
}
.overlay {
position: absolute;
width: 300px;
height: 200px;
// styling
background-color: #fff;
border: 1px solid #ccc;
box-shadow: 0 2px 4px 0 rgba(0,0,0,0.2);
border-radius: 4px;
}
.arrow {
position: absolute;
width: 0;
height: 0;
border-style: solid;
border-width: 0 10px 10px 10px;
border-color: transparent transparent #fff transparent;
top: -9px;
right: 10px;
}
.arrow:after {
content:"";
position: absolute;
width: 0;
height: 0;
border-style: solid;
border-width: 0 10px 10px 10px;
border-color: transparent transparent #ccc transparent;
left:-10px;
top:-1px;
z-index:-1;
}
<div class="overlay">
<div class="arrow"></div>
<div class="overlayContent">
</div>
</div>
We used two elements (arrow and content) inside the overlay wrapper because we're rounding the corners using overflow:hidden this would cause our arrows to be cut off as well. So instead we'll have an extra container. The content area uses flexbox to push the button bar to the bottom regardless of the size. There are other ways to do this but this is easy.
body {
margin: 50px;
}
.overlay {
position: absolute;
width: 300px;
height: 200px;
// styling
background-color: #fff;
border: 1px solid #ccc;
box-shadow: 0 2px 4px 0 rgba(0,0,0,0.2);
border-radius: 4px;
}
.arrow {
position: absolute;
width: 0;
height: 0;
border-style: solid;
border-width: 0 10px 10px 10px;
border-color: transparent transparent #fff transparent;
top: -9px;
right: 10px;
}
.arrow:after {
content:"";
position: absolute;
width: 0;
height: 0;
border-style: solid;
border-width: 0 10px 10px 10px;
border-color: transparent transparent #ccc transparent;
left:-10px;
top:-1px;
z-index:-1;
}
.overlayContent {
position:absolute;
z-index: 1;
top:0; right:0; bottom:0; left:0;
overflow:hidden;
border-radius: 4px;
display:flex;
flex-direction: column;
justify-content: space-between;
}
.top {
flex-basis: 70%;
}
.bottom {
flex-basis: 30%;
border-top: 1px solid #ccc;
background-color: #f5f5f5;
}
<div class="overlay">
<div class="arrow"></div>
<div class="overlayContent">
<div class="top"></div>
<div class="bottom"></div>
</div>
</div>
That's the fundamentals of the overlay. Try filling in the content you want and ask more questions if you need help.

Use CSS3 perspective and transform to render image as 3d cube

I have been using PHP and ImageMagick for to generate a 3D preview of a canvas print (see image below).
There are options to change the edge type, depth, size etc which are AJAX calls to a PHP support file which re-renders the preview with new settings and I reload it into the DOM.
This is starting to overload our server when busy. So I thought I could do this in CSS3 and do all the preview rendering client-side instead.
Here's what I have so far:
<div class="wrapper">
<div class="inner">
<div>
<img src="http://lorempixel.com/200/200/nature" alt="Nature">
</div>
</div>
</div>
.wrapper {
perspective: 500px;
margin: 4em auto;
width: 37em;
}
.inner {
transform: rotateY(40deg);
}
.inner div {
width: 11em;
display: inline-block;
margin-right: 1em;
}
.inner img {
display: block;
height: auto;
max-width: 100%;
margin: 0 auto;
}
The problem I am having is wrapping the image around the edges like in the image above. How can I do this?
I have done a demo, with 2 elements holding the same image.
Just set the image origin on them accordingly to the dimension, and it will match.
.main {
width: 400px;
height: 300px;
border: solid 1px red;
background-image: url(http://lorempixel.com/400/300);
background-size: 0px 0px;
perspective: 500px;
position: relative;
}
.front {
position: absolute;
width: 360px;
height: 100%;
left: 40px;
top: 0px;
transform: rotateY(45deg);
transform-origin: left center;
background-image: inherit;
background-position: -40px 0px;
}
.side {
position: absolute;
width: 40px;
height: 100%;
left: 0px;
top: 0px;
transform: rotateY(-45deg);
transform-origin: right center;
background-image: inherit;
background-position: 0px 0px;
}
<div class="main">
<div class="side"></div>
<div class="front"></div>
</div>

Centre an Image

I'm trying to horizontally center an image. However it does not move from the left side of the page. This answer does not work in my case. What am I doing wrong?
#container {
width: 100%;
border: 2px yellow dashed;
height: 100px;
}
#profile-image img{
margin-left: auto;
margin-right: auto;
border: 2px orange solid;
}
mypage:
<div id="container">
<div id="profile-image">
<p><img src="<?php echo $data['profile_image_url'];?>" alt="me"></p>
</div>
to make any div or anything horizontally at center , common css approach will be,lets have a width and declare margin:0 auto;
#profile-image{
width:400px;
margin:0 auto;
}
Try this: http://jsfiddle.net/rua4d/2/
#container {
width: 300px;
border: 2px yellow dashed;
height: 100px;
display:table-cell;
position:relative;
vertical-align:middle;
}
#profile-image img{
margin-left: auto;
margin-right: auto;
border: 2px orange solid;
display:block;
position:relative;
vertical-align:middle;
text-align:center;
width:50px;
}
You just need to add display:block to your image's style. Images are inline elements, and inline elements ignore margins.
why cant this work?
#profile-image p { text-align: center; }
#profile-image img { display: inline; }
that way you won't need to specify the width.. if you want margins to work together with the text-align: center you would need inline-block instead:
#profile-image p { text-align: center; }
#profile-image img { display: inline-block; }

Categories