Styling two divs with borders

Hello everyone, I could really use some assistance with merging the borders of two <div>s. Here's what I'm trying to achieve compared to where I currently stand: view image here and this is my desired outcome view image here

Would anyone be able to guide me on how to accomplish this? Below is the code that I have so far:

CSS :

#plink {

    position: relative;
    width: 200px;
    float: left;
}

#open {
    border-top: 1px solid black;
    border-bottom: 1px solid black;
    border-left: 1px solid black;
    width: 200px;
    text-align: center;
    line-height: 50px;

}

#closed {
    border: 1px solid black;
    width: 200px;
    text-align: center;
    line-height: 50px;

}

#closed:hover a {
    display: block;
}


#open:hover a {
    display: block;
}

#pbase {
    border: 1px solid black;
    position:relative;
    width: 600px;
    height: 300px;
    float: left;
}

HTML :

<div id="plink">
<div id="open">My details</div>
<div id="closed"><a href="ads.php">My ads</a></div>
<div id="closed"><a href="fav.php">Favorites</a></div>
</div>
<div id="pbase"></div>  

Answer №1

#plink {
    position: relative;
    width: 200px;
    float: left;
    border-top: 1px solid black;
    border-left: 1px solid black;
}
#open {
    border-bottom: 1px solid black;
    border-right: 1px solid white;
    text-align: center;
    line-height: 50px;
}
#closed {
    border-bottom: 1px solid black;
    width: 200px;
    text-align: center;
    line-height: 50px;
}
#pbase {
    border: 1px solid black;
    position: relative;
    width: 600px;
    height: 300px;
    float: left;
    margin-left: -1px;
    z-index: -1;
}

https://jsfiddle.net/8rrov5hb/

This effect was accomplished by applying a negative margin-left: -1px and setting the z-index: -1 on #pbase to position it behind #plink.

To create a transparent appearance for the div #open, you can use border-right: 1px solid white – simply adjust this style to match the desired background color.

Answer №2

Change the border-right color to white and utilize z-index to ensure that the menu remains open over the right section. You can try implementing it as shown below. Hopefully, this will be beneficial for you.

#open {
    border-color: black #fff black black;
    border-style: solid;
    border-width: 1px;
    line-height: 50px;
    position: relative;
    text-align: center;
    width: 199px;
    z-index: 1;
}

Update:

$('.menu a').click(function (e) {
            e.preventDefault();
            $(this).closest('div').siblings().removeClass('open');
            $(this).closest('div').addClass('open');
        });
#plink {
        position: relative;
        width: 200px;
        float: left;
    }

    .open {
        background-color: #a7a7ff !important;
        border-right: 1px solid #a7a7ff !important; 
        line-height: 50px;
        position: relative;
        text-align: center;
        z-index: 1;
    }

    .menu {
        border: 1px solid black;
        width: 200px;
        text-align: center;
        line-height: 50px;
        background-color: #5e5eb6;
    }

    .menu:hover a {
        display: block;
    }


    .open:hover a {
        display: block;
    }

    #pbase {
        border: 1px solid black;
        position: relative;
        width: 600px;
        height: 300px;
        float: left;
        background-color: #a7a7ff;
    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="plink">
    <div class="menu open"><a href="details.php">My details</a></div>
    <div class="menu"><a href="ads.php">My ads</a></div>
    <div class="menu"><a href="fav.php">Favorites</a></div>
</div>
<div id="pbase"></div>

Answer №3

There were a couple of issues that needed addressing. Firstly, using multiple id's with the same name should have been changed to classes. Additionally, 'open' and 'active' states should be defined with classes.

Another problem was the duplication in the css for different states.

The key point is adjusting the width of the active `.tab-nav`.

A crucial piece missing from the css was `box-sizing`.

* {
  box-sizing: border-box;
}

.tab-navigation {

    position: relative;
    width: 200px;
    float: left;
}

.tab-nav {
    border-top: 1px solid black;
    border-left: 1px solid black;
    background-color: white;
    width: 200px;
    text-align: center;
    line-height: 50px;
}

.tab-nav:last-of-type {
    border-bottom: 1px solid black;  
}


.tab-nav:hover, .tab-nav.open {
    width: 202px;
}

.tab-nav a {
    display: block;
}


#pbase {

    border: 1px solid black;
    position:relative;
    width: 600px;
    height: 300px;
    float: left;
    z-index: -1;
}
<div class="tab-navigation">
  <div class="tab-nav open"><a href="details.php">My Details</a></div>
  <div class="tab-nav"><a href="ads.php">My ads</a></div>
  <div class="tab-nav"><a href="fav.php">Favorites</a></div>
</div>
<div id="pbase"></div>

Answer №4

<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){

    $('#plink').click(function(){
        $('#open, #pbase').css('border','2px solid #000');

    })

})

</script>

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

Dynamic JavaScript Calculations Based on User Input in Real Time

I am in the process of creating a dynamic calculator that updates in real-time based on user input from a form. I have successfully implemented this feature using a sample div, but I am encountering difficulties when attempting to display the total inside ...

Navigating to the bottom of a specific element by scrolling

I am currently working on enhancing a module within the application I'm developing. The goal is to automatically scroll the browser window to the bottom of an element when said element's height exceeds the height of the window. The functionality ...

I am having trouble getting the (:active) pseudo-class to function properly with the menu on my WordPress theme

Purchased a theme called HelpGuru and encountering issues with the CSS of the menu. Reached out to support but they were unable to assist, directing me to a company that specializes in customizing WordPress themes instead. The link to the demo can be found ...

What types of events can be used to trigger the start of HTML5 audio playback in mobile Chrome?

When it comes to mobile browsers, Audio elements require user action before play can start. The click event usually satisfies this requirement, but touchstart doesn't seem to be an acceptable initiating event in Chrome on Android or iOS. (Refer below ...

Altering the dimensions of radio buttons

I am a newcomer to using material-ui. I am currently working on incorporating radio buttons in a component and would like to reduce its size. While inspecting it in Chrome, I was able to adjust the width of the svg icon (1em). However, I am unsure how to a ...

execute the changePage() function in jQuery using the data stored in localStorage

In my jQuery mobile page, I have a simple setup: <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.2"> <link rel="stylesheet" href="js/jquery.mobile-1.2.0.css" /> < ...

The img-fluid class is not properly adjusting the height of the image

I'm currently working with Bootstrap 4 and facing a challenge with creating a grid of 4 images - 2 on top and 2 at the bottom. I've applied the img-fluid class, but the image resizing is based solely on width, leading to the height being too larg ...

Preventing a webpage's CSS from affecting an iframe loading an HTML document

Whenever I load an iframe, it seems to change a bit. Do I need to apply some kind of reset or adjustment? How can I ensure that the content within the iframe looks consistent no matter what page it's loaded into? ...

When applying a maximum width of 100% with automatic height, images may become cropped

I'm a beginner in learning CSS, and since my technical skills are limited, I'll try to keep things simple. Currently, I have an image taking up half of the screen with the following CSS code that I found after reading some articles: <div class ...

Aligning Text at the Center in Your React Native Application

I'm facing a few issues with my visualization: Despite aligning it to the center, the text on my first button is positioned at the right end of the button. How can I move the text 'login' to the center? Currently, the 'Sign Up Her ...

Passport and Node.js team up to create powerful user group functionalities

Seeking advice on this topic. I am interested in setting up a page with a login form as the main page. Upon logging in, users would be directed to their personalized dashboard. However, if someone logs in with admin privileges, they should be redirected t ...

Is there a way to calculate the height of a component that is only rendered conditionally?

I have a scenario where I need to dynamically adjust the height of a component that is conditionally rendered without explicitly setting it. The height should automatically match the size of its content. To achieve this, I am using a reference to determin ...

My images seem to lose control and go completely wild when I try to turn them into hyperlinks

Seeking advice on why my social icons are behaving strangely. This is a new issue for me and I suspect that some other CSS is causing the problem, but I can't seem to locate it. I want to ensure that the formatting of these images remains consistent ...

Is there a way to incorporate two Bootstrap navbars on a single page that are of varying heights?

Utilizing Bootstrap 3.0 with dual navbars on a single page that adjust in height using the same variable for both .navbar blocks. Despite attempting to incorporate an additional class to alter the height of the initial navbar, it remains unaffected. Check ...

What is the process for customizing the user interface of modules in Apache OFBiz?

For the past month, I have been immersed in working on Apache ofbiz (17.12.07) and have developed a custom UI requirement for a client. My goal is to incorporate a side-bar (see screenshot attached below) into all ofbiz modules. To achieve this, I created ...

Is there a way to change my cursor to a pointer finger when hovering over my box?

<script type="text/javascript"> function draw() { var canvas = document.getElementById('Background'); if (canvas.getContext) { var ctx = canvas.getContext('2d'); ctx.lineWidth = 0.4 ctx.strokeRect(15, 135, 240, 40) Is there a w ...

Dynamic Code for Removing List Items Based on Date

I need assistance in resolving an issue with my company's website design and function. Specifically, I am working on a page that displays a list of events where employees will be present throughout the year. Here is an example: <div class="contai ...

The Javascript calculation function fails to execute proper calculations

I have been facing immense frustration while working on a project lately. The project involves creating a unique Webpage that can calculate the total cost for users based on their selections of radio buttons and check boxes. Assuming that all other functi ...

Having trouble setting the selected option in Jquery by value?

I have exhausted all options found on the internet. What could I be overlooking? The desired option is not getting selected. Here is the troublesome section of code. I have also included some other attempts that I have commented out. If it helps, this li ...

issues with the handler not functioning properly in html and javascript

<form method="post" action="."> <label class="input-label">Enter Your First Name</label><input field="first_name" class="input-edit" maxlength="30" type="text" value="{{ user.first_name }}" /> <label class="i ...