Using the clip-path property to determine the content padding within a div

I am encountering an obstacle while attempting to insert icons into a polygon-shaped div. The problem lies with the padding, as the icons get cut off by the borders of the polygon.

#container {
  width: 200px;
  height: 200px;
  border: 2px solid black;
  background: rgba(176, 75, 80, 0.5);
}

#example {
  position: absolute;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  text-align;
  center;
  top: 50px;
  left: 50px;
  color: red;
  width: 100px;
  height: 100px;
  background: rgba(76, 175, 80, 0.5);
  clip-path: polygon(0 25%, 100% 0%, 83% 60%, 7% 82%);
}
<script defer src="https://pro.fontawesome.com/releases/v5.8.1/js/all.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.0/animate.min.css" />

<div id="container">
  <div id="example">
    <i class="fas fa-star fa-fw filled"></i>
    <i class="fas fa-star fa-fw filled"></i>
    <i class="fas fa-star fa-fw filled"></i>
    <i class="fas fa-star fa-fw filled"></i>
    <i class="fas fa-star fa-fw filled"></i>
    <i class="fas fa-star fa-fw filled"></i>
  </div>
</div>

My attempt to use padding: auto did not resolve the issue.

Answer №1

Instead of using the flex layout, you have the option to utilize float and shape-outside.

https://developer.mozilla.org/en-US/docs/Web/CSS/shape-outside The shape-outside CSS property allows you to define a shape (even non-rectangular) around which adjacent inline content wraps. This provides flexibility in wrapping text around more intricate shapes rather than just rectangular boxes.

Take inspiration from this basic example:

  #container {
  width: 200px;
  height: 200px;
  border: 2px solid black;
  background: rgba(176, 75, 80, 0.5);
}

#example {
  position: absolute;
  text-align: justify;
  top: 50px;
  left: 50px;
  color: red;
  width: 100px;
  height: 100px;
  background: rgba(76, 175, 80, 0.5);
  clip-path: polygon(0 25%, 100% 0%, 83% 60%, 7% 82%);
}

#example:before {
  content: '';
  float: left;
  width: 100%;
  height: 30%;
  shape-outside:  polygon(0 0, 100% 0, 0 25%, 0 45%, 7% 100%, 0 100%, 0 44%, 0 34%);
  }
  #example [data-shape]{
  float:right;
  width:100%;
  height:100%;
  shape-outside: polygon(100% 0, 53% 40%, 0 100%, 100% 100%);
  }
  
<script defer src="https://pro.fontawesome.com/releases/v5.8.1/js/all.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.0/animate.min.css" />

<div id="container">
  <div id="example">
  <b data-shape></b>
    <i class="fas fa-star fa-fw filled"></i>
    <i class="fas fa-star fa-fw filled"></i>
    <i class="fas fa-star fa-fw filled"></i>
    <i class="fas fa-star fa-fw filled"></i>
    <i class="fas fa-star fa-fw filled"></i>
    <i class="fas fa-star fa-fw filled"></i>
  </div>
</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

Tips for dynamically filling HTML content with Ajax calls

I'm currently in the process of creating a website for my semester project, and I need to dynamically populate HTML content from an AJAX response. The data I'm receiving is related to posts from a database, but I specifically need to display 5 jo ...

Having trouble loading Yeoman Webapp SASS

Every time I try to build a web application using 'yo webapp', I encounter a 404 Error. GET http://localhost:9000/styles/main.css 404 (Not Found) I removed compass from the project, but that shouldn't be causing the issue, correct? ...

Unable to locate template or render function for Vue Draggable Next component

Looking to incorporate Vue Draggable Next into a Vue 3 example page but encountering some challenges. I've attempted to follow the instructions in the repository. However, I ran into issues when importing the Vue Draggable Next component and had to re ...

Guide to retrieving a user's current address in JSON format using Google API Key integrated into a CDN link

Setting the user's current location on my website has been a challenge. Using Java Script to obtain the geographical coordinates (longitude and latitude) was successful, but converting them into an address format proved tricky. My solution involved le ...

Default check reversed for radio inputs

I am working with an MVC radio button group, and the issue I'm encountering is that even though the value of 1 "Copy" is set to checked="True", it is not displaying as pre-checked. Here's the code snippet: <div class="editor-field"> < ...

Refresh a page automatically upon pressing the back button in Angular

I am currently working on an Angular 8 application with over 100 pages (components) that is specifically designed for the Chrome browser. However, I have encountered an issue where the CSS randomly gets distorted when I click the browser's back button ...

Modify the innerHTML to adjust font size when a button is clicked in Ionic 5, or eliminate any unnecessary spaces

I have been experimenting with changing the font size of a variable in .html when the variable contains whitespace. In my .ts page, I use the following code to remove the whitespace: this.contents = this.sanitizer.bypassSecurityTrustHtml(this.product[&apos ...

Unable to align divs horizontally

On my webpage, I have set up two divs - Box1 and Box2. Within Box2, there are two nested divs called Box2-1 and Box2-2. However, when I view the page, Box1 and Box2 do not align side-by-side as expected. Instead, Box1 moves downwards and lines up with the ...

What is the effect of SEO on the use of image width and height attributes for a responsive website

Is it true that setting inline width and height for all images is beneficial for SEO and can improve site loading speed? Here's an example: <img src="http://www.example.com/images/free-size.jpg" width="200" height="400" alt="random image" /> E ...

Incorporate a course within the conditional statement

Currently, I'm working on the development of an input site and one of my goals is to highlight empty fields. My plan is to check if a field is empty using an if statement and then apply a specific class that will serve this purpose. This is the JavaS ...

implementing jquery for dynamic pop up placement

When I click the English button, a pop-up appears, but I can only see the full contents of the pop-up after scrolling down. Is there any way to view the entire pop-up without scrolling? Below is the code that I am using: http://jsfiddle.net/6QXGG/130/ Or ...

Is there a way for me to remove an uploaded image from the system

Here is an example of my HTML code: <input type='file' multiple/> <?php for($i=0;$i<5; $i++) { ?> <div class="img-container" id="box<?php echo $i ?>"> <button style="display: none;" type="submit" cl ...

Issue with array merging/inserting feature not functioning as expected

Here are two arrays that I have: First Array: "workingHours": [ { "opening": "09:30", "closing": "13:30", "dayName": "sunday" }, { ...

Adjusting the spacing between the logo and navbar in HTML code

I am struggling to understand why this issue keeps occurring: I have thoroughly checked for errors, attempted multiple solutions, yet the problem persists. Please assist body { margin: 0; padding: 0; } .logo { margin: 0; padding: 0; } ul { li ...

Turn off the custom CSS section in the WordPress Customizer for WordPress themes

Looking for assistance in locking or disabling the Appearance -> Customizer -> Additional CSS area on Wp-admin. I have referred to this codex: https://codex.wordpress.org/Theme_Customization_API. However, I couldn't find any hook or function to disab ...

Utilize WebGL to incorporate a mesh as a background image mask

Currently, I am faced with a challenge in WebGL that involves the following scenario: Picture a mesh positioned in front of the camera. This mesh does not have traditional shading, but its outline, or "silhouette," is utilized to display a background imag ...

Retrieving all buttons from a webpage and removing those with a specific background-image using JavaScript

Hey everyone, I'm still learning about javascript and other web development languages. My current task is to locate all the buttons on a webpage and remove the ones that have a specific background image. I know about using getElementsByTagName but n ...

Go to a distant web page, complete the form, and send it in

As the creator of Gearsbook.net, a social network for Gears of War players, I am constantly striving to improve the site's functionality. Currently, it is quite basic and in need of updates. One highly requested feature by users is the ability to lin ...

Attempting to use tabs within a tab does not function correctly

Visit the CodePen link here This is the codepen example. <div class="row"> <div class="col s12"> <ul class="tabs2"> <li class="tab col s3"><a href="#test1">Test 1</a></li> <li class=" ...

Slideshow plugin glitch on Safari and Opera caused by jQuery implementation

My current project involves utilizing a fantastic plugin called Sequence.js for creating animations and transitions with CSS3 based on jQuery. I have set up a simple responsive fadeIn-fadeOut slideshow using this plugin. While everything works smoothly an ...