Reputation: 222501
I am trying to have a close button on the right side of the div but a little bit higher than the div. Something like on the following picture:
After searching for a little bit I found the following relevant question here, I tried to modify it a little bit to get what I want.
My attempt can be viewed on the fiddle:
<div class="area">
<span class="close">X</span>
<div class="areaInside">some data</div>
</div>
.areaInside{
border: 2px dashed #bbb;
border-radius: 10px;
color: #bbb;
min-height: 80px;
}
.area{
width:70%;
height:100px;
}
.close{
float:right;
cursor: pointer;
font-weight: bold;
}
But clearly it does not do what I wanted. I want the close button to be above the area and a little bit to the left. How can I achieve this without changing the markup (only with css).
Upvotes: 0
Views: 3628
Reputation: 10378
Use Position concept make parent property relative and child property absolute now child css work relative to parent
.areaInside{
border: 2px dashed #bbb;
-moz-border-radius: 10x;
-webkit-border-radius: 10x;
border-radius: 10px;
color: #bbb;
min-height: 80px;
position:absolute;
width: 100%;
}
.area{
width:200px;
height:100px;
position:relative;
}
.close{
float:right;
cursor: pointer;
font-weight: bold;
position: absolute;
right: 2px;
top: -14px;
}
Upvotes: 1
Reputation: 3220
.close {
float: right;
cursor: pointer;
font-weight: bold;
display: block;
margin-top: -17px;
margin-right: 8px;
background: red;
}
Upvotes: 1
Reputation: 20313
Try this:
.close {
float: right;
cursor: pointer;
font-weight: bold;
position: relative;
margin-top: -15px;
margin-right: 10px;
}
Upvotes: 1
Reputation: 4270
You can use positions
.area{
width:70%;
height:100px;
position:relative;
}
.close{
position: absolute;
right: 2px;
top: -10px;
cursor: pointer;
font-weight: bold;
}
Upvotes: 1