Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make child element cover border of parent?

Tags:

html

css

Here is a sort of rough picture of what I am trying to do. If it doesn't explain it well enough I can throw together a fiddle.

enter image description here

The black box is a <div> and the pink ones are also divs. What I want is for them to look sort of like tabs. So when one is active, it covers up the border of the parent giving the 'bridge' effect that is important in tabs.

I thought that I could just make the active one slightly more wide so it would cover up the border. The problem is if I have overflow-x: hidden; the wider part is 'beneath' the black outline and if I do auto or visible then it just lets it scroll.

One important thing: the pink need to have position relative.

What am I doing wrong?

EDIT: forgot to mention the most important part. The black box has overflow-y: hidden. Without it the methods below work fine, but when I add it, it goes back to how it was

like image 891
Troy Cosentino Avatar asked Apr 23 '13 22:04

Troy Cosentino


2 Answers

Maybe this approach will help you:

.main {text-align: right;border: 10px solid #000;}
.main > div > div {width: 100px; height: 60px; display: inline-block;background-color: red;margin: 10px 0;}
.main > .selected > div {margin-right: -10px;padding-left: 10px;}
<div class="main">
    <div class="selected"><div></div></div>
    <div><div></div></div>
    <div><div></div></div>
</div>
like image 144
fje Avatar answered Sep 22 '22 10:09

fje


You just need to set a width on your container div, and not use overflow-x hidden;.

Here's an example: http://jsfiddle.net/YhAmh/1/

like image 34
thatmiddleway Avatar answered Sep 21 '22 10:09

thatmiddleway