"Resolving the Problem of a CSS Width Setting at 100

Encountering difficulties when using 100% in the container CSS. Referencing the attached image, you can see the RED background color displayed on the right side image.

Below is the link to my CSS code on jsfiddle. Please review it and advise on the modifications needed to prevent the display of the background angles (red, yellow, green).

The total width assigned to different IDs exceeds 100% (39% on the left, 50% in the middle, and 34% on the right), totaling 123%. Although I acknowledge this is an incorrect approach, I'm unsure of an alternative method to correct the design.

After implementing the CSS on my computer screen with a resolution of 1600 by 900, I only see the RED background in the right image. However, on a smaller screen, as shown in the link, all other background images are displayed.

HTML

<div id="container">
    <div id="left"><img  src="http://media-cdn.tripadvisor.com/media/photo-s/03/c3/1f/5f/working-people-exhibit.jpg"/></div>
    <div id="middle"><img src="http://global.fncstatic.com/static/managed/img/Health/Women%20Working.jpg"/></div>
    <div id="right"><img src="http://www.koindo.com/images/WORKING%20PEOPLE%20IMAGE.jpg"/></div>
</div>

CSS

#container{
    width:100%;
    background-color:orange;
    height:300px;
    overflow:hidden;
    position:relative;
}

#left{
    position:absolute;
    left:-4%;
    display:inline-block;
    width:39%;
    background-color:red;
    height:300px;
    transform:skew(-20deg,0deg);
    -ms-transform:skew(-20deg,0deg); /* IE 9 */
    -webkit-transform:skew(-20deg,0deg); /* Safari and Chrome */
    z-index:1;
    overflow:hidden;
}
#left img{
    transform:skew(20deg,0deg);
    -ms-transform:skew(20deg,0deg); /* IE 9 */
    -webkit-transform:skew(20deg,0deg); /* Safari and Chrome**/ 
    width:100%;
    height:100%;
}
#middle{
    position:absolute;
    margin-left:30%;
    display:inline-block;
    width:50%;
    background-color:green;
    height:300px;
    transform:skew(-20deg,0deg);
    -ms-transform:skew(-20deg,0deg); /* IE 9 */
    -webkit-transform:skew(-20deg,0deg); /* Safari and Chrome */
    z-index:2;
    border-left:10px solid white;
    overflow:hidden;
}
#middle img{
    transform:skew(20deg,0deg);
    -ms-transform:skew(20deg,0deg); /* IE 9 */
    -webkit-transform:skew(20deg,0deg); /* Safari and Chrome**/ 
    margin-left:-11%;   
    width:100%;
    height:100%;

}
#right{
    position:absolute;
    right:-4%;
    display:inline-block;
    width:34%;
    background-color:red;
    height:300px;
    border-left:10px solid white;
    transform:skew(-20deg,0deg);
    -ms-transform:skew(-20deg,0deg); /* IE 9 */
    -webkit-transform:skew(-20deg,0deg); /* Safari and Chrome */
    z-index:3;
    overflow:hidden;

}

#right img{
    transform:skew(20deg,0deg);
    -ms-transform:skew(20deg,0deg); /* IE 9 */
    -webkit-transform:skew(20deg,0deg); /* Safari and Chrome**/     
    width:100%;
    height:100%;

}

(Find the code on JSFiddle: http://jsfiddle.net/swati712/XQNzu/5/)

Answer №1

One issue to consider is the assumption that both your left and right divs need to be skewed. In reality, only the middle div requires it and can be placed on top of the others.

To ensure that the corners of the middle div are covered, adjust the inner div's width to not be 100%, but rather start 55px to the left and right - the width of the resulting green triangles on each side.

Take a look at the revised version in this fiddle: http://jsfiddle.net/XQNzu/7/

I made several other changes, such as converting your img tags to divs with background images. This allows you to utilize the background-size: cover property to preserve the aspect ratio and ensure corners are fully covered.

The outcome is similar to your initial design but not identical. You may need to make some adjustments to achieve the desired appearance.

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

Adjust the height value of each element to match the maximum height within a single line using only CSS

There are 3 divs styled with display:inline-block. I aim to adjust their height values so they match the highest one. The desired effect is demonstrated visually below. Is it doable using only CSS? ----- ----- ----- ----- ----- ---- ...

Removing data entry from MySQL database table using PDO

I'm facing an issue with deleting a row from my database. Despite trying various methods like PDO and MySQL, the data is not getting deleted, but it shows as if it has been deleted. Can someone please help me identify what might be wrong with my code? ...

I am having trouble getting my textarea to accept width attributes

Strangely, the text area on my website just won't cooperate with the width I specify. I've double-checked the CSS multiple times to no avail! Take a look at this jsfiddle example that demonstrates what I'm trying to achieve. However, on my ...

Designing a dynamic patterned backdrop that seamlessly extends for a column in bootstrap

Experiencing some difficulties with Bootstrap and creating a resizable column background. In one row, there is a column with a fluid image at the top, another column below it with a CSS class that gives it a repeating background along the Y axis, and fina ...

Using gradients in the app bar with ReactJS and Material UI is not currently supported

Recently, I decided to create my own custom appbar for a personal project and opted to use the Erica One font. As it is still in its initial stages, there isn't much code written yet. However, I've encountered two issues related to linear and ra ...

Change the z-index of divs when clicked

When a button is clicked, I want to iterate through a group of absolutely positioned children divs with varying z-indexes. The goal is for the z-index of the currently visible div to decrease on each click, creating a looping effect where only one div is v ...

I am experiencing some difficulty with the GetServerDate using the JSON protocol in JQuery; it's

I am facing an issue while trying to execute a basic ajax call to fetch data from a file on a server. Even though I can access the file via the web browser and have diligently followed tutorials related to this topic, I have hit a dead end. Here is the sn ...

Laravel issues with displaying data in a 'foreach' loop

I encountered a quirky issue while working with Laravel 5.2. I have a chunk of text that I'm attempting to display using some explode functions. The strange part is, Laravel is rendering it oddly by adding incorrect ':' before the end of the ...

How to minimize the amount of typing needed when specifying grid positions in CSS Grid layout?

(I am currently in the process of upgrading the design of this data entry page from a basic CSS/HTML table layout to something more advanced, utilizing CSS Grid layout). Following common conventions, I have structured it into 12 columns. Each entry field ...

"Combining JSON, JavaScript, and HTML for dynamic web development

I am a junior computer programmer facing challenges with our JSON project. The objective is to store an object in local storage, but my HTML and JS code are not working as intended. It seems like nothing happens at all. Any suggestions or feedback would ...

Trouble encountered when attempting to override styles in Material UI's TableRow

I am attempting to customize Material UI's default styles in order to create a margin between each TableRow. Despite my efforts, it appears that the override is not being reflected in the user interface. ...

Customize the overlay color using the theme's background color

I want to create an overlay on my webpage that covers all the content. However, I'm facing a challenge because my website allows users to customize the theme colors, and the overlay div does not adopt these color changes automatically. To rectify this ...

Avoiding the use of a particular URL when using this.router.navigate() in AngularJs

In my angularJS registration form, I am using a bootstrap template for the design. The URL path to access the form page is http://localhost:4200/signup <form method="post" (submit)='register(username.value,email.value,password.value)'> ...

Instead of only one menu icon, now there are three menu icons displayed on the screen. (Additionally, two more divs containing

When visiting on a smartphone browser, you may notice that instead of one menu icon, three icons appear. Upon inspecting the elements, you will find that there are three div's that look like this: <div class="responsive-menu-icon">&l ...

Can a websocket be used to communicate with a server that is not the same as the one hosting the html5 website?

My goal is to establish communication between a hardware device and an HTML5 website. It seems like the best way to do this would be through WebSockets or possibly WebRTC over a WiFi network. Is that correct? I haven't come across any solutions invol ...

A guide on how to insert content into a text area using a drop-down menu choice

I'm a total beginner at this. Is it possible to use JavaScript to automatically fill in a text area on an HTML form based on what is selected in a drop-down menu? If so, can someone please explain how to achieve this? ...

The Bootstrap 4 navigation bar remains expanded on tablet screens

I recently obtained and modified a basic bootstrap 4 theme. By customization, I mean that I ensured all menu items have the same margin and added my logo. The issue I encountered is that on tablets, the navbar does not collapse as expected. I have attache ...

Simultaneously sending jQuery.ajax data while submitting a form

I'm facing a bit of a dilemma here. I have a form with multiple fields, including one for entering links. When you input a link and click the add button, the link is added to a link_array using jQuery. My goal is to send this array through the jQuery. ...

The Bootstrap Modal will still appear even in the presence of a validation error

Recently, I created a sign-up page using HTML and Bootstrap 5. To ensure data validation on the form, I integrated Bootstrap's validation feature. However, after completing the registration process, a modal pops up as intended. The only issue is that ...

[CSS] What's the trick to getting it to smoothly glide to the top?

As a new designer, I have a question about how to make the background color extend to the top without any white space. Can someone please guide me on how to achieve this? <!DOCTYPE html> <html> <head> <style> body{ margin: 0px; p ...