Positioning relative and absolute boxes inside the Bootstrap 3 .well - css

I am working on this demo. Why am I not able to position the #box-wrap and its child element (#box-1, #box-2, #box-3) properly inside the Bootstrap 3 .well?
#box-wrap {
position: relative;
width:100%;
background-color:#fff;
}
#box-1 {
position: absolute;
width:100%;
height:120px;
top: 0;
left: 0;
background:khaki;
}
#box-2 {
position: absolute;
top: 5px;
left: 5px;
}
#box-3 {
position: absolute;
top: 44px;
left: 5px;
}
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="row">
<div class="container">
<div class="well">
<div id="box-wrap">
<div id="box-1"></div>
<div id="box-2"><button class="btn btn-success">></button></div>
<div id="box-3"><button class="btn btn-success"><</button></div>
</div>
</div>
</div>
</div>

If I understood your layout correctly, here's my solution.
I removed position: absolute; and changed the box-2, box-3 from divs to spans (since divs have a display:block by default.
HTML
<div class="row">
<div class="container">
<div class="well">
<div id="box-wrap">
<div id="box-1"></div>
<span id="box-3"><button class="btn btn-success"><</button></span>
<span id="box-2"><button class="btn btn-success">></button></span>
</div>
</div>
</div>
</div>
CSS
#box-wrap {
position: relative;
width:100%;
}
#box-1 {
width:100%;
height:120px;
top: 0;
left: 0;
background:khaki;
}
#box-2,
#box-3 {
background:khaki;
}
DEMO
UPDATE (Thx #ckuijjer)
Thanks to #ckuijjer for the comment. Here's his simpler version that accomplishes the same thing:
Simplified HTML
<div class="container">
<div class="row">
<div class="well">
<div id="box-1"></div>
<button class="btn btn-success"><</button>
<button class="btn btn-success">></button>
</div>
</div>
</div>
Simplified CSS
#box-1 {
height:120px;
background:khaki;
}
Simplified DEMO

Just change your css as
#box-2 {
position: absolute;
top: 45px;
float:right;
right: 5px;
}
Working Demo

Using
#box-1{
position:relative;
}
will solve the issue.
I think as none of the parent element of box-1 has fixed height this is somehow affecting using position:absolute for a child div.

Related

How to hover one containers over another in Bootstrap3

I am trying to implement the following design in bootstrap3.
Does anyone know how to hover the container2 over the container1?
I can use the position:absolute way but I think there must be a better way to do it.
Thanks.
Try this:
.container-1 {
position: relative;
z-index: 0;
}
.container-2 {
position: relative;
z-index: 1;
top: -50px;
}
HTML:
<div class="container container-1">...</div>
<div class="container container-2">...</div>
You can use margin-top on the "container 2" to get this effect
.container-2 {
margin-top: -200px;
}
http://jsfiddle.net/mwo8jdeL/
http://i.stack.imgur.com/rxKfW.png
Index.html
[![<div class="container-fluid">
<div class="row one">
<div class="col-md-12">
</div>
</div>
<div class="row two">
<div class="col-md-12">
</div>
</div>
</div>][1]][1]
CSS File
.one{
background-color: red;
height: 400px;
}
.two{
background-color: green;
height: 400px;
margin-top: -100px;
margin-left: 15%;
margin-right: 15%;
}

Resizable containers at the same level

<div class="row container-row">
<div class="col-md-8 col-xs-12 no-padding-column">
<div class="video-container">
<img class="video-image" src="image.jpg">
<a href="#" class="js-play-video">
<img class="play-image" src="play.png">
</a>
</div>
</div>
<div class="col-md-4 col-xs-12 no-padding-column">
<div class="text-content">
<h1>Superious Quality</h1>
<p>sometext</p>
</div>
</div>
</div>
Below is my Style
.panel-container {
color: #fff;
height: auto;
position: relative;
margin: 0px auto;
}
.panel-container .container-row {
margin: 5%;
}
.panel-container .container-row .no-padding-column {
padding-right: 0px;
padding-left: 0px;
}
.panel-container .video-container {
display: block;
position: relative;
}
.panel-container .video-container .video-image {
width: 100%;
}
.panel-container .play-image {
position: absolute;
width: 13%;
height: auto;
top: 50%;
left: 57%;
margin-left: -12%;
margin-top: -6%;
}
.panel-container .text-content {
padding-left: 15px;
padding-right: 15px;
float: left;
height: 381px;
background-color: rgba(0, 0, 0, 0.6);
color: #fff;
}
#media (max-width: 30em) {
.panel-container .text-content {
height: auto;
}
}
.panel-container .text-content h1 {
color: #fff;
}
I want the text-content has the same height as the video-container. Please note that the height of video-container is not fixed and defined by the size of image and it's resizing when the browser resize. How can I make the text-content resizable to always be aligned (height) with the video-container?
One solution would be to make the .container-row and the .text-content the same background-color. The code:
.panel-container {
color: #fff;
margin: 0px auto;
}
.panel-container .container-row {
background: #666666;
margin: 5%;
}
.panel-container .container-row .no-padding-column {
padding-right: 0px;
padding-left: 0px;
}
.panel-container .video-container .video-image {
width: 100%;
}
.panel-container .play-image {
position: absolute;
width: 13%;
height: auto;
top: 50%;
left: 57%;
margin-left: -12%;
margin-top: -6%;
}
.panel-container .text-content {
padding: 0 15px;
float: left;
color: #fff;
}
.panel-container .text-content h1 {
color: #fff;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid panel-container">
<div class="row container-row">
<div class="col-xs-8 no-padding-column">
<div class="video-container">
<img class="video-image" src="http://www.keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/image1.jpg" />
<a href="#" class="js-play-video">
<img class="play-image" src="http://uxrepo.com/static/icon-sets/iconic/svg/play-circle2.svg" />
</a>
</div>
</div>
<div class="col-xs-4 no-padding-column">
<div class="text-content">
<h1>Superious Quality</h1>
<p>sometext</p>
</div>
</div>
</div>
</div>
I know it is not the right way to do it and that it doesn't answer the question, but it works on behaviour.
I actually used the Reflex on a link but it's not used extensively. I'm not sure if it's a right thing to use to get the site to production. Please let me know if there is any better option.
To adjust both divs at the same height, all I did was adding
float: left;
to the css class .no-padding-column
.panel-container .container-row .no-padding-column {
padding-right: 0px;
padding-left: 0px;
float: left;
}
I tried to reproduce your situation in a fiddle. Notice that I removed the .panel-container class, since it's not in your code. I am not sure where this class is, it might cause problems as well, let me know if my Fiddle works as exspected. And if there's still a problem, could you add your .panel-container class as well? (And maybe images from the internet and not local ones? That would make it much easier for us)
For those who want to adjust the height of the second div, depending on the change of the first div:
For this you could use the JS framework "attrchange". Add the JS file to your page and use the following code.
$(".video-container").attrchange({
trackValues: true, // set to true so that the event object is updated with old & new values
callback: function(event) {
if(event.attributeName == "height") { // which attribute you want to watch for changes
$(".text-content").css('height', event.newValue);
}
}
});
I post the solution I found you might be interested as well.
Here is codepen link!
<div class="table-wrapper">
<div class="table-row">
<div class="table-column short-column">
<div class="content-container">
<p>Short Column</p>
</div>
<div class="button-row">
<button>Click Me</button>
</div>
</div>
<div class="table-column medium-column">
<div class="content-container">
<p>Medium Column</p>
<p>Medium Column</p>
<p>Medium Column</p>
</div>
<div class="button-row">
<button>Click Me</button>
</div>
</div>
<div class="table-column long-column">
<div class="content-container">
<p>Long Column</p>
<p>Long Column</p>
<p>Long Column</p>
<p>Long Column</p>
<p>Long Column</p>
<p>Long Column</p>
<p>Long Column</p>
</div>
<div class="button-row">
<button>Click Me</button>
</div>
</div>

Inline-block display of divs with position relative

I have a series of images each with his own overlay. How can I have them aligned like inline-blocks? I tried adding adding display: inline-block;to .image-wrapper but the images are always all positioned in the top left corner of the div.container (Here is a jsfiddle).
Here are the html and css
.container {
position: relative;
}
.image-wrapper {
position: relative;
display: inline-block;
}
.tweetty {
position: absolute;
overflow: auto;
top: 0;
left: 0;
}
.image-vest {
position: absolute;
top: 0;
left: 0;
background-color: #00f;
width: 220px;
height: 300px;
opacity: 0.4;
color: #fff;
}
<div class="container">
<div class="image-wrapper">
<div class="tweetty">
<img src="http://www.picgifs.com/clip-art/cartoons/tweety/clip-art-tweety-191375.jpg" />
</div>
<div class="image-vest">Tweetty-one</div>
</div>
<div class="image-wrapper">
<div class="tweetty">
<img src="http://www.picgifs.com/clip-art/cartoons/tweety/clip-art-tweety-191375.jpg" />
</div>
<div class="image-vest">Tweetty-two</div>
</div>
</div>
EDIT:
revised css with dfsq suggestion to remove position:absolute; from .tweetty.
Quoting dfsq comment:
"Elements with position absolute don't contribute to the width and height of their parent container. So the image-wrapper divs just collapse as if they were empty if all children have position:absolute; "
.container {
position: relative;
}
.image-wrapper {
position: relative;
display: inline-block;
}
.tweetty {
overflow: auto;
top: 0;
left: 0;
}
.image-vest {
position: absolute;
top: 0;
left: 0;
background-color: #00f;
width: 220px;
height: 300px;
opacity: 0.4;
color: #fff;
}
<div class="container">
<div class="image-wrapper">
<div class="tweetty">
<img src="http://www.picgifs.com/clip-art/cartoons/tweety/clip-art-tweety-191375.jpg" />
</div>
<div class="image-vest">Tweetty-one</div>
</div>
<div class="image-wrapper">
<div class="tweetty">
<img src="http://www.picgifs.com/clip-art/cartoons/tweety/clip-art-tweety-191375.jpg" />
</div>
<div class="image-vest">Tweetty-two</div>
</div>
<div class="image-wrapper">
<div class="tweetty">
<img src="http://www.picgifs.com/clip-art/cartoons/tweety/clip-art-tweety-191375.jpg" />
</div>
<div class="image-vest">Tweetty-three</div>
</div>
</div>
I fiddled with the fiddle, and this seems to work. removed all the positioning from all but the vest. Used the inline-block display mode. Set top to -300px, and also the bottom-margin, otherwise you get a gap below the images.
.container {
/* position:relative;*/
}
.image-wrapper {
/* position: relative;*/
display: inline-block;
}
.tweetty {
/* position:absolute;
overflow:auto;
top:0;
left:0;*/
}
.image-vest {
position:relative;
top:-300px;
margin-bottom: -300px;
left:0;
background-color:#00f;
width:220px;
height:300px;
opacity:0.4;
color:#fff;
}
<div class="container">
<div class="image-wrapper">
<div class="tweetty">
<img src="http://www.picgifs.com/clip-art/cartoons/tweety/clip-art-tweety-191375.jpg" />
</div>
<div class="image-vest">Tweetty-one</div>
</div>
<div class="image-wrapper">
<div class="tweetty">
<img src="http://www.picgifs.com/clip-art/cartoons/tweety/clip-art-tweety-191375.jpg" />
</div>
<div class="image-vest">Tweetty-two</div>
</div>
<div class="image-wrapper">
<div class="tweetty">
<img src="http://www.picgifs.com/clip-art/cartoons/tweety/clip-art-tweety-191375.jpg" />
</div>
<div class="image-vest">Tweetty-three</div>
</div>
</div>
(here's the JSFiddle version)

overlapping elements in bootstrap

How to overlap a text with an image (text in front of the image) and center them while keeping both responsive (without using position fixed or background-image) in Bootstrap?
<pre>
<!--jumbotron-->
<div class="jumbotron">
<div class="container">
<div class="brand">
<h1 id="success">Alexandra</h1>
<img class="img-responsive" src="lavrente.jpg" width="300" height="52" >
</div>
</div>
</div>
</pre>
<pre>#success {
color: #000;
font-family: "Chopin Script";
position:relative;
z-index: 1;
}
.img-responsive {
position:relative;
z-index: 0;}
</pre>
Use position: absolute on the text.
h1{
position: absolute;
}
Here is another solution with full responsive:
<div class="jumbotron">
<div class="container">
<div class="brand">
<img src="http://via.placeholder.com/350x150" alt="" class="img-responsive" width="300" height="52">
<h1 id="success">Alexandra</h1>
</div>
</div>
</div>
CSS:
.brand {
position: relative;
text-align: center;
}
#success {
position: absolute;
top: 0%;
left: 50%;
transform: translate(-50%, -50%);
}
live preview: https://codepen.io/mesapkota/pen/QryREB

Better way to absolutely position boxes to the left and right?

Is there a better way to absolutely position a bunch of boxes to the left and right like this? Perhaps using flexbox?
http://jsfiddle.net/frank_o/zpv4jbmx/
HTML:
<div class="box first">
<h1>Lipsum</h1>
</div>
<div class="box second">
<h1>Lipsum</h1>
</div>
...
CSS:
.box {
position: absolute;
background: blue;
color: white;
}
.box.first, .box.third, .box.fifth {
left: 20px;
}
.box.second, .box.fourth, .box.sixth {
right: 20px;
}
.box.first {
top: 20px;
}
.box.second {
top: 120px;
}
...
Since we are going for "better", you could use floating and CSS even/odd rules, like so:
HTML
<div class="box">
<h1>Lipsum</h1>
</div>
<div class="box">
<h1>Lipsum</h1>
</div>
<div class="box">
<h1>Lipsum</h1>
</div>
<div class="box">
<h1>Lipsum</h1>
</div>
<div class="box">
<h1>Lipsum</h1>
</div>
<!-- As many as you'd like... -->
CSS
.box {
background: blue;
color: white;
}
.box:nth-child(odd){
float: left;
clear: both;
}
.box:nth-child(even){
float: right;
clear: both;
}
The result is the same, but the implementation is much more scalable.
http://jsfiddle.net/9mcgvqLj/

Resources