Wanting to overlay a div over an image using flexbox - css

I have a series of scaling triangles that I've arranged using flexbox, they get bigger and smaller depending on how the window is stretched. I want to have these overlay the bottom of an image to give it a sort of ripped paper or mountain peak sort of effect. The image that they will overlay scales to fit the window and the triangles must follow the image, scaling up and down with the window.
I'm having a lot of difficulty coming up with a solution to this problem and could use some help.
This is how I want the triangles and image to look and relate to one another, the triangles being black in this screenshot and the image being grey.
http://i.imgur.com/KkXq9pc.png
Here's a jsfiddle link to the project: http://jsfiddle.net/wD2r2/
CSS:
.triangle-up {
margin: 0 auto;
width: 50%;
height: 0;
padding-left:50%;
padding-bottom: 50%;
overflow: hidden;
}
.triangle-up:after {
content: "";
display: block;
width: 0;
height: 0;
margin-left:-9999px;
border-left: 9999px solid transparent;
border-right: 9999px solid transparent;
border-bottom: 9999px solid #000000;
}
.triangle-container {
display: flex;
}
.overlay {
top: -100px;
left:0px;
right:0px;
z-index: 1;
position: relative;
margin-top: 10px;
}
HTML:
<div>
<div>
<img style="width:100%;" src="images/treeline.jpg" />
</div>
<article class="overlay">
<div class="triangle-container">
<article>
<div class="triangle-up" />
</article>
<article>
<div class="triangle-up" />
</article>
<article>
<div class="triangle-up" />
</article>
<article>
<div class="triangle-up" />
</article>
<article>
<div class="triangle-up" />
</article>
<article>
<div class="triangle-up" />
</article>
</div>
</article>
</div>
I want to avoid the effect of the triangles rising up or down or shifting along the sides of the window in relation to the image. I've been trying to get it to stay constantly running along the bottom and scaling appropriately but with no luck.
Thanks a bunch.

There is a bit to this, so I'll explain everything that I did in order.
1. Brown/Yellow bars' container
In order to get those two brown and yellow bars at the bottom, you need a container for them. Since there is black around them, I simply created a 100% x 40px div with a black background:
.bottom
{
background: black;
width: 100%;
height: 40px;
}
2. Create the brown and yellow bars
Since the brown and yellow bars are on the same line and are blocks, I created two inline-block elements with width 43% and one-side margins of 7%, as well as setting the proper background-color:
.brown, .yellow
{
display: inline-block;
width: 43%;
height: 20px;
margin: 20px 0 0 0;
}
.brown
{
background: brown;
margin-left: 7%;
}
.yellow
{
background: yellow;
margin-right: 7%;
}
3. Image border
Since you have that grey border around the image, I set the image box-sizing mode to border-box so that the image size would not change and I added 20px of padding to all of the sides. Then I set the background to grey to make the space around the image the right color:
img
{
padding: 20px;
box-sizing: border-box;
-moz-box-sizing: border-box;
background: #888;
}
JSFiddle

I made this flexbox text overlaying on an image
.wrapper {
display: flex;
flex-flow: row wrap;
font-weight: bold;
text-align: center;
}
.wrapper > * {
padding: 10px;
flex: 1 100%;
}
.header {
background: tomato;
}
.footer {
background: lightgreen;
}
.main {
text-align: left;
background: url(https://raw.githubusercontent.com/212mr/608m02SamsungS8/master/image/1482233503439.jpg) no-repeat 0 0;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
}
.aside-1 {
background: gold;
}
.aside-2 {
background: hotpink;
}
#media all and (min-width: 600px) {
.aside { flex: 1 auto; }
}
#media all and (min-width: 800px) {
.main { flex: 3 0px; }
.aside-1 { order: 1; }
.main { order: 2; }
.aside-2 { order: 3; }
.footer { order: 4; }
}
body {
padding: 2em;
}
<div class="wrapper">
<header class="header">Header</header>
<article class="main">
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
</article>
<aside class="aside aside-1">Aside 1</aside>
<aside class="aside aside-2">Aside 2</aside>
<footer class="footer">Footer</footer>
</div>
First, you need to make your flexbox.
Second, put the image (as a background image) into your flexbox child.
Third, put your text to overlay on the image.

Related

How to set the size of the bootstrap text and card size

I have the card implemented using bootstrap. But my card size is varying according to the quantity of the text characters.
Details link is varying as well, and when i shrink the browser, it overlap my card text.
How to fix the size of the card text (class: card-text) to avoid the overlap and to avoid different cards size?
<div class="card">
<div class="img-dimension">
<img class="card-img-top" src="img.jpg">
</div>
<div class="card-body">
<h5 class="card-title">title</h5>
<div class="card-text">
<p>
My long card-text....Phasellus a est. Nam eget dui.
Pellentesque ut neque. Nunc sed turpis. Donec mi odio,
faucibus at, scelerisque quis, convallis in, nisi.
</p>
</div>
<div class="text-left pb-2 pt-2">
Details...
</div>
</div>
</div>
My CSS code. I didn't change this bootstrap CSS Code:
.card {
position: relative;
display: flex;
flex-direction: column;
min-width: 0;
word-wrap: break-word;
background-color: #fff;
background-clip: border-box;
border: 1px solid rgba(0,0,0,.125);
border-radius: .25rem;
}
.card-body {
flex: 1 1 auto;
padding: 1.25rem;
}
.card-title {
margin-bottom: .75rem;
}
.card-img-top {
width: 100%;
border-top-left-radius: calc(.25rem - 1px);
border-top-right-radius: calc(.25rem - 1px);
}
.text-left {
text-align: left!important;
}
.pb-2, .py-2 {
padding-bottom: .5rem!important;
}
.pt-2, .py-2 {
padding-top: .5rem!important;
}
Text-Overflow
This might help you, you can use it to control the overflow of your text according to your needs.
For example:
.card-text{
font-size:19px;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
If you wish to make your website responsive you should try using #media rule
in which you can specify the exact changes according to the resolution.
Have a look at this link for #media rule.
For example: -->Hide an element when the browser's width is 600px wide or less:
#media screen and (max-width: 600px) {
div.example {
display: none;
}
}
I hope this can help you.

Center block in div with absolute position

I have a div with 2 blocks:
One with informations
Another absolute on the bottom (with variant height)
Problem: I would like to center image on the middle of the div, excluding absolute block.
What I have
What I want
My actual code:
https://jsfiddle.net/ph4kfuy9/5/
.block {
height: 400px;
background-color: #EEE;
margin: 20px 50px;
position: relative;
}
.text {
padding: 20px;
background-color: #CCC;
width: auto;
text-align: center;
width: 50%;
margin: 0 auto;
}
.absolute {
padding: 20px;
background-color: #555;
color: #FFF;
position: absolute;
bottom: 0;
width: 100%;
box-sizing: border-box;
}
<div class="block">
<div class="text">
<p>My text</p>
<div>Lorem Ipsum</div>
<p>Another text</p>
</div>
<div class="absolute">
My absolute block
<p>
Quam ob rem cave Catoni anteponas ne istum quidem ipsum, quem Apollo, ut ais, sapientissimum iudicavit; huius enim facta, illius dicta laudantur. De me autem, ut iam cum utroque vestrum loquar, sic habetote.
</p>
</div>
</div>
Thank
I would use flex for this
.block {
height: 400px;
background-color: #EEE;
margin: 20px 50px;
display:flex; /* make this flex */
flex-direction:column; /* line up chld elements in a column */
}
.text {
padding: 20px;
background-color: #CCC;
width: auto;
width: 50%;
margin: 0 auto;
flex-grow:1; /* make this take up remaining space that footer doesn't */
display:flex; /* make this flex */
flex-direction:column; /* line up chld elements in a column */
justify-content:center; /* vertical centre */
align-items:center; /* horizontal centre */
}
.footer { /* no need to be absolute */
padding: 20px;
background-color: #555;
color: #FFF;
width: 100%;
box-sizing: border-box;
}
<div class="block">
<div class="text">
<p>My text</p>
<div>Lorem Ipsum</div>
<p>Another text</p>
</div>
<div class="footer">
My footer block
<p>
Quam ob rem cave Catoni anteponas ne istum quidem ipsum, quem Apollo, ut ais, sapientissimum iudicavit; huius enim facta, illius dicta laudantur. De me autem, ut iam cum utroque vestrum loquar, sic habetote.
</p>
</div>
</div>

CSS display: table-cell width 100% overflow-x expand

I have this two column layout, made with display: table and display: table-cell, and I want to put in the second column a div with horizontal scroll, but the table expands itself and the scroll goes to the entire page rather then the div.
HTML
<div class="wrapper">
<div id="one"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque convallis finibus metus. Suspendisse commodo rutrum sapien, eu faucibus metus. Nunc elementum augue eu aliquet condimentum.
</div>
<div id="two">
<div id="horizontal">
<img src="https://dl.dropbox.com/u/1218282/slideshow/1.jpg" />
<img src="https://dl.dropbox.com/u/1218282/slideshow/2.jpg" />
<img src="https://dl.dropbox.com/u/1218282/slideshow/3.jpg" />
<img src="https://dl.dropbox.com/u/1218282/slideshow/4.jpg" />
</div>
</div>
</div>
CSS
.wrapper {
display: table;
table-layout: fixed;
}
#one {
display: table-cell;
background-color: gray;
width: 200px;
}
#two {
display: table-cell;
width: 100%;
}
#horizontal {
width: 100%;
overflow-x: scroll;
white-space: nowrap;
}
#horizontal img {
max-width: 200px;
}
Here is the jsfiddle:
http://jsfiddle.net/cUCvY/2597/
In this example I'd like to have the horizontal scroll active on the div with the images inside and not on the page.
Hope i understood correctly:
.wrapper {
display: table;
table-layout: fixed;
width:100%
}
#one {
display: table-cell;
background-color: gray;
width: 200px;
}
#two {
}
#horizontal {
overflow-x: scroll;
white-space: nowrap;
}
#horizontal img {
max-width: 200px;
}
}
#media screen and (max-width: 400px) {
#one {
float: none;
margin-right:0;
width:auto;
border:0;
border-bottom:2px solid #000;
}
}
http://jsfiddle.net/cUCvY/2600/

bottom align 3 responsive divs

I am a keen follower of this website and this is the first time I couldn't find what I was looking for. I hope someone can help me soon.
I have 3 divs inside a responsive container div. the middle div need to be vertically aligned to the bottom. How do I achieve that? Please help
CSS:
/* COLUMN LAYOUT GRID CSS */
/* SECTIONS */
.section {
clear: both;
padding: 0px;
margin: 0px;
}
.section img {
width: 100%;
}
/* COLUMN SETUP */
.col {
display: block;
float:left;
margin: 0 0 0 0;
}
#press-grid .col {
margin: 1% 0 1% 1.5%;
}
.col:first-child { margin-left: 0; }
/* GROUPING */
.group:before,
.group:after {
content:"";
display:table;
}
.group:after {
clear:both;
}
.group {
zoom:1; /* For IE 6/7 */
}
/* END OF GENERAL CSS */
/* GRID OF TWO */
#featured-slider {
}
#featured-right {
padding: 20px;
}
/* GRID OF THREE */
.span_3_of_3 {
width: 100%;
}
.span_2_of_3 {
width: 66.66%;
}
.span_1_of_3 {
width: 33.33%;
}
#press-grid .span_1_of_3 {
width: 31%;
background-color: white;
height: 500px;
}
/* GO FULL WIDTH AT LESS THAN 480 PIXELS */
#media only screen and (max-width: 798px) {
.col {
margin: 1% 0 1% 0%;
}
}
#media only screen and (max-width: 798px) {
.span_1_of_3 {
width: 100%;
}
.span_2_of_3 {
width: 100%;
}
.span_3_of_3 {
width: 100%;
}
.featured-slider {
width: 100%;
}
#featured-right {
height: 150px;
}
}
/* END COLUMN LAYOUT GRID CSS */
HTML:
<div class="content-section" id="cabin-mockup">
<div class="container">
<div class="row">
<div class="section group">
<div class="col span_1_of_3 text-center" id="home-mockup-left">
<p> </p>
<p>
<i class="fa fa-paper-plane-o"></i>
</p>
<h3>Cabin Mockup</h3>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec.</p>
<img src="/template/images/mockup2.jpg" alt="Aircraft Cabin Mockup" />
</div>
<div class="col span_2_of_3 text-center" id="home-mockup-right">
<img src="/template/images/mockup.jpg" alt="Aircraft Cabin Mockup" />
</div>
</div>
</div>
</div>
</div>
Try changing col to this:
.col {
display: table-cell;
vertical-align:bottom;
margin: 0 0 0 0;
}

center 3 divs in footer with dynamic with?

i got a tricky situation here. im trying to center 3 divs inside my footer and they need to have dynamic width, like min-width.
[cotainer [first] [second] [third] /container]
my setup is this
<footer>
<div id="container">
<div id="first"></div>
<div id="second"></div>
<div id="third"></div>
</div>
</footer>
footer #container { width: 800px; margin: 0 auto; }
#container #first,#container #second,#container #third
{
float: left;
min-width: 200px;
height: 25px;
background: /* image url */
padding: 4px;
margin: 0 20px 0 0;
}
#container #third { margin-right: 0; }
You should use display: table; and table-cell.
#container {
display:table;
}
#first, #second, #third {
display: table-cell;
width: 200px;
height: 40px;
border: 1px dashed #000;
}
Demo available here.
set container to display as:table and set it's margin to 0 auto.
#container {
display:table;
margn:0 auto;
whitespace: nowrap;
}
#first, #second, #third {
min-width: 200px;
float:left
...
}
Demo: http://jsfiddle.net/AZ4yT/1/
Edit: It gets left aligned in IE. so you might wanna use a workaround for that
What about using display: inline-block? You can see a jsFiddle of it here:
http://jsfiddle.net/S7bKT/1/
HTML
<div id="container">
<div id="first">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Aliquam scelerisque euismod auctor. Sed pulvinar nulla eu
lorem iaculis ultrices. Mauris
</div>
<div id="second">Lorem ipsum dolor sit amet</div>
<div id="third">Sed pulvinar nulla eu lorem iaculis ultrices</div>
</div>
CSS
#container {
width: 500px;
background: #dedede;
margin: 0 auto;
text-align: center;
}
#first, #second, #third {
display: inline-block;
min-width: 50px;
max-width: 120px;
min-height: 100px;
zoom: 1; /* Fix for IE */
_display: inline; /* Hack for IE */
margin-right: 20px;
vertical-align: top;
}
#first {
background: #f00;
}
#second {
background: #0f0;
}
#third {
background: #00f;
}
#container div:last-child {
margin-right: 0;
}

Resources