Jump to content

Tilt a DIV in fex. 45 degrees.


LeonLatex

Recommended Posts

Look at the picture I attach. I want a DIV if possible (CSS?) And tilt it at an angle as many degrees as the image. In that case, I will have 5-6 such in a row in the head on the website to avoid making a large (wide) image with 5-6 such in a row. I have tried it, but then I lose the scaling of the page to be as narrow in width as without a picture with your slanted words on.
Lorem ipsum is the only image on the preview image, but it's not displayed yet.
So is there such a feature in CSS3 that tilts a DIV in e.g. 45 degrees?

tilt_text_image.png

Edited by LeonLatex
Link to comment
Share on other sites

Here's an example to get you started

<?php 
    function svgHead($txt)
    {
        $svg = "<svg class='longhead' width='150' height='100'>
                <style type='text/css'>
                    .headtext {
                        font-size: 11pt;
                        fill: orange;
                    }
                </style>
                <path d='M 0 100 l 40 0 l 100 -100 l -40 0 Z' fill='black' />
                <text x='35' y='95' class='headtext' transform='rotate(-45, 35, 95 )'>$txt</text>
                </svg> 
               ";
        return $svg;
    }
?>
<style type='text/css'>
    div.outer {
        border: 1px solid black;
        height: 105px;
    }
    
    svg.longhead {
        margin: -50px;
        position: relative;
        top: 35px;
        left: 50px;
    }
</style>
<div class='outer'>
    <?= svgHead('Long Heading 1')?>
    <?= svgHead('Long Heading 2')?>
    <?= svgHead('Long Heading 3')?>
    <?= svgHead('Long Heading 4')?>
    <?= svgHead('Long Heading 5')?>
    <?= svgHead('Long Heading 6')?>
</div>

output

image.png.46d2977feaaca6e3c797999ce7812802.png

  • Like 1
Link to comment
Share on other sites

Thanks barand. I tried a little myself by using the transform: skewX(45deg); But this wasn't working. I used some time on it but gave up for the evening. Then I came over/I saw your example too late, but when I did, I tried your script, and that was working (of course 😊👍). Hope it's ok if I copy and paste and saves your code on my network for later use? This was great😊 thanks 😊

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.