After pseudoelement appear outside overflow-y ancestor - css

I am trying to create a list of elements inside a wrapper container with overflow-y set to scroll. The problem is that I want each of these elements to have a tag appear on their right on hover.
This wrapper is inside of a vertical container with fixed width (cant be modified), which is used to align the wrapper with their siblings.
I am using an after pseudoelement to achieve this. The problem comes when I try to position the tag outside the wrapper container, which makes the tags not render.
Some example code:
<div class="wrapper">
<p class="item" data-text="tag-1">
item1
</p>
<p class="item" data-text="tag-2">
item2
</p>
<p class="item" data-text="tag-3">
item3
</p>
</div>
.wrapper {
width: 10rem;
height: 5rem;
padding: 1rem;
border: 1px solid red;
overflow-y: scroll;
font-size: 2.5rem;
}
.item{
position: relative;
font-size: 2rem
}
.item::before{
content: "#";
}
.item::after{
content:attr(data-text);
position: absolute;
top: 50%;
left: 10rem;
padding: 1rem;
transform: translateY(-50%);
font-size: 1rem;
color: white;
background-color: black;
border-radius: 500px;
cursor: pointer;
}
In this case I want the tags to appear outside the wrapper but positioned relative to their parent element. Is this posible to achieve using only css?
I tried using different positions, setting the overflow-x to visible and almost every answer I could find except using JS.

Related

How can I absolute-position a child element relative to the content box (not padding box) of its relative-positioned parent?

As you can see from the example below, .absolute_child is positioned relative to .relative_parent's padding box. How can I position it at the top of .relative_parent's content box instead? I'm willing to add extra elements (e.g. nested divs) to the HTML, as that generally seems to be what I wind up having to do for more fiddly layouts!
.relative_parent {
position: relative;
height: 100px;
padding: 30px;
background-color: green;
}
.absolute_child {
position: absolute;
top: 0px;
height: 10px;
width: 10px;
background-color: blue;
}
<div class="relative_parent">
Content box of parent starts here
<div class="absolute_child">
</div>
</div>

Prevent content to scroll beneath a fixed navbar

This page http://alsotoday.com/roemerstrasse/ has a fixed bootstrap navbar, which should stay fixed, so the video in the background can shine through it. When scrolling the content all the way up, it will go beneath the navbar, which is not favourable. Anybody know, how to create an upper margin for the content, so it will scroll only just beneath the navbar without changing the navbar to not-fixed?
Edit 1:
main-area-video and panel_container (meanwhile called main-area) are both height 100%, because each, the video and the tiles should fill a screen.
Something like this ? In this snippet, the articles will not go behind the navbar, and only the content is scrollable. This is how SPA are supposed to work, for instance.
EDIT I added an opacity to the navbar so you can see, nothing is behind it.
body {
margin: 0;
height: 100%;
overflow: hidden;
}
.navbar {
position: fixed;
top: 0;
height: 50px;
line-height: 50px;
font-weight: bold;
font-family: Helvetica;
font-size: 30px;
background: darkcyan;
width: 100%;
padding: 0 20px;
color: white;
opacity: 0.2;
}
.content {
margin-top: 50px;
background: #ddd;
height: calc(100vh - 50px);
overflow: auto;
padding: 12px;
box-sizing: border-box;
}
.article {
height: 200px;
width: 100%;
background: #ccc;
margin: 12px 0;
}
<div class="navbar">Navbar</div>
<div class="content">
<div class="article"></div>
<div class="article"></div>
<div class="article"></div>
<div class="article"></div>
<div class="article"></div>
</div>
Since your page is always at 100% height and the only thing getting scrolled is the content you could just make it absolute instead of fixed.
But since you asked for a solution with a fixed position just add an margin to the content wrapper.
So to be clear: add margin-top: {MENU_HEIGHT}px to the content div, replacing {MENU_HEIGHT} with the actual height of your menu or the desired distance from it.

Button width % seems to jump out of container on smaller screens

Using bootstrap3 with mvc5.
Using the grid system, I have 4 across in a row ("col-md-3"). Here is HTML for one box:
<div class="col-md-3">
<div class="index-box">
<h2>Other Reports</h2>
<p>Click this button to go to the report index page.</p>
<button class="big-button">View Reports</button>
</div>
</div>
In full screen, the button sits nicely in the box, but when I view on mobile device, the boxes are stacked (as they should) but the button width becomes a percent of the full screen instead of the .index-box. HEre is current css:
.index-box {
border: 1px #527f03 solid;
border-radius: 5px;
text-align: center;
padding-bottom: 20px;
height: 250px;
max-width: 260px;
}
.index-box h2 {
position: relative;
top: -25px;
background-color: #dfece2;
display: inline-block;
}
.big-button {
position: absolute;
margin-left: -35%;
left: 50%;
width: 70%;
max-width: 70%;
bottom: 20px;
background: #9cc64e;
padding: 5px 10px;
color: #23423a;
font-size: 18px;
text-decoration: none;
}
How it looks on mobile screen width:
Using Bootstrap's classes when available, such as .btn-block will give you a full-width button, then wrap that in a container and add margin or padding to it. And remove the absolute positioning...
This should point you in the right direction....
.big-button {
background: #9cc64e;
padding: 5px 10px;
color: #23423a;
font-size: 18px;
text-decoration: none;
}
.big-button-cont {
padding: 0 15%;
}
</style>
<div class="col-md-3">
<div class="index-box">
<h2>Other Reports</h2>
<p>Click this button to go to the report index page.</p>
<div class="big-button-cont">
<button class="btn big-button btn-block">View Reports</button>
</div>
</div>
</div>
it's a good idea to take bootstrap's classes and modify them in an "override" that loads after the bootstrap.css stylesheet, this way you can keep it within the framework and just change the bits and pieces you need, such as the button color, etc.
Try adding position relative the index-box. An element that is positioned using absolute behaves like fixed except relative to the nearest positioned ancestor instead of relative to the viewport. If it has no positioned ancestor it will position itself relative to the viewport

Absolute positioning (with relative position container) with an image or nothing under it is affecting other divs

I don't really even know what my problem is anymore, but I'll try to explain it as best as I can.
Basically what I have is a two column layout. On the left is the content, which at present only contains a h1 and filler text. On the right is the sidebar which should have a div in it (userinfobox).
The header text of the box is supposed to be outside the box a bit so I have the userinfobox position: relative and the header text position: absolute
Then, under that inside the box, there is a 150x150 image and then some more text below that.
Here's the HTML:
<!-- Main Content -->
<div id="contentwrapper" role="presentation">
<div id="content" role="main">
<h1>Header</h1>
Content link
</div> <!-- content div -->
<!-- Sidebar -->
<div id="sidebar" role="complementary">
<div id="userinfobox">
<p id="header">User Info</p>
<div id="userinfo">
<div id="avatar"><img src="" id="tag" alt="tag" /></div>
<p class="username">Username #</p>
<p id="icons">Icons</p>
<p id="membersonline">Online Members (#)</p></div>
</div> <!-- userinfo div -->
</div> <!-- userinfobox div -->
</div> <!-- sidebar div -->
</div> <!-- contentwrapper div -->
And then the CSS
/* Main Content */
#contentwrapper {
min-height: 400px;
height: 100%;
position: relative;
display: table;
font-size: 1em;
}
#content {
width: 669px;
height: 100%;
padding: 20px;
position: relative;
display: table-cell;
background-color: #F7F8F7;
text-align: left;
}
#content h1 {
margin-bottom: 20px;
font-size: 2.75em;
line-height: 1em;
}
/* Sidebar */
#sidebar {
width: 234px;
height: 100%;
padding: 20px;
position: relative;
color: #0D130D;
background-color: #FDEBCF;
display: table-cell;
text-align: center;
}
#sidebar p#header {
position: absolute;
top: -10px;
font-size: 1.5em;
line-height: 1em;
text-align: left;
overflow: hidden;
}
#sidebar p {
max-width: 214px;
margin: 0 auto;
text-align: center;
overflow: hidden;
}
/* Logged In Sidebar */
#userinfobox {
width: 214px;
max-width: 214px;
padding: 10px;
position: relative;
background-color: #F7F8F7;
}
#avatar, #tag, #userinfo {
margin: 0 auto;
position: relative;
display: block;
outline: 1px solid #000;
overflow: hidden;
}
#avatar, #tag {
width: 150px!important;
height: 150px!important;
}
That should be working, I don't see any reason why it wouldn't be; actually it is working, the sidebar anyway is doing what it's supposed to. But sometimes it pushes down the content (currently the h1 and two words of text), almost to where the bottom of the 150x150 image would be.
I'll attempt to list the conditions that cause it to do this:
It does not work when:
the avatar div is completely empty and the header is position: absolute
the image has a src and the header is position: absolute
But, it does works when (seemingly regardless of absolute positioning of the header):
the src of the image is empty
there is no image, just text, in the avatar div (ie. just text in the entire userinfo div)
the userinfo div is completely empty
I just don't understand how it's affecting something in a completely different div. Every place I've tried to search about this just talked about how absolutely positioned elements inside a relatively positioned element won't affect anything outside and how to use them. Also, this is a fixed width setup, so it's not like the width is changing at all; it is also not based on percent.
Since your #content div is using display:table-cell;, you must also apply vertical-align:top; to prevent your content from centering:
http://jsfiddle.net/R8zAw/3/
#content {
width: 669px;
height: 100%;
padding: 20px;
padding-top: 0;
position: relative;
display: table-cell;
background-color: #F7F8F7;
text-align: left;
border-bottom-left-radius: 5px;
vertical-align: top; /* add this */
}

CSS - parent div is not expanding to width/height of child

I am looking to overlay a caption on to an image. I have managed to do this, but the image is expanding out of the parent div.
I have the containing div set to inline-block, as I want it to 'auto size', not take up width: 100%. If you look at the current output, you'll see the image could be within the black bordered box.
It only needs to work in Chrome, if you encounter cross-browser issues.
Thanks in advance!
LIVE DEMO
CSS:
#body_content {
border: solid 1px blue;
display: inline-block;
padding: 5px;
}
#body_header {
border: solid 1px red;
font-size: 25px;
padding: 5px;
}
#body_image {
position: absolute;
}
#body_image_caption {
color: white;
line-height: 30px;
margin-left: 10px;
}
#body_image_container {
background: white;
border: solid 1px black;
margin-top: 3px;
padding: 10px;
}
#body_image_overlay {
background-color: black;
bottom: 5px;
display: block;
height: 30px;
opacity: 0.85;
position: absolute;
width: 100%;
}​
HTML:
<div id="body_content">
<div id="body_header">
Heading
</div>
<div id="body_image_container">
<div id="body_image">
<img src="http://i.imgur.com/s6G8n.jpg" width="200" height="200" />
<div id="body_image_overlay">
<div id="body_image_caption">
Some Text
</div>
</div>
</div>
</div>
</div>
The #body_image element is escaping from the #body_image_container because its position is set to absolute. Absolutely positioned elements are removed from the document's flow, causing parent elements to collapse as though the child element wasn't there. If you change it to relative, then it becomes contained within the black box:
#body_image{
position: relative;
}
http://jsfiddle.net/AaXTm/2/
Try this css in parent div.
Overflow:auto
Check this fiddle. You need to set the position of the child element of the image to be absolute and the parent element to be relative. Change the width of the caption accordingly.
child-element {
position:absolute;
}
parent-element {
position:relative
}
http://jsfiddle.net/AaXTm/4/

Resources