Create a hexagon shape using a Div element and start from one of its sides

Is there a way to create a Div with a background image that appears like a hexagon when viewed from one side?
Check out this demo to see exactly what I'm looking for: Demo

In the example/demo, the header is designed to look like a hexagon from its bottom side

Answer №1

One way to create interesting shapes using CSS is to experiment with different properties. Here is an example of how you can create a hexagon shape:

#hexagon {
width: 1000px;
height: 550px;
background:url(http://tresroyale.com/wp/wp-content/uploads/2013/08/1200x480.gif);
position: relative;
}
#hexagon:after {
content: "";
position: absolute;
bottom:0px;
left: 0;
width: 0;
height: 0;
border-left: 500px solid red;
border-right: 500px solid red;
border-top: 100px solid transparent;
}
 <div id="hexagon"></div>

Answer №2

For the content below, assign it a class of "hexagon" and apply the following styles:

.hexagon::before, .hexagon::after {
    content: "";
    position: absolute;
    width: 0;
    height: 0;
    border-bottom: 1670px solid #f7f5ed;
    top: -1669px;
    left: 50%;
    z-index: -10;
}

.hexagon::before {
    border-right: 10000px solid transparent;
    -moz-transform: translateX(-100%);
    -ms-transform: translateX(-100%);
    -o-transform: translateX(-100%);
    -webkit-transform: translateX(-100%);
    transform: translateX(-100%);
}

.hexagon::after {
    border-left: 10000px solid transparent;
}

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

What is the preferred approach in JavaScript: having a single large file or multiple smaller files?

Having a multitude of JavaScript files loaded on a single page can result in decreased performance. My inquiry is this: Is it preferable to have individual files or combine them into one JavaScript file? If consolidating all scripts into one file is the ...

What strategies can we implement to reduce the gutter width in Bootstrap 3?

Is there a way to decrease the gutter-width in Bootstrap 3? Since Bootstrap uses a 12-grids system, using col-sm-* creates a gap between elements of around 30px (15px on each side of the grid-column). However, my theme requires less space between columns ...

How can I make my image shine when the mouse hovers over

I have recently come across a fascinating effect where an image glows up when the mouse hovers over it. This is not your typical border glow, but rather a unique enhancement of colors within the image itself. I discovered a library called Pixastic that can ...

Error 404: Django is unable to locate the static/css files

This particular issue appears to be quite widespread, but existing Q&A resources are outdated and do not address my specific problem. Currently, with Django 2.0.2, my basic webpage is failing to render the bootstrap.css file simply because it cannot locat ...

What is the best way to implement CSS Float in typescript programming?

For a specific purpose, I am passing CSS Float as props. To achieve this, I have to define it in the following way: type Props = { float: ???? } const Component = ({ float }: Props) => {......} What is the most effective approach to accomplish this? ...

Unleashed placement and drifting

Is it possible to style this layout without specifying an exact height for "Element 1"? Code Element1 { positon: relative; width: 100%; height: auto; /* Avoiding specific height */ } Inner1 { position: absolute; top: xyz px; left: xyz px; } Inner2 { po ...

Error: React unable to access the 'title' property as it is undefined

I'm trying to access an array from the state in my App Component, but for some reason it's not working. import React from "react"; import "./App.css"; //import Category from "./components/Category"; class App extends React.Component { const ...

Ways to collect email address or name from an email message

Suppose I send an email to someone with a link at the bottom. The text of the link might be something like click me. When the user clicks on this link, they will be directed to a webpage. On this webpage, a message saying "Thank you" will be displayed a ...

Employing JavaScript to display or conceal a <div> element while scrolling

I'm looking to create a customized sticky navigation bar through Javascript, but I have never written my own code in this language before. My approach involves implementing two sticky navigation bars that appear and disappear based on scrolling behav ...

Is there a way to position right and left divs within a content div on the same top-level?

#textblock{ width: 260px; height: 100%; position; border: 1px solid #999999; padding: 0 5px; float: right; font-size: 95%; background-color: #FEF4CC; } #brevillestandard{ padding: 8px 0 0 5px; ...

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=" ...

Targeting all children instead of just the odd ones when using `nth-child(odd)`

In the portfolio, I have a unique requirement where every odd entry should be reversed. These projects are generated dynamically from an array and passed into the component through props. To style it, I'm utilizing styled-components. However, I&apos ...

Utilize PHP to generate a table from data

I successfully created a table using information retrieved from my database, and everything is displaying as intended. However, I am facing an issue where adding a background color applies it to every row in the table. How can I add a background color wit ...

What is the best way to remove a row in MySQL using PHP?

I am working on a dropdown feature in my code that allows users to choose which notice they want to delete. However, I am struggling to identify what is causing an issue in my code. I am new to this, so please forgive my lack of knowledge. Here are the ...

PHP HTML failing to recognize "mandatory" attributes

I'm facing an issue with adding validation for an empty field. When the field is left empty, the form should not be submitted. However, the "required" attributes seem to be ineffective in achieving this. Birthdate: <select name="month" r ...

Is there a way to maintain scroll position on a dynamically refreshing div?

After searching for hours, I still can't find a solution to my problem. I am using a simple JQuery script to refresh a div and display my PHP output in it. $script = " <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery ...

Optimizing image centering in Next JS as screen size expands

I've been struggling to work with NextJS's Image component. My goal is to set up a banner image that only covers a specific amount of space on the screen, regardless of screen size. I have managed to achieve this by using max-height: 30vh and ov ...

Sometimes I receive a notification that the session ID cannot be regenerated because the session is not active, without any apparent cause

Despite reading numerous posts on this problem, none have provided a solution for me! Some suggest that using session_regenerate_id(true); before session_start(); could be causing the issue. However, this is not applicable to my code. Others recommend remo ...

Apply a dual-color gradient background vertically

I am trying to figure out how to achieve a two-tone background color in an HTML document. I know this question has been asked before, but I specifically want the colors to be split vertically rather than horizontally. ...

Validating your tel hyperlink with HTML5 W3C standards is essential for

Hey there! I have a question about adding telephone links to the numbers on my website. How can I ensure that it passes W3C validation successfully? Currently, when using this syntax: <a href="tel: 0141 123456">0141 123456</a> I am getting th ...