Numerous DIVs with floating elements and border styling

Trying to align two divs with one floating to the left and with a width of 80%, while the other is floated to the left with 20% width, is causing some issues. I want to add a border on the right side of the first div and apply a box-shadow of 5px since each div has a different color.

After searching for a solution, I came across this helpful link. However, in my opinion, it's not an ideal solution as setting specific percentages for widths can lead to white spaces in certain resolutions.

Another issue arises when setting the height of the second div to 100%. While it worked in an example, on the actual website where the height is also set to 100%, the div doesn't occupy the full column height but stops at the margin limit of the last image.

The last problem encountered is regarding applying a box-shadow to floating divs. Should the box-shadow be placed only on the last div for the left side, instead of on the right side of the previous div?

You can view my code here:

div#contenuto_body{
    margin: 0;
    padding: 0;
    float: left;
    width: 80%;
    height: 100%;

    background-color: #C90;

    -moz-box-shadow: 0 0 5px 1px #333;
    -webkit-box-shadow: 0 0 5px 1px #333;
    -ms-box-shadow: 0 0 5px 1px #333;   
    box-shadow: 0 0 5px 1px #333;

    border-right: 4px solid #E6B800;
}

body{
    margin: 0;
    padding: 0;
}

div#ads{
    margin: 0;
    padding: 0;
    width: 20%;  
    float: left;
    height: 100%;

    background-color: #CCC;
}

div#ads img{
    width: 70%;
    max-width: 200px;
    display: block;
    margin: 25% auto;
}

Answer №1

If you're looking to incorporate the css3 feature calc(...) into your design, be sure to consider which browsers you are targeting as support may vary. Versions of Internet Explorer prior to IE9 do not support this feature, so it's important to keep that in mind. Take a look at this example on JSFiddle: http://jsfiddle.net/9gp6J/9/

Another approach would be to use negative margins like so:

div#contenuto_body{
    ...
    margin-right: -4;
}

This method should work for IE7 and newer.

Answer №2

To solve the border issue, you can create a nested div inside the main left div and apply a right border to that inner div. This will allow the outer left div to maintain its 80% width without encountering the extra 4px border problem.

Here is the HTML structure:

<div id="container">
    <div id="left">
        <div id="inner_left">
            content on the left
        </div>
    </div>
    <div id="right">
        content on the right
    </div>
</div>

The corresponding CSS code:

div#container {
    height:200px;
}

div#left {
    float:left;
    width:80%;
    height:100%;
    background:red;
}

div#inner_left {
    border-right:4px solid black;
    height:100%;
}

div#right {
    float:left;
    width:20%;
    height:100%;
    background:green;
}

You can also view this implementation on JSFiddle.

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

Passing a Javascript variable to the NAME attribute of an HTML <a href> tag: Steps to do it efficiently

I need assistance with passing a JavaScript variable to the NAME attribute of an HTML tag. Let's consider this script example: <script> var name = "Click here!"; </script> My goal is to pass the variable to some code in order for <a ...

Optimizing loading times for mobile banners through media queries

I currently have a standard size banner that loads when my page is accessed on a computer. However, I would like to optimize the loading speed by having a smaller version specifically for mobile devices using a media query. My main question is how does t ...

Showing the precise age in years by utilizing the provided 'Date of Birth' selected from the datePicker

Is it possible to retrieve the date entered in the datePicker and use it to populate the current age field in a PHP file using either PHP or Javascript? if ($key == 'currentage') { $group[] = $this->form->createEleme ...

How to access form elements within a submit function without specifically defining the form name

I have a form that I am submitting using a submit function. However, instead of using document id for submission variable, I am utilizing classes. $(".modalform").submit(function(event) { /* prevent form from submitting normally */ event.preventDefa ...

poor scrolling performance when transitioning focus between elements in the interface

Looking for some assistance? Check out this codepen. I'm currently working on a search bar widget that allows navigation from the input field to the search results, displayed as a series of divs. The navigation is controlled via jquery, where the foc ...

Limiting the number of characters in PHP/MySQL

Here is a glimpse into the scenario I am currently facing: The content, including the heading, text, and image, is all dynamically generated based on user input. Users have the option to include an image and choose the text for both the heading and main c ...

Achieving responsive design using text font percentage instead of text images can be done by implementing the following code snippet provided below

When working with text in HTML, I encountered an issue where using percentages for width and height was not giving me the desired results. To work around this, I used images of text instead, but each image ended up either stretched or looking too small. H ...

What is the reason behind individuals choosing to minify assets instead of minifying the HTML

Have you ever wondered why people emphasize the minification of web assets like CSS and JavaScript, yet rarely mention doing the same for markup? It's interesting to note that CSS and JavaScript are often reused across multiple pages, whereas markup i ...

Retrieve the string data from a .txt document

I am facing an issue with my script that retrieves a value from a .txt file. It works perfectly fine when the value is a number, but when trying to fetch text from another .txt file, I encounter the "NaN" error indicating it's not a number. How can I ...

node index of data that has been posted

My HTML file is quite straightforward: <form method="post" action="http://localhost:3000/post"> <input name="name" type="text"/><br /> <input name="last_name" type="text"/><br /> <button id="submit" type="submit"& ...

The CSS styling undergoes a transformation following the integration of Bootstrap

Hey there! I'm new to the world of web development and currently working on creating a simple todo list application. Recently, I revamped my webpage design by incorporating Bootstrap, and the results were pretty exciting! Original Code without Bootst ...

Struggling with using flexboxes and creating animated elements

Seeking assistance with animating the search bar on a website project. The animation is functioning, but the search input abruptly moves when the animation starts, as shown in this GIF: https://i.sstatic.net/17sFl.gif I am utilizing jQuery for the animat ...

Retrieve the value from an input tag that is only displayed based on a condition using *ngIf

In my HTML form, I have implemented conditional visibility of input fields based on the radio button selection using *ngIf. <table> <tr> <td><label>name</label></td> <td><input #name />&l ...

What are the reasons for the failure of an image upload when checked with PHP's is_uploaded_file function?

My html form allows users to upload images, but I'm encountering an issue where the uploaded image fails the "is_uploaded_file" check for some unknown reason. I'm puzzled as to why the upload is failing the is_uploaded_file check. Any ideas? He ...

Unable to modify the text color within a moving button

Working on a school project and implemented an animated button style from w3 schools. However, I'm struggling to change the text color within the button. Being new to HTML, I would greatly appreciate any insights or suggestions on what might be going ...

Toggle the backgroundImage visibility by setting it to either hidden or displayed using jquery

$('.arrow').css("background-image", "url('../img/arrow.png')").hide(); I have implemented a custom solution using CSS and jQuery to hide the downward arrow when scrolling down on my webpage. `$( document ).ready(function() {
 co ...

What methods can be used to test scss subclasses within an Angular environment?

Exploring different background colors in various environments is a task I want to undertake. The environments include bmw, audi, and vw, with each environment having its own unique background color. Need help writing an Angular test for this? How can I mod ...

EaseSlide 'Basic Slideshow' created by Ameenullah Fails to Function

I'm trying to embed a carousel into my webpage. I copied the code from Bootsnips but have been unable to solve this issue with other solutions. This is my HTML Code: <div class="container"> <div class="row> <div class="col ...

Is there a way to alter a form element based on the selected image?

Below is a code snippet that allows the price in the 'price' div to change based on user selection. <script type="text/javascript"> function showprice(e){ document.getElementById("price").innerHTML = e.getAttribute(&apo ...

The carousel's slides don't behave properly when swiping or using the slider controls (next/prev)

I have recently completed the construction of a carousel with swipe/touch functionality and control buttons for previous and next slides. However, I am facing an issue with the behavior of the carousel as it seems to be sliding by 2 or 3 instead of one at ...