Align element to bottom of container that uses display: table - html

I have 3 boxes which need to be the same height with varying content. I am using display: table to achieve this. I need to vertically align the button to the bottom of the container. The button width could also change. I was not able to successfully get vertical-align: bottom to work.
http://codepen.io/simply-simpy/pen/kBaHt
<div id="cta-3-col" class="cta-3-col">
<div class="container">
<div class="cta">
<figure>
<img src="http://lorempixel.com/200/100/" alt="">
<figcaption>
<h2>CTA 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing </p>
</figcaption>
</figure>
Follow<i></i>
</div>
<div class="cta">
<figure>
<img src="http://lorempixel.com/200/100/" alt="">
<figcaption>
<h2>CTA 2</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt magna aliqua sed do edunt ut labore et dolore magna aliqua. </p>
</figcaption>
</figure>
Partner With Us<i></i>
</div>
<div class="cta">
<figure>
<img src="http://lorempixel.com/200/100/" alt="">
<figcaption>
<h2>CTA 3</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
</figcaption>
</figure>
Learn<i></i>
</div>
</div>
</div>
.cta {
background: #fff;
display: table-cell;
width: 270px;
padding: 0 0 30px;
}
.cta-3-col {
background: gray;
text-align: center;
border-spacing: 10px;
}
.container {
display: table;
width: 1000px;
margin: 0 auto;
}
.btn {
background: blue;
color: #fff;
padding: 10px;
}

You just have to change/add some CSS properties to your existing classes without adding extra markup:
http://codepen.io/anon/pen/rFmxa
CSS:
.cta {
background: #fff;
display: table-cell;
width: 270px;
/*padding: 0 0 30px;*/
padding: 0 0 4em;
position: relative;
}
.cta-3-col {
background: gray;
text-align: center;
border-spacing: 10px;
}
.container {
display: table;
width: 1000px;
margin: 0 auto;
}
.btn {
background: blue;
color: #fff;
padding: 10px;
position: absolute;
bottom: 0;
margin-bottom: 1em;
left: 50%;
-webkit-transform: translateX(-50%);
-moz-transform: translateX(-50%);
-ms-transform: translateX(-50%);
-o-transform: translateX(-50%);
transform: translateX(-50%);
}

look modified code without complex transform-translate properties wich will work in all browsers including ols IE!
advantages over other methods: efficient, fast, cross-browser, easy!
Codepen YourSolution
Modified css
.cta {
background: #fff;
display: table-cell;
width: 270px;
padding: 0 0 30px;
position:relative;
}
.cta-3-col {
background: gray;
text-align: center;
border-spacing: 10px;
.container {
display: table;
width: 1000px;
margin: 0 auto;
}
}
p {
margin:10px 0px 40px 0px;
}
a.btn {
position: absolute;
bottom: 10px;
left: 0;
right: 0px;
width: 64px;
margin: auto;
background: blue;
color: #fff;
padding: 10px;
}

Here's an updated CodePen.
The bulk of the change was adding a position:relative; modifier to the .cta class and then giving the following rules to the class .btn:
position:absolute;
bottom:5px;
left:50%;
-moz-transform:translateX(-50%);
-webkit-transform:translateX(-50%);
transform: translateX(-50%);
That should take care of the problem for you.

.cta {
background: #fff;
display: table-cell;
width: 270px;
padding: 0 0 40px;
position:relative;
}
.btn {
background: blue;
color: #fff;
padding: 10px;
position:absolute;
left:50%;
bottom:0;
-webkit-transform: translateX(-50%);
-moz-transform: translateX(-50%);
-ms-transform: translateX(-50%);
-o-transform: translateX(-50%);
transform: translateX(-50%);
}

You just need to add below additional css and it will display your html as you requested:
- .cta {position:relative;}
- .btn {position:absolute;left:45%;bottom:0px;}

Related

Change the colour of text that overlaps an image

The look I'm trying to achieve is if you have black text on a white page, but that text runs into an image. The section of text that is over the image changes it's colour.
I have a 'working' (not flexible) example here using a data attribute to grab the same text and set it on the :before element using content:
https://codepen.io/moy/pen/rNeaGbJ
/* General Shit */
body {
color: #000;
font-family: Arial;
font-size: 1.2rem;
line-height: 1.5;
}
h2 {
font-size: 3.6rem;
margin-bottom: 30px;
}
p {
margin-bottom: 30px;
}
.btn {
background: #000;
color: #fff;
display: inline-block;
font-size: 1.2rem;
padding: 15px 60px;
}
img {
width: 100%;
max-width: 100%;
}
/* Grid */
.grid {
clear: both;
margin: 0 auto;
padding: 30px 0;
max-width: 1000px;
}
.grid__item {
box-sizing: border-box;
float: left;
}
.grid--flip .grid__item {
float: right;
}
.grid__item--caption {
padding: 30px 60px;
}
.one-half {
width: 50%;
}
/* Title */
.title-wrap {
display: -webkit-box;
display: flex;
-webkit-box-pack: start;
justify-content: flex-start;
margin-left: -60%;
overflow: hidden;
position: relative;
}
.grid--flip .title-wrap {
-webkit-box-pack: end;
justify-content: flex-end;
margin-left: 0;
margin-right: -60%;
}
.title {
color: #000;
}
.grid--flip .title {
color: #fff;
}
.title:before {
color: #fff;
content: attr(data-title);
display: block;
overflow: hidden;
position: absolute;
width: 27.75%;
white-space: nowrap;
}
.grid--flip .title:before {
color: #000;
width: 34.75%;
}
<div class="grid">
<div class="grid__item grid__item--image one-half">
<img src="http://www.fillmurray.com/800/800" />
</div>
<div class="grid__item grid__item--caption one-half">
<div class="title-wrap">
<h2 class="title" data-title="Title goes here">Title goes here</h2>
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
Shop Collection
</div>
</div>
<div class="grid grid--flip">
<div class="grid__item grid__item--image one-half">
<img src="http://www.fillmurray.com/800/800" />
</div>
<div class="grid__item grid__item--caption one-half">
<div class="title-wrap">
<h2 class="title" data-title="Title goes here">Title goes here</h2>
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
Shop Collection
</div>
</div>
The problem with this is if...
I adjust the width of the container, all the values are off and it looks broken.
the title is longer and wraps onto multiple lines, it is cut off due to the overflow
And why the widths are what they are on the :before element (if someone could explain that'd be great ha)
So I tried a version using px values instead of % which fixes the issues of changing the container width. However I still have the issue of it not behaving right when text wraps onto 2 lines.
Example (using px): https://codepen.io/moy/pen/JjXoMvb
Can anyone think of a better solution for this? Am I overcomplicating this or missing something obvious?
Edit: PX example wrong incorrect, updated link now.
Use the CSS clip-path property
Example
:root {
--size: 100px;
}
.resizable {
border: 2px solid black;
width: calc(var(--size) * 3);
height: calc(var(--size) * 2);
resize: both;
overflow: auto;
}
.container {
position: relative;
}
.divider {
height: 100px;
}
.title {
position: absolute;
top: 0;
left: 0;
right: 0;
margin: 0;
}
img {
width: var(--size);
height: var(--size);
}
.left {
color: blue;
clip-path: polygon(0 0, var(--size) 0, var(--size) var(--size), 0 var(--size));
}
.right {
color: red;
clip-path: polygon(var(--size) 0, 100% 0, 100% 100%, 0 100%, 0 var(--size), var(--size) var(--size));
}
.container-reverse img {
float: right;
}
.container-reverse .left {
clip-path: polygon(100% 0, 100% var(--size), calc(100% - var(--size)) var(--size), calc(100% - var(--size)) 0);
}
.container-reverse .right {
clip-path: polygon(0 0, calc(100% - var(--size)) 0, calc(100% - var(--size)) var(--size), 100% var(--size), 100% 100%, 0 100%);
}
.container-reverse h1 {
text-align: right;
}
<div class="resizable">
<div class="container">
<h1 class="title left">Lorem ipsum dolor sit amet, consectetur adipiscing elit</h1>
<h1 class="title right">Lorem ipsum dolor sit amet, consectetur adipiscing elit</h1>
<img src="http://placehold.it/100x100" />
</div>
<div class="divider"></div>
<div class="container container-reverse">
<h1 class="title left">Lorem ipsum dolor sit amet, consectetur adipiscing elit</h1>
<h1 class="title right">Lorem ipsum dolor sit amet, consectetur adipiscing elit</h1>
<img src="http://placehold.it/100x100" />
</div>
</div>

non semantic and semantic HTML [duplicate]

This question already exists:
non-semantic html code to semantic code html [closed]
Closed 3 years ago.
I currently have the HTML and CSS code below where I have used divs for different elemenets within the webpage. You can run the code to see the output below. I have been told by my lecturer that it is not semantic and need to change the divs to main, section, article etc but i'm not entirely sure how to go about doing this with the HTML and CSS that I have posted below. Can you still add classes to main, section etc?
*{
box-sizing: border-box;
}
body{
margin: 0;
padding: 0;
font:15px/1.5 Arial, Helvetica, sans-serif;
}
/*box display*/
.box_content{
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
/*box sizing*/
.box_content .box{
position: relative;
width: 350px;
padding: 30px;
background:#2a333b;
box-shadow: 0px 20px 25px rgba(0,0,0,.2);
border-radius: 4px;
margin: 30px;
box-sizing: border-box;
overflow: hidden;
text-align: center;
}
/*number icons*/
.box_content .box .icon{
position: relative;
width: 80px;
height: 80px;
color: #fff;
background: #000;
display: flex;
justify-content: center;
align-items: center;
margin: 0 auto;
border-radius: 50%;
font-size: 40px;
font-weight: 700;
transition: 1s;
}
/*icon colouring*/
.box_content .box .icon{
box-shadow: 0 0 0 #4eb1ba;
background: #4eb1ba;
}
/*hovering*/
.box_content .box:hover .icon{
box-shadow: 0 0 0 400px #4eb1ba;
}
/*position content*/
.box_content .box .content{
position: relative;
z-index: 1;
transition: 0.5s;
}
/*title color*/
.box_content .box .content {
color: #fff;
}
/*paragraph sizing*/
.box_content .box .content p{
margin: 10px;
padding: 0;
}
/*heading size*/
.box_content .box .content h1{
margin: 10px;
padding: 0;
font-size: 25px;
}
/*links- read more*/
.box_content .box .content a{
display: inline-block;
padding:10px 20px;
background: #2a333b;
color:#fff;
border-radius: 4px;
text-decoration: none;
font-weight: 500;
margin: 20px;
box-shadow: 0 2px 5px rgba(0,0,0,.2);
}
*/
<div class="box_content">
<div class="box">
<div class="icon">01</div>
<div class="content">
<h1>Intro to Business Management</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
Read More
</div>
</div>
<div class="box">
<div class="icon">02</div>
<div class="content">
<h1>Digital Identity</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
Read More
</div>
</div>
<div class="box">
<div class="icon">03</div>
<div class="content">
<h1>Information Systems & Databases</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
Read More
</div>
</div>
</div>

Absolute div height being cut off inside relative div

I'm having trouble getting one of my absolutely positioned divs to display correctly. It's getting cut off unless I set a height for the parent (relative) div which I can't do as I will never know the height required.
I originally wasn't using any absolute positioning but the contents of the comm div were wrapping underneath the avatar div so I thought absolute positioning would fix it and it has, apart from the text being cut off at the bottom.
This is the structure and you can see what's happening in this fiddle.
body {
background: #212121;
font-family: arial;
}
.main {
width: 80%;
margin: 20px auto;
}
.wrap {
width: 100%;
background: white;
padding: 10px;
overflow: hidden;
position: relative;
}
a.avatar {
width: 45px;
height: 45px;
border-radius: 50%;
overflow: hidden;
display: inline-block;
float: left;
margin-right: 10px;
position: relative;
}
a.avatar img {
width: 100%;
}
.top {
display: block;
overflow: hidden;
position: absolute;
left: 70px;
}
a.name {
font-weight: bold;
margin-right: 10px;
float: left;
}
.posted {
color: #BBB;
font-size: 12px;
padding-top: 3px;
float: left;
}
p.comm {
display: block;
position: absolute;
left: 70px;
top: 20px;
height: 100%;
}
<div class="main">
<div class="wrap">
<img src="http://www.tangoflooring.ca/wp-content/uploads/2015/07/user-avatar-placeholder.png" />
<div class="top">
John Doe
<div class="posted">8 mins ago</div>
</div>
<p class="comm">Lorem ipsum dolor sit amet.
</p>
</div>
<div class="wrap">
<img src="http://www.tangoflooring.ca/wp-content/uploads/2015/07/user-avatar-placeholder.png" />
<div class="top">
Jane Doe
<div class="posted">11 mins ago</div>
</div>
<p class="comm">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p>
</div>
<div class="wrap">
<img src="http://www.tangoflooring.ca/wp-content/uploads/2015/07/user-avatar-placeholder.png" />
<div class="top">
Jimmy Doe
<div class="posted">18 mins ago</div>
</div>
<p class="comm">Ut enim ad minim veniam.
</p>
</div>
</div>
Try using this modified css code.
body {
background: #212121;
font-family: arial;
}
.main {
width: 80%;
margin: 20px auto;
}
.wrap {
width: 100%;
background: white;
padding: 10px;
position: relative;
}
a.avatar {
width: 45px;
height: 45px;
border-radius: 50%;
overflow: hidden;
display: inline-block;
float: left;
margin-right: 10px;
position: relative;
}
a.avatar img {
width: 100%;
}
.top {
display: flex;
margin-left: 70px;
}
a.name {
font-weight: bold;
margin-right: 10px;
}
.posted {
color: #BBB;
font-size: 12px;
padding-top: 3px;
}
p.comm {
display: block;
margin-left: 70px;
height: 100%;
}
You need to wrap .top and .comm in a div and with the use of flex you can achieve it
body {
background: #212121;
font-family: arial;
}
.main {
width: 80%;
margin:20px auto;
}
.wrap {
width: 100%;
background: white;
padding: 10px;
overflow: hidden;
position: relative;
display: flex;
}
a.avatar {
margin-right: 10px;
}
a.avatar img {
width: 45px;
height: 45px;
border-radius: 50%;
}
.top {
width: 100%;
overflow: hidden;
}
a.name {
font-weight: bold;
margin-right: 10px;
float: left;
}
.posted {
color: #BBB;
font-size: 12px;
padding-top: 3px;
float: left;
}
p.comm {
margin-top: 5px;
}
.right {
max-width: 88%;
}
<div class="main">
<div class="wrap">
<img src="http://www.tangoflooring.ca/wp-content/uploads/2015/07/user-avatar-placeholder.png">
<div class="right">
<div class="top">
Jane Doe
<div class="posted">11 mins ago</div>
</div>
<p class="comm">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do </p>
</div>
</div>
<div class="wrap">
<img src="http://www.tangoflooring.ca/wp-content/uploads/2015/07/user-avatar-placeholder.png">
<div class="right">
<div class="top">
Jane Doe
<div class="posted">11 mins ago</div>
</div>
<p class="comm">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
</div>
<div class="wrap">
<img src="http://www.tangoflooring.ca/wp-content/uploads/2015/07/user-avatar-placeholder.png">
<div class="right">
<div class="top">
Jane Doe
<div class="posted">11 mins ago</div>
</div>
<p class="comm">Lorem ipsum dolor sit amet</p>
</div>
</div>
</div>
Working fiddle here
Just modify on your p.comm selector like below:
p.comm {
display: block;
position: relative;
top: 10px;
padding-left: 60px;
}

Align CSS arrow with the bottom center of the button

I have a "ticket" component. There are some information, button and a notification in some cases. And that notification has an arrow which I should align with the bottom center of the button. The problem is that the button has the different width because our website translated into a few languages and the button text length changes. I tied to find percentage but failed and I have no idea how to solve it.
The ticket structure:
.ticket {
border: 1px dashed gray;
border-radius: 3px;
}
.ticket__content {
padding: 0.5rem 1rem;
}
.button {
border-radius: 3px;
border: 0;
padding: 1rem 1.5rem;
background-color: darkslateblue;
text-align: center;
min-width: 180px;
max-width: 100%;
width: auto;
display: inline-block;
color: #FFFFFF;
font-size: 1rem;
}
.notification {
margin-top: 2rem;
}
.notification__content {
background-color: gold;
padding: 1.5rem;
text-align: left;
}
.notification__arrow-container {
width: 75%;
padding-right: 1.5rem;
padding-left: 1.5rem;
position: relative;
}
.notification__arrow::after {
top: -1rem;
right: 0;
position: absolute;
border-bottom-color: gold;
display: block;
content: "";
width: 0;
height: 0;
border-right: 1rem solid transparent;
border-bottom-width: 1rem;
border-bottom-style: solid;
border-left: 1rem solid transparent;
}
.align-right {
text-align: right;
}
<div class="ticket">
<div class="ticket__content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
<div class="align-right">
<button class="button">Do it</button>
</div>
</div>
<div class="notification">
<div class="notification__arrow-container">
<div class="notification__arrow">
</div>
</div>
<div class="notification__content">
Some notification
</div>
</div>
</div>
Is it possible to solve that problem without JS?
I think you're looking for this:
body {
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";
}
.wrap {
text-align: right;
}
.button {
border: 0;
padding: 1rem 1.5rem;
background-color: darkslateblue;
text-align: center;
min-width: 180px;
max-width: 100%;
width: auto;
display: inline-block;
color: #FFFFFF;
font-size: 1rem;
position: relative;
}
.notification {
background-color: gold;
padding: 1.5rem;
text-align: left;
position: absolute;
top: 100%;
left: 50%;
transform: translateX(-50%);
}
.notification::after {
border-bottom: 5px solid gold;
content: '';
display: block;
height: 0;
width: 0;
position: absolute;
top: -5px;
left: 50%;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
}
<div class="ticket">
<div class="ticket__content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
<div class="align-right">
<button class="button">Do it
<div class="notification">Some Notification</div>
</button>
</div>
</div>
</div>
The trick is to put the notification as a child element of the button and position it absolutely, at the bottom center. Then adding an arrow in de middle of that notification will always put that arrow in the middle of the button.

How to make a vertical bar that follows its user in a specific area?

I do have a simple box designed in HTML and CSS. If you want to see it, just use this fiddle.
Now I want to design a bar at the right side of the box, overlaying ~10-20px of the right side/image.
It should be a bit transparent, slighty different-colored and so on. Nothing hard.
But I also wish that this bar has a little image or text (e.g. "floating text", 90° flipped), that follows the user when he scrolls up and down. BUT not further than the maximum top or bottom line of the box.
How can I design a bar that follows the user in a specific area?
Do clearify it, I just used my ultimate paint skills to paint what I'm looking for:
The orange area would be the area where my box may float. No more than this, not less than this. The red thingy should be the box.
As jsfiddle.net can only be linked with providing code, I'll do this:
HTML:
<section class="mbox">
<h2>Business PC</h2>
<div class="mbox_content">
<h3>Lorem ipsum dolor sit amet, consetetur sadipscing elitr!
<span>sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam</span>
</h3>
<p>Erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
</div>
<hr>
<img src="http://www.club-3d.com/tl_files/club3d/uploads/en/content/Accesories/CAC-1052/cac-1052_use_01.png" alt="Testbild">
</section>
CSS:
#import url(http://fonts.googleapis.com/css?family=Open+Sans);
body, html {
height:100%;
padding:0;
margin:0;
background:#5cafff;
font-family:'Open Sans', sans-serif;
}
.mbox {
z-index: 1;
margin: 2em;
position:relative;
background: #ff1a00;
background: linear-gradient(to right, #ffffff 33%, #ff1a00 100%);
border: 1px solid #fff;
height:600px;
clear:both;
}
.mbox * {
padding:0;
margin:0;
}
.mbox_content {
z-index: 2;
float:left;
padding: 20px;
background: #ffffff;
width:60%;
height:560px;
overflow: hidden;
overflow-y: hidden;
}
.mbox img {
z-index:-1;
position:absolute;
right:0;
max-height:200px;
}
.mbox hr {
z-index: 2;
float:left;
width: 0;
height: 0;
border-style: solid;
margin-top: 30px;
border-width: 15px 0 15px 20px;
border-color: transparent transparent transparent #ffffff;
}
.mbox h2 {
text-transform: uppercase;
font-weight:normal;
font-size:1em;
top:-0.7em;
left: 0.5em;
position:absolute;
color:#fff;
background:#ff1a00;
padding:0 1em;
border:1px solid #fff;
border-radius:1em;
}
.mbox_content h3 {
font-size:1.4em;
color:#666;
border-left:2px solid #ccc;
padding-left: 1em;
margin-bottom:0.5em;
}
.mbox_content h3 span {
margin-top:0.5em;
display:block;
font-size:0.7em;
text-transform: uppercase;
font-weight:normal;
}
FIDDLE
I tryed to do as mutch as possible in css and html but the scrolling part does need some javascript.
The only thing i did not do is make the bar stop at the end of the container. This would recquire even more javascript.
So what i did was make a extra div. positioned it position:absolute and right:0 so it would allways be on the outer most right of the container.
Added a overflow:hidden so our close button would not go over its container.
Added a container <div class="rotate"> for the rotating of the text.
added the text close.
Added some javascript that addes the current scroll amout to the close button.
var i = document.querySelector(".stickbar .close");
var doc = document.documentElement;
window.onscroll = function () {
var top = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);
i.style.right = (20 + top) + "px";
}
#import url(http://fonts.googleapis.com/css?family=Open+Sans);
body, html {
height: 500vh;
padding:0;
margin:0;
background:#5cafff;
font-family:'Open Sans', sans-serif;
}
.mbox {
z-index: 1;
margin: 2em;
position:relative;
background: #ff1a00;
background: linear-gradient(to right, #ffffff 33%, #ff1a00 100%);
border: 1px solid #fff;
height:600px;
clear:both;
}
.mbox * {
padding:0;
margin:0;
}
.mbox_content {
z-index: 2;
float:left;
padding: 20px;
background: #ffffff;
width:60%;
height:560px;
overflow: hidden;
overflow-y: hidden;
}
.mbox img {
z-index:-1;
position:absolute;
right:0;
max-height:200px;
}
.mbox hr {
z-index: 2;
float:left;
width: 0;
height: 0;
border-style: solid;
margin-top: 30px;
border-width: 15px 0 15px 20px;
border-color: transparent transparent transparent #ffffff;
}
.mbox h2 {
text-transform: uppercase;
font-weight:normal;
font-size:1em;
top:-0.7em;
left: 0.5em;
position:absolute;
color:#fff;
background:#ff1a00;
padding:0 1em;
border:1px solid #fff;
border-radius:1em;
}
.mbox_content h3 {
font-size:1.4em;
color:#666;
border-left:2px solid #ccc;
padding-left: 1em;
margin-bottom:0.5em;
}
.mbox_content h3 span {
margin-top:0.5em;
display:block;
font-size:0.7em;
text-transform: uppercase;
font-weight:normal;
}
.stickbar {
position: absolute;
display: block;
width: 20px;
height: 600px;
right: 0;
top: 0;
background-color: Orange;
overflow: hidden;
}
.stickbar .rotate {
position: absolute;
right: 0;
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
-ms-transform: rotate(-90deg);
-o-transform: rotate(-90deg);
transform: rotate(-90deg);
-webkit-transform-origin: 50% 50%;
-moz-transform-origin: 50% 50%;
-ms-transform-origin: 50% 50%;
-o-transform-origin: 50% 50%;
transform-origin: 50% 50%;
}
.stickbar .close {
position: relative;
display: block;
width: 50px;
right: 20px;
bottom: -0.7em;
background-color: white;
cursor: pointer;
}
<section class="mbox">
<h2>Business PC</h2>
<div class="mbox_content">
<h3>Lorem ipsum dolor sit amet, consetetur sadipscing elitr!
<span>sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam</span>
</h3>
<p>Erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
</div>
<hr/>
<img src="http://www.club-3d.com/tl_files/club3d/uploads/en/content/Accesories/CAC-1052/cac-1052_use_01.png" alt="Testbild" />
<div class="stickbar">
<div class="rotate"> <span class="close">Close</span>
</div>
</div>
</section>
I think this is what you want:
<div class="a-box"></div>
.a-box {
width:180px;
height:200px;
position:fixed;
background: rgba(255,255,255,0.5);
right:60px;
top:40%;
padding: 20px;
}
JSFIDDLE
Probably the best solution for you:
JSFIDDLE #1
var fixed = document.getElementById('fixed-div');
var fixedHeight = fixed.parentNode.scrollHeight - fixed.offsetHeight;
fixed.parentNode.parentNode.onscroll = function() {
fixed.style.top = Math.min(this.scrollTop, fixedHeight) + "px";
}
#wrapper {
width: 100%;
height: 1500px;
border: 1px solid red;
padding-top: 380px;
}
#wrapper .scrollbar-container {
border: 1px solid green;
width: 100%;
height: 500px;
overflow: scroll;
}
#wrapper .scrollable {
height: 1500px;
width: 100%;
border: 1px solid yellow;
position: relative;
}
#wrapper .fixed {
right: 10px;
width: 50px;
height: 500px;
background: black;
overflow: none;
position: absolute;
color: white;
}
<div id="wrapper">
<div class="scrollbar-container">
<div class="scrollable">
<div id="fixed-div" class="fixed">
close (fixed)
</div>
Text inside Div that moves with scroll.
</div>
</div>
</div>
or you could also try something like this JSFIDDLE.
.outer {
width: 200px;
height: 600px;
background-color: gray;
margin: 0 auto;
}
.inner {
width: 50px;
border: 1px solid white;
position: fixed;
margin-left: 150px
}
<div class="outer">
<div class="inner">close
</div>
</div>