Creating a slanted bottom edge on a div without compromising responsiveness

Is there a way to create a skew on the bottom side of a div without it being affected when the height and width change in responsive design? Check out the image for reference. I've attempted using the CSS transform property, but haven't been able to resolve this issue. Additionally, I'd like to add a background repeating pattern and a box shadow to the div.https://i.sstatic.net/IzCpV.png

.mydiv
{
    height:400px;
    /*width:100%;*/
    width:350px;
    box-shadow: 0px 0px 5px 1px rgba(0,0,0,0.15);
    -webkit-transform: rotate(-3.8deg);
    background:url(http://www.emoticonswallpapers.com/background/thumb/nice/nice-background-pattern-184.gif);
}

http://jsfiddle.net/harikriz92/266f31o8

Answer №1

In order to achieve this particular outcome, I had to incorporate additional elements into the DOM.

Essentially, a triangular div was created with a base for overflow hidden on the left side and to maintain a fixed aspect ratio using a padding trick.

Subsequently, an inner triangle was added to facilitate the necessary rotation and have overflow to clip along the diagonal line.

Within the inner triangle, a pseudo element was utilized to establish the background pattern.

The shadow effect was implemented directly on a pseudo element of the base component.

.test {
    width: 60%;
    position: relative;
    background-position: bottom left;
    background-image: url("http://emoticonswallpapers.com/background/animals/animal-backgound-pattern-015.gif");
}

.test:after {
    content: "";
    position: absolute;
    width: 103%;
    height: 2px;
    top: 100%;
    right: 0px;
    transform: rotate(-14deg);
    transform-origin: top right;
    box-shadow: 0px 4px 6px 0px black;
}

.trianglebase {
    width: 100%;
    padding-top: 25%;
    position: absolute;
    top: 100%;
    left: 0px;
    overflow: hidden;
    z-index: -1;
}

.triangleinner {
    width: 104%;
    height: 100%;
    position: absolute;
    top: 0px;
    left: 0px;
    transform: rotate(-14deg);
    transform-origin: bottom left;
    overflow: hidden;
}

.triangleinner:after {
    content: "";
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0px;
    left: 0px;
    background-image: url("http://emoticonswallpapers.com/background/animals/animal-backgound-pattern-015.gif");
    transform: rotate(14deg);
    transform-origin: bottom left;
}
<div class="test">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam.
Lorem ipsum dolor sit amet, consectiuster adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam.
<div class="trianglebase">
<div class="triangleinner">
</div>
</div>
</div>

Please note: Although this could be achieved more easily with a clip path, given that IE lacks this feature, I chose the longer route to ensure compatibility with all modern browsers.

Answer №2

Consider these two potential solutions:

Utilizing Background-size Property

An easy approach is to use a background image that matches the desired shape and fits the entire size of the div, adjusting to its size changes as well. Here's an example:

.mydiv {
  width:100%;
  background:url(https://i.sstatic.net/Kbmfx.png);
  background-size:100% 100%;
  padding-bottom:30px;
}
<div class="mydiv">
  <p>Line 1</p>
  <p>Line 2</p>
  <p>Line 3</p>
</div>

In case you opt for a vector image like SVG instead of a bitmap/raster image (e.g., PNG/JPEG), you can avoid distortion or pixelation issues when scaling. The use of SVG is widely accepted across major browsers, but do note that the solution mentioned here relies on background-size, which may not be compatible with IE9 and below. If this method proves effective, then SVG should work accordingly.


Implementing an Absolute-positioned Image

If you need support for older versions such as IE8 and earlier, another alternative involves adding a position:relative attribute to .mydiv, followed by positioning an image with position:absolute to cover the width/height of

.mydiv</code positioned at the back using a negative z-index.</p>

<p>This setup simulates having the image as a background while maintaining compatibility with CSS2, thereby supporting older IE versions. Although employing SVG can ensure sharp visuals without pixelation concerns, it may not function properly on pre-IE8 versions.</p>

<p>Below is a demonstration:</p>

<p><div>
<div>
<pre class="snippet-code-css lang-css"><code>.mydiv {
  position:relative;
  width:100%;
  padding-bottom:30px;
}

.mydiv .bg {
  position:absolute;
  top:0;
  left:0;
  width:100%;
  height:100%;
  z-index:-1;
}
<div class="mydiv">
  <img src="https://i.sstatic.net/Kbmfx.png" alt="" class="bg" />
  <p>Line 0</p>
  <p>Line 1</p>
  <p>Line 2</p>
  <p>Line 3</p>
  <p>Line 4</p>
  <p>Line 5</p>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Text will not be moved to a new line

Hello, I am encountering an issue with my messaging system where the messages retrieved from the database are not properly going to a new line in the window. Despite adjusting the width, the messages continue to overlap. Below is the code snippet: This co ...

Adjust the alignment of items in the NavBar using BootStrap to ensure they

I'm having trouble centering the contents of my Nav Bar, and for some reason, everything seems to be left-aligned instead of centered. I haven't used float: left anywhere, so I'm not sure why it's not working as expected. The goal is ...

Guide to fetching and displaying dropdown values from a database using PHP

Hello everyone, I need help on retrieving data from a database and displaying it in a drop-down list. I have written the following PHP code: public function System_parameter_dropdown_value() { $sql= " SELECT * FROM SYSTEM_PARAMETERS WHERE PARAMETER_KE ...

The various options in the dropdown menu are descending in order

I am currently facing an issue with a dropdown menu that contains the list of products offered by our company. Specifically, one of the product names, Hotel Management Solutions, is appearing on multiple lines instead of a single line in the dropdown menu. ...

Displaying an HTML/CSS image layered on top of another image with a fixed navigation bar

I've run into an issue with my webpage layout. I have a fixed navigation bar and an image displayed, but now I want to add another image on top of the existing one. However, when I use "position: relative" and position:absolute", the two images end up ...

iCloud Web Portal - Element Search Failed: Element Not Found

Exploring Python as a novice, I embarked on a project that requires logging into Gmail and iCloud using Selenium. The Gmail portion went smoothly, indicating that I am headed in the right direction. However, I hit a roadblock while trying to identify the l ...

Dynamic elements create an interactive horizontal scrolling experience

I have square elements that will be displayed in a row on the screen extension. These elements are generated dynamically, starting with 2 and going up to 50. Depending on the screen size and number of elements, there may be overflow. In such cases, I want ...

dynamically assigning a style attribute based on the dimensions of an image retrieved from a URL

My aim is to determine whether or not I should use an image based on its dimensions. To achieve this, I came across a function on stack overflow that can retrieve the dimensions of an image just by using its URL. Here is the code snippet they provided: f ...

The top of the page does not align with the HTML body even when the margin is set to 0

I am facing an issue with my Ruby on Rails app where the body content is not displaying at the top of the page. Here is a screenshot of the problem: I have double-checked all the properties and everything seems to be set correctly. If you want to take a l ...

Bringing in the bootstrap JavaScript file

I've recently started using Bootstrap that I installed from npm, but I'm having trouble importing the JS file. This is my main JS file where I want to utilize all the tools: import * as bootstrap from '../node_modules/bootstrap/dist/js/boot ...

How can I create a jumping animation effect for my <li> element in JQuery?

I have a horizontal navigation bar with a "JOIN" option. My goal is to make the #jump item continuously jump up and down after the page has finished loading. Currently, I have this code which only triggers the jump effect once when hovering over the eleme ...

reveal one div and conceal another using Bootstrap's collapse feature

I'm not sure why it's not working. Maybe I missed some simple thing? I want to show one div when I use an icon, then hide the other div. Currently, if I click on the first icon, a div will show. But if I click on the second icon, the div will sh ...

Implementing File Retrieval in a Controller

I have a specific file where I declared the URL for my videouploadfolder, and now I need to reference that file in my JavaScript config.js. var filepath = { uploadVideoUrl : './public/videos' } In my Node.js script, I included it like th ...

XSL fails to display HTML tables

I am having trouble displaying information from an XML file about hotels using XSL on a webpage without HTML tables. Despite searching through numerous posts on StackOverflow, I cannot seem to pinpoint where I may have gone wrong. Here is an excerpt from ...

Is there a way to condense a paragraph of text without using a span or div element?

There is a common scenario where I often encounter this issue: <span> <p>hello world</p> </span> It involves reducing the width of a paragraph to fit the text, but unfortunately it leads to clutter in my HTML. Is there a way to ...

Track when a user modifies a <select> dropdown list generated using the Jquery method ".html()"

Is it possible to detect a change in the value of a select list when that select list has been added using either the .html(htmlString) or .append(content[,content]) jQuery function? HTML CODE: <ul class="htmlClass"> <!-- Populated via JS --& ...

Video HTML autoplay feature malfunctioning

I have been attempting to use the <embed> tag in order to showcase a video on my webpage. However, I have encountered an issue where the video begins playing automatically when the page loads. In an effort to remedy this situation, I included autost ...

Configure UL element as a dropdown on mobile devices and expand it to full width on desktop screens

Circumstances This HTML code is intended to create a horizontal <ul> element that spans the entire width of the <div class="list__wrapper"> container on desktop screens with a minimum width of 1024px. However, for mobile devices with a maximum ...

Display various JavaScript function outputs in an HTML table for convenient tracking

Thanks to a helpful user on this platform, I was able to capture data from a JavaScript function and display it in an html table. However, I now have another query. How can I execute the function multiple times during page load and record the results in ...

Attempting to generate two columns out of a list of divs, with additional white space in the left column

I am attempting to render a series of divs into two columns. However, when viewing the example in this [JSFiddle](http://jsfiddle.net/nb32P/2/) link, I noticed there is extra spacing above Group Heading 4 in the left column that I cannot seem to remove. ...