HTML position absolute for a table - html

I have a table that is inside a div. The div has a class="bar" and it is on the top of the screen. It has
top:0px;
left:0px;
right:0px;
The table inside this one, has 2 cells with a css hover that changes the color when you go over them with the mouse.
JSFiddle
Here you can see that when you go over C / C++ the grey background doesn't stay "inside" the div. I set the table to top:0px; left:0px; right:0px; but it is not fixed.
I want the grey rectangle to be inside the black div. What could I do?

The absolute positioning on the table isn't actually needed. You can remove that and then collapse the borders of your table using border-collapse: collapse:
#ontop {
width:100%;
text-align:center;
z-index:10;
border-collapse: collapse;
}
JSFiddle demo.

This css line will help you:
#bgrect { padding: 0; }

You forgot to set the border-spacing on the table to 0.
#ontop {
width:100%;
text-align:center;
top:0px;
left:0px;
right:0px;
position:absolute;
z-index:10;
border-spacing:0;
}
New fiddle.
(And while I agree that the absolute poisitioning is not needed in this example, I'm sure you have your reasons. You don't need the z-index though...)

You cannot have duplicate ID in one document!
Change #bgrect to .bgrect
<td width="50%" class="bgrect">
LIVE DEMO
CSS:
.bar{
/* NO BACKGROUND ! */
width:100%;
height:28px;
position:absolute;
top: 0;
left: 0;
font: 67.5%'Lucida Sans Unicode', 'Bitstream Vera Sans', 'Trebuchet Unicode MS', 'Lucida Grande', Verdana, Helvetica, sans-serif;
color:#D8D8D8;
}
#ontop {
width:100%;
text-align:center;
top:0px;
left:0px;
right:0px;
position:absolute;
z-index:10;
border-collapse:collapse; /* collapse borders */
}
.bgrect{
background-color: #0C0C0C; /* initial bg */
}
.bgrect:hover {
background-color: #2E2E2E; /* hover bg */
cursor:pointer;
}

Related

Images overflowing borders

I'm having an issue with images overflowing the set border for link type posts on my tumblr blog. I've tried re sizing width and height ratios and percentages for images, and yet I haven't been able to fix the issue. This also isn't an issue for images on of any other post types.
Here is the code that I'm pretty sure dictates the appearance of this.
.post.link .postcontainer{
padding:0;
overflow:hidden;
padding-bottom:5px;
}
.post.link .description{
padding-left:20px;
padding-right:60px;
padding-bottom:10px;
}
.post.link a.postlink{
font-family:"Helvetica Neue", helvetica, Arial, sans-serif;
font-size:12;
color:#000;
font-weight:bold;
width:428px;
padding-right:70px;
display:block;
padding-top:15px;
padding-bottom:10px;
padding-left:20px;
text-decoration:none;
}
.post.link a.postlink span{
background: url(http://static.tumblr.com/xsp9wak/PHAkloide/icon-linkpost-arrow.png) no-repeat top left;
width:35px;
height:36px;
display:block;
position:absolute;
right:20px;
top:50%;
margin-top:-17px;
opacity: .7;
-moz-opacity: 0.7;
}
.post.link a.postlink:hover span{
opacity: 1;
-moz-opacity: 1;
}
.post.link .vialink{
margin-left:20px;
}
For images, its ideally to add the following CSS rule:
img {
max-width: 100%;
}
When you set width to 100% it takes the width of content box. It will be fine when you don't have any padding or border. But, when you add border, then the width of border will be added to the 100% and it will be more than 100% which causes the overflow. So to include the border within the 100% you should set box-sizing property in css of image.
box-sizing: border-box;

How do you overlay text perfectly from a textarea onto div with same text?

I'm looking to overlap the same texts right on top of each other for an interesting idea I had on syntax highlighting.
I'm trying to do it with the textarea in the foreground, and the div in the background.
After setting the same position of the elements as well as the same font size, they still do not overlap perfectly. What am I missing, exactly?
Fiddle
div,textarea{
position:absolute;
top:0;
left:0;
background:transparent;
font-size:1em;
line-height:1em;
}
set a same font-family for both
textarea has 1px border so you can add border:1px solid transparent to div which has the text so that it aligns
* {
margin: 0;
padding: 0;
}
div{
border:1px solid transparent
}
div,
textarea {
position: absolute;
top: 0;
left: 0;
background: transparent;
font-size: 1em;
line-height: 1em;
font-family: arial;
}
<div>Hello, world!</div>
<textarea>Hello, world!</textarea>
Try setting the font-family, padding, and border-width explicitly:
div,textarea{
position:absolute;
top:0;
left:0;
background:transparent;
font-size:1em;
line-height:1em;
font-family:sans-serif;
padding:0;
border-width:0;
}
Two comments:
Browsers define a default style for textarea elements, so the trick is to figure out what properties are being set by the browser and override those explicitly. It's best to override the properties on both the div and the textarea. If you only change the div to accommodate for the browser's default style of the textarea, you'll get varying results in different browsers. For example, in Chrome the default border width for a textarea is 1 pixel, while in Firefox, it's 2 pixels.
Due to the way font anti-aliasing works, you'll always get a slightly bold effect. Probably best to set one of the two font colors to white or transparent.
Try this :-
Link
div,textarea{
position:absolute;
top:0;
left:0;
background:transparent;
font-size:1em;
line-height:1em;
font-family:arial /*add same font-family */
}
and
div{
padding:3px 3px 0
}

How can i make it so the overflow of a div positions to the right ? CSS

Ok so this is how it looks right now but i want to overflow to go to the right instead of down.
This is the CSS code:
body{
position:relative;
margin:0px;
background-image:url('../images/background.png');
font-family: 'Open Sans', sans-serif;
}
#logo{
font-size:45px;
font-weight:bold;
}
#today_section{
position:relative;
margin-top:100px;
margin-left:auto;
margin-right:auto;
width:900px;
height:219px;
background-image:url("../images/slider_background.png");
/*overflow:hidden;*/
}
.movie{
position:relative;
margin-top:10px;
margin-left:15px;
width:134px;
height:199px;
}
The slider is called "today_section" and each movie has the class "movie".
Try adding:
#today_section{
overflow:hidden;
}
.movie{
display:inline-block
}
.movie{
float:left;
}
try adding this
I raised the width of the today_section to 2000 and added overflow:hidden to the container

How to make html text rise above absolutely positioned element?

I am trying to get some hardcoded text to show above a absolutely positioned element that is an image using z-index to no avail.
Is there something I'm missing?
.repay {
font-family:Arial,Helvetica, sans-serif;
font-size:18px;
color:#444;
text-align:center;
font-weight:bold;
margin:40px 0px 30px 0px;
z-index:10001;
}
.sliderbubble-repay {
width:227px;
height:140px;
background:url('../images/white-sliderbubble.png') no-repeat;
position:absolute;
top:119px;
left:255px;
z-index:1;
}
Elements need to have position:absolute; or position:relative; for z-index to work.
Try adding position:relative; to .repay

Cannot arrange layout with z-index

HTML
<div id='divTop'>divTop<br>divTop<br>divtop</div>
<div id='btnHome'>Home</div>
<div id="player">player<br>player<br>player</div>
CSS
body{
position:relative;
max-width:1024px;
height:100%;
margin:0 auto;
font-family: "Trebuchet MS", sans-serif;
text-align:center;
}
#divTop{
display:none;
position:relative;
z-index:5;
text-align:center;
background:#008080;
border-bottom:medium ridge #D10000;
}
#btnHome{
cursor:pointer;
position:absolute;
top:1.5vh;
left:1vw;
max-width:3.4vw;
z-index:6;
}
#player{
display:none;
position:relative;
z-index:3;
max-width:95vmin;
max-height:95vmin;
border:medium ridge #ffffff;
border-radius:9px;
}
JS
y = $(window).innerHeight() - $('#player').height();
$('#player').css ('margin-top', y/2);
$('#player').show();
$("#btnHome").click(function() {
$('#divTop').slideToggle('slow');
});
Why is btnHome inside player. It should be fixed on top-left of page ?
Clicking on btnHome why is player pushed down ? It should be also fixed. I just want to show-hide divTop by overlapping everything bellow.
fiddle is here
Remove position:relative from body.
UPDATE: add a parent wrapper to the #divTop
#wrapper {
width:100%;
overflow:hidden;
}
#divTop{
position:relative;
z-index:5;
text-align:center;
background:#008080;
border-bottom:medium ridge #D10000;
}
JS
var dTHei = $('#divTop').outerHeight(); //get height of the #div top
$('#wrapper').height(dTHei); //set it as the height of the wrapper
$('#divTop').hide(); // hide the div top
//run your function here
http://jsfiddle.net/2zAm5/1/
Try changing position from relative to absolute
and use top,bottom,right and left instead.
change positions of btnHome and player to fixed, and also use top property for player so it will not move: e.g. top : 200px.
#divTop{
display:none;
position:relative;
z-index:5;
text-align:center;
background:#008080;
border-bottom:medium ridge #D10000;
}
#btnHome{
cursor:pointer;
position:fixed;
top:1.5vh;
left:1vw;
max-width:3.4vw;
z-index:6;
}
#player{
display:none;
position:fixed;
z-index:3;
max-width:95vmin;
max-height:95vmin;
border:medium ridge #ffffff;
border-radius:9px;
top:200px;
}