Div Not Floating When Text Wraps to Second Line? - html

I ran into a floating/alignment issue and can't seem to figure it out. When I float some DIVs next to each other they all line up like they should... until the text from one of the DIVs falls to a second line.
If you look below you can see how Line 1 shows up. As you can see, ABCD sits next to the other DIVs on the same line.
On Line 2 you can see how EFGH falls to another line, even though there's plenty of space for it on the previous line.
How can I make it so the DIVs always sit next to each other regardless of how many lines of text there are?
Any help would be greatly appreciated!
SCREENSHOT
#sample-list {
margin-bottom: 35px;
float: left;
width: 400px;
background: orange;
word-wrap: break-word;
}
.sample-overview {
width: 100%;
float: left;
font-family: "open sans", "arial";
font-size: 12px;
line-height: 14px;
margin-bottom: 20px;
word-wrap: break-word;
}
.sample-name-wrap {
width: 100%;
white-space: normal;
}
.sample-name {
float: left;
}
.sample-dash {
float: left;
margin: 0 5px;
}
.sample-div {
float: left;
background: #ccc;
}
<div id="sample-list">
<div class="sample-line">
<div class="sample-overview">
<div class="sample-name-wrap">
<div class="sample-name">
Line 1: ostrum exercitationem ullam corporis
</div>
<div class="sample-dash">–</div>
<div class="sample-div">ABCD</div>
</div>
</div>
</div>
<div class="sample-line">
<div class="sample-overview">
<div class="sample-name-wrap">
<div class="sample-name">
Line 2: atis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab sdaf sfffdaf ntoowerf jdj
</div>
<div class="sample-dash">–</div>
<div class="sample-div">EFGH</div>
</div>
</div>
</div>
<div class="sample-line">
<div class="sample-overview">
<div class="sample-name-wrap">
<div class="sample-name">
Line 3: vitae dicta sunt explicabo. Nemo enim
</div>
<div class="sample-dash">–</div>
<div class="sample-div">IJKL</div>
</div>
</div>
</div>
</div>
CODEPEN
https://codepen.io/anon/pen/aEqjRo

Try the code below. I think you dont need to use floats at all. Use spans instead. They have inline display property.
.container {
max-width: 300px;
}
<div class="container">
<div>
Lorem Ipsum bla bla bla bla bla bla bla bla bla bla bla blabla bla bla
<span> - </span>
<span> ABCD </span>
</div>
<div>
Lorem Ipsum bla bla bla bla bla bla bla bla bla bla bla blabla bla bla
<span> - </span>
<span> EFG </span>
</div>
<div>
Lorem Ipsum bla bla bla bla bla bla bla bla bla bla bla blabla bla bla
<span> - </span>
<span> HIJ </span>
</div>
</div>

Using inline elements instead of floated divs fixes the issue. See https://codepen.io/anon/pen/VyQGWM?editors=1100.
<div id="sample-list">
<div class="sample-line">
<div class="sample-overview">
<div class="sample-name-wrap">
Line 1: ostrum exercitationem ullam corporis
<span class="sample-dash">
–
</span>
<span class="sample-span">
ABCD
</span>
</div>
</div>
</div>
<div class="sample-line">
<div class="sample-overview">
<div class="sample-name-wrap">
Line 2: atis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab sdaf sfffdaf ntoowerf jdj
<span class="sample-dash">
–
</span>
<span class="sample-span">
EFGH
</span>
</div>
</div>
</div>
<div class="sample-line">
<div class="sample-overview">
<div class="sample-name-wrap">
Line 3: vitae dicta sunt explicabo. Nemo enim
<span class="sample-dash">
–
</span>
<span class="sample-span">
IJKL
</span>
</div>
</div>
</div>
</div>
#sample-list {
margin-bottom: 35px;
float: left;
width: 400px;
background: orange;
word-wrap: break-word;
}
.sample-overview {
width: 100%;
float: left;
font-family: "open sans", "arial";
font-size: 12px;
line-height: 14px;
margin-bottom: 20px;
word-wrap: break-word;
}
.sample-name-wrap {
width: 100%;
white-space: normal;
}
.sample-dash {
margin: 0 5px;
}
.sample-span {
background: #ccc;
}
If you'd like to see why this is happening visit https://codepen.io/anon/pen/QaQVqP. The only change is a CSS border which illustrates why your floated div is wrapping to the next line.

Try With css Display property.
set Display: inline; to container so that DIVs inside container div sit next to each other.
Hope this helps!

Related

Flex Not Behaving as expected within Grid

I am trying to get a flex display living in a grid to behave like I want. Upon resizing the browser, the flex area refuses to drop below 2 columns no matter what I tinker with and am at a loss as to what to do. I've just taken up markup/coding and am still in the phase of layouts. I'm trying to leverage the powers of Grid and Flex together but am having minimal luck.
Here is what I have so far....please disregard and styling as this is just me tinkering.
html {
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
color: #333;
}
.container {
display: grid;
grid-template-columns: repeat(autofit, minmax(200px, 1fr));
grid-template-rows: autofit 250px 1fr autofit;
grid-template-areas:
"h h h"
"c c c"
"p p p"
"f f f";
}
.flex-container {
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: center;
margin: 0, auto;
}
.main-box {
width: 350px;
text-align: center;
justify-content: center;
margin-top: 2rem;
}
.text-wrap {
background-color: #eee;
width: 300px;
margin: auto;
}
.main-box p {
max-width: 200px;
margin: auto;
}
ul {
list-style: none;
padding: 0;
margin: 0;
}
li {
display: inline-block;
}
.green {
grid-area: h;
}
.red {
grid-area: c;
background-image: url("img/bgmain.jpg");
background-position: center;
background-size: cover;
background-repeat: no-repeat;
height: 250px;
}
.blue {
grid-area: p;
}
.yellow {
grid-area: f;
}
<!DOCTYPE html>
<html>
<head>
<title>Grid/Flex Test</title>
<link rel="stylesheet" type="text/css" href="./style.css" />
</head>
<body>
<div class="container">
<div class="green">
<ul>
<li>Home</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
</div>
<div class="red">Test</div>
<div class="blue">
<div class="flex-container">
<div class="main-box">
<img
src="https://source.unsplash.com/random/300x300/?webdesign"
alt=""
/>
<div class="text-wrap">
<h3>Project Name</h3>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Harum
error ea corporis perferendis facere exercitationem.
</p>
</div>
</div>
<div class="main-box">
<img
src="https://source.unsplash.com/random/300x300/?webdesign"
alt=""
/>
<div class="text-wrap">
<h3>Project Name</h3>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Harum
error ea corporis perferendis facere exercitationem.
</p>
</div>
</div>
<div class="main-box">
<img
src="https://source.unsplash.com/random/300x300/?webdesign"
alt=""
/>
<div class="text-wrap">
<h3>Project Name</h3>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Harum
error ea corporis perferendis facere exercitationem.
</p>
</div>
</div>
<div class="main-box">
<img
src="https://source.unsplash.com/random/300x300/?webdesign"
alt=""
/>
<div class="text-wrap">
<h3>Project Name</h3>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Harum
error ea corporis perferendis facere exercitationem.
</p>
</div>
</div>
<div class="main-box">
<img
src="https://source.unsplash.com/random/300x300/?webdesign"
alt=""
/>
<div class="text-wrap">
<h3>Project Name</h3>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Harum
error ea corporis perferendis facere exercitationem.
</p>
</div>
</div>
<div class="main-box">
<img
src="https://source.unsplash.com/random/300x300/?webdesign"
alt=""
/>
<div class="text-wrap">
<h3>Project Name</h3>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Harum
error ea corporis perferendis facere exercitationem.
</p>
</div>
</div>
</div>
</div>
<div class="yellow">
<span>Copyright © Designed by: Useless Dipshit</span>
</div>
</div>
</body>
</html>
So yeah, I'm a noob.
I forgot:
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
That solved everything for me.

How can i target a specific containers within a container to change the background color?

Hi guys!
Im new to the community as to HTML and CSS.
Im building a website that has 5 cards:
1st card has one container with an image left and a paragraph right
2nd card is divided in two containers with a paragraph left and image right
3rd card is divided in two containers with a image left and paragraph right
4th card has one container with an image left and a paragraph left and image right
5th card has one container with a centered paragraph
#home {
&-a {
.card {
&-container {
display: flex;
background: $main-color;
box-shadow: 5px 5px 10px 5px rgba(0, 0, 0, 0.3);
width: auto;
height: auto;
margin: 5rem 1rem;
padding: 0.5rem;
.text-wrapper {
width: 150%;
}
&:nth-child(4) {
background: $secondary-color;
}
&-split {
display: flex;
margin: 5rem 1rem;
height: auto;
}
&-text {
background: $secondary-color;
box-shadow: 5px 5px 10px 5px rgba(0, 0, 0, 0.3);
margin-right: 2rem;
width: 300%;
}
&-image {
background: $secondary-color;
box-shadow: 5px 5px 10px 5px rgba(0, 0, 0, 0.3);
padding: 0.5rem;
}
}
}
.image-wrapper {
background: $dark-color;
padding: 3rem;
}
.text-wrapper {
padding: 1rem;
margin: 2rem;
}
}
}
.container {
max-width: $website-width;
margin: auto;
padding: auto;
overflow: hidden;
}
.reverse {
flex-direction: row-reverse;
}
<section id="home-a">
<div class="container">
<!-- 1st Card -->
<div class="card-container my-2">
<div class="image-wrapper">
<img src="img/darts.jpg" alt="Darts" />
</div>
<div class="text-wrapper">
<h2>Darts</h2>
<h3>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Nam ab
inventore ratione architecto velit labore quae consequatur minus
rem incidunt.
</h3>
</div>
</div>
<!-- 2nd Card - Split -->
<div class="card-container-split my-2">
<div class="card-container-text">
<div class="text-wrapper">
<h2>Unsere Getränkekarte</h2>
<h3>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Nam ab
inventore ratione architecto velit labore quae consequatur minus
rem incidunt.
</h3>
</div>
</div>
<div class="card-container-image">
<div class="image-wrapper">
<img src="img/drinks.jpg" alt="Getränke" />
</div>
</div>
</div>
<!-- 3rd Card - Split Reverse -->
<div class="card-container-split my-2 reverse">
<div class="card-container-text">
<div class="text-wrapper">
<h2>Reservierung</h2>
<h3>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Nam ab
inventore ratione architecto velit labore quae consequatur minus
rem incidunt.
</h3>
</div>
</div>
<div class="card-container-image">
<div class="image-wrapper">
<img src="img/reserved.jpg" alt="Reservierung" />
</div>
</div>
</div>
<!-- 4th Card Reverse -->
<div class="card-container my-2 reverse">
<div class="image-wrapper">
<img src="img/open.jpg" alt="Öffnungsschild" />
</div>
<div class="text-wrapper">
<h2>Öffnungszeiten</h2>
<h3>
Montag: 11:00 - 23:30 Uhr
</h3>
<h3>
Dienstag: 11:00 - 23:30 Uhr
</h3>
<h3>
Mittwoch: 11:00 - 23:30 Uhr
</h3>
<h3>
Donnerstag: 11:00 - 23:30 Uhr
</h3>
<h3>
Freitag: 11:00 - 23:30 Uhr
</h3>
<h3>
Samstag: 11:00 - 23:30 Uhr
</h3>
<h3>
Sonntag: 11:00 - 23:30 Uhr
</h3>
</div>
</div>
<!-- 5th Card -->
<div class="card-container my-2">
<div class="text-wrapper">
<h2>Covid 19</h2>
<h3>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Nam ab
inventore ratione architecto velit labore quae consequatur minus
rem incidunt.
</h3>
</div>
</div>
</div>
</section>
Now i want color the background of these cards with alternating $main-color and $secondary-color. I used nth-child(4) to target the 4th card and change the background color but i cant find a way to target the 2 inner containers of the 3rd card to add margin and change the background color!
I would appreciate any help! Thanks!
https://www.w3schools.com/cssref/sel_element_element.asp
I would recommend adding an ID to each card instead of relying on these classes that they share. It might look like this:
<div class="card-container my-2" id="FirstCard"></div>
<div class="card-container my-2" id="SecondCard"></div>
And so on...
Regardless, this should work:
/*3rd Slide Div 1*/
card-container-split:nth-child(2) card-container-text{
/*your styling*/
}
/*3rd Slide Div 2*/
card-container-split:nth-child(2) card-container-image{
/*your styling*/
}
If you decide to switch to using IDs, replace card-container-split:nth-child(2) with the ID for the third slide.
For altenate styling you can use :nth-child(odd) and :nth-child(even).
To select the 2 inner containers of the third you can use something like:
.container > :nth-child(3) > * {margin: 2rem; background-color: blue}
That will select all direct childs of the third element direct child of .container

make the text take up as much space as the picture in grid with

i'm working on a school project where im supposed to do a portfolio. im trying to make a grid with pictuers and information next to that picture about stuff i have worked on. I'm trying to get the textbox to be as big as the picture. I have tried jusing flexbox and a lot of other stuff but can't get it to work. is there someone who can help me?
*{
box-sizing: border-box;
}
body{
background-color: #f4f4f4;
padding: 20px;
font-family: Arial;
}
.container {
max-width: 1600px;
margin: 0 auto;
}
.row {
margin:8px-16px;
}
.row,
.row > .column {
padding:2px 0px;
}
.column {
float:left;
width:50%;
}
.row:after {
content:"";
display:table;
clear:both;
}
.content {
background-color: white;
padding: 10px;
}
/* Responsive layout - makes the two columns stack on top of each other instead of next to each other */
#media screen and (max-width: 600px) {
.column {
width:100%;
}
}
<div class="container">
<div class="row">
<div class="column">
<div class="content">
<h3>Hemsida 1</h3>
<p>Lorem ipsum.</p>
</div>
</div>
<div class="column">
<div class="content">
<img src="atleta1.jpg" style="width:100%">
</div>
</div>
</div>
<div class="row">
<div class="column">
<div class="content">
<img src="atleta1.jpg" style="width:100%">´
</div>
</div>
<div class="column">
<div class="content">
<h3>Hemsida 2</h3>
<p>Lorem ipsum.</p>
</div>
</div>
</div>
<div class="row">
<div class="column">
<div class="content">
<h3>Hemsida 2</h3>
<p>Lorem ipsum.</p>
</div>
</div>
<div class="column">
<div class="content">
<img src="atleta1.jpg" style="width:100%">
</div>
</div>
</div>
</div>
You have complicated the layout very much. How do you like this layout option?
Each line is divided into two parts of 50%.
A small bonus: with small screens, due to the Flexbox property order, the description block is located above the picture.
P.S. Of course, this is not the final option. You can continue to improve it
Result
* {
box-sizing: border-box;
}
body {
background-color: #f4f4f4;
padding: 20px;
font-family: Arial;
}
.container {
max-width: 1600px;
margin: 0 auto;
padding: 0;
list-style: none;
}
.item {
display: flex;
justify-content: space-between;
margin-bottom: 20px;
;
padding: 10px;
background-color: white;
}
.item__desc {
flex-basis: 50%;
}
.item__pic {
flex-basis: 50%;
}
.item_img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
}
/* Responsive layout - makes the two columns stack on top of each other instead of next to each other */
#media screen and (max-width: 600px) {
.item {
flex-direction: column;
width: 100%;
}
.item__desc {
order: -1;
}
}
<ul class="container">
<li class="item">
<div class="item__desc">
<h3>Hemsida 1</h3>
<p>Lorem ipsum.</p>
</div>
<div class="item__pic">
<img class="item_img" src="https://picsum.photos/536/354"></div>
</li>
<li class="item">
<div class="item__pic">
<img class="item_img" src="https://picsum.photos/536/354">
</div>
<div class="item__desc">
<h3>Hemsida 2</h3>
<p>Lorem ipsum.</p>
</div>
</li>
<li class="item">
<div class="item__desc">
<h3>Hemsida 2</h3>
<p>Lorem ipsum.</p>
</div>
<div class="item__pic">
<img class="item_img" src="https://picsum.photos/536/354"></div>
</li>
</ul>
And same code on CodePen
will be enough for homework. Edit and improve codes
*{
margin: 0;
padding: 0;
box-sizing:border-box;
}
.box{
margin-bottom:20px;
background: #3498db;
height:500px;
}
.box-left{
width:50%;
float:left;
height:500px;
padding:50px;
}
.box-left h3{
margin-bottom: 15px;
}
.box-right{
width:50%;
float:right;
height:500px;
}
.box-right img{
width:100%;
height:100%;
}
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div class="box">
<div class="box-left">
<h3>Head</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequuntur quas a velit. Aut nihil, modi nobis corporis eveniet ratione aperiam repellat maiores corrupti quidem ipsam animi officiis, fugit quasi rem!</p>
</div>
<div class="box-right">
<img src="https://i.ibb.co/S6PdtwP/69037904-2403297686584790-2753464427788369920-n.jpg" alt="">
</div>
</div>
<div class="box">
<div class="box-left">
<h3>Head</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequuntur quas a velit. Aut nihil, modi nobis corporis eveniet ratione aperiam repellat maiores corrupti quidem ipsam animi officiis, fugit quasi rem!</p>
</div>
<div class="box-right">
<img src="https://i.ibb.co/S6PdtwP/69037904-2403297686584790-2753464427788369920-n.jpg" alt="">
</div>
</div>
</body>
</html>
live demo
codepen live demo

Image and text in one row aligned and responsive

I am trying to accomplish
IMG + text in one row, like in this example
I would like the image to be responsive somehow... so when I resize the window, the image remains there, but also text with background...
Also, I need the text to be vertically aligned... any ideas?
Any help is greatly appreciated! thanks
This may help you, later you can control with media-queries and place your image or content wherever you want.
.img-text {
width: 100%;
display: table;
table-layout: fixed;
}
.photo,
.content {
display: table-cell;
vertical-align: middle;
}
.photo {
width: 40%;
}
.photo img {
max-width: 100%;
height: auto;
}
.content {
width: 60%;
padding: 15px;
}
<div class="img-txt">
<div class="photo">
<img src="http://lorempixel.com/image_output/people-q-c-640-480-6.jpg" alt="">
</div>
<div class="content">
<h1>Something</h1>
<p>Something more</p>
<p>You should have tried yourself first, then asked with your code as example</p>
</div>
</div>
It would be really good if you had posted some of your code. I have already done a similar example, which I would like to share. You need to use positioning for this case. This is a case of fixed-fluid:
+-------+-----------+
| FIXED | FLUUUUUID |
+-------+-----------+
Or
+-------+-----------+
| FIXED | FLUUUUUID |
| | FLUUUUUID |
+-------+-----------+
Fixed-Fluid Model. In my snippet, I have demonstrated two kinds of examples. In the first case, the fluid is less in size. And the next has too long content.
Snippet
.parent {position: relative; margin: 0 0 15px; border: 1px solid #999; padding: 5px; padding-left: 100px;}
.parent .fixed {position: absolute; left: 5px; width: 90px; background-color: #99f;}
.parent .fluid {background-color: #f99;}
<div class="parent">
<div class="fixed">Fixed</div>
<div class="fluid">Fluid</div>
</div>
<div class="parent">
<div class="fixed">Fixed</div>
<div class="fluid">Fluid Lorem ipsum dolor sit amet, consectetur adipisicing elit. Itaque animi placeat, expedita tempora explicabo facilis nulla fuga recusandae officia, maiores porro eaque, dolore et modi in sapiente accusamus id aut.</div>
</div>
Working Snippet
.parent {position: relative; margin: 0 0 15px; padding: 5px; padding-left: 100px; min-height: 50px;}
.parent .fixed {position: absolute; left: 5px; width: 90px; background-color: #99f;}
.parent .fluid {}
<div class="parent">
<div class="fixed">
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAADsUlEQVR4nO3aS4gcVRTG8TsTgjMxCCoYo1ExulCjLjRCGElwISooLgRF1JWjIaIYooIQH5gsghtfIBoiAWeCCLoRxYX4IAjqJkpEXWlAUUQUQWMyMer0z0VVOzVl3X5NV3dPT/2hF9P3u4dzvuqpOvfWDaGioqKioqKiYgDBJjyMLTi13/n0DIzjdfP5BTf0O7eegOcUcxjn9ju/UsEYjkUMgB39zrFUcFaD4uHlfudYKji7iQFT/c6xNHAS3l2SBmAVPmlS/PAZgBFsxm8tFD9cBuBMvNFi4cNjAM7DNP5qs/jFbQBW41nMdFD44jQAo7gWr+H4Agrv2ACsxc162UViPZ7CD10oumMD8Dhm07k17Cyj2DFcjSckz/E/ulx0RwbgskiMG/PCk3E9NmKkSdDVabFbsQcf4fcSC85TaABWYGXuu8lIjEMYq4suxU+ZwTcxgVsla/EX8Da+wtGSimqHqVyRJ0guxHH8g30YT8eubBDnznqAZq3noJE34OkCzXRm/MNInI/rgp9LS7Uc8gZ8U6CpYUM6fkX6dxEXBK23oINC3oADEd2rGc37Ec29QW9vYN0gb8DmiO5PrEg1d0c000G5j6wyyBuwHN9GtFelmosj4wcDjpSRZYn87zGI5yPae9LxZeaaoSzfBwvry/tBkQFbI9rHMppfC8ZngsYbkINIkQEPRrSPZDRFN/sjQXcWKL2kyIDdEe2WzH2i6FH4XcDfZWVaEvmb4ErFP2+YSDWxNcGnQdI+LibyBtwX0c2Ya4nvj2j2BvEuaVDJG/BlRLcvo/ksopkcBgOK9htmcXk6vikSp4bzA74uKdGyyBvwYoFmTzo2is8jcfbXA9xufpMQ6wyPNRjrJXkDxiVL4FnJ/WzK3P/+dQ3i3JYNMiHZvnoA6yITjuI0yaurayTNx27s19sVZWxDZAwn5r6LNUgHsawoTn3ij5GJ70jdzWiXS65Ar2hnS2yiYH4NG5tN3NUggUPYjlvwEL5ooD1g/m5TN2h3U3SXuRv9LLa3Mul0C18jzGCN5Bdyk2RbrRs9Ryfb4hdJtsUvbGfSXQtMdFtBzDWSK7KQvcXevRjBMx0muRejDeKegZd09ovo7ZshPKr19cIsdjQqPhd7HT4YaAPSRC/BWw2MqOE9rO8g9ojkGNzhgTUgk+wq3IGdeDL9TGJtF2KfI77BORgGlI3kJccrS9aAEJb4IakQqmNy1UHJEJb4UdkQqsPS/4EN2CZ59J7S73wqKioqKioqhot/AedCJIQMIKG9AAAAAElFTkSuQmCC"/></div>
<div class="fluid">The Text</div>
</div>
<div class="parent">
<div class="fixed">
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAADsUlEQVR4nO3aS4gcVRTG8TsTgjMxCCoYo1ExulCjLjRCGElwISooLgRF1JWjIaIYooIQH5gsghtfIBoiAWeCCLoRxYX4IAjqJkpEXWlAUUQUQWMyMer0z0VVOzVl3X5NV3dPT/2hF9P3u4dzvuqpOvfWDaGioqKioqKiYgDBJjyMLTi13/n0DIzjdfP5BTf0O7eegOcUcxjn9ju/UsEYjkUMgB39zrFUcFaD4uHlfudYKji7iQFT/c6xNHAS3l2SBmAVPmlS/PAZgBFsxm8tFD9cBuBMvNFi4cNjAM7DNP5qs/jFbQBW41nMdFD44jQAo7gWr+H4Agrv2ACsxc162UViPZ7CD10oumMD8Dhm07k17Cyj2DFcjSckz/E/ulx0RwbgskiMG/PCk3E9NmKkSdDVabFbsQcf4fcSC85TaABWYGXuu8lIjEMYq4suxU+ZwTcxgVsla/EX8Da+wtGSimqHqVyRJ0guxHH8g30YT8eubBDnznqAZq3noJE34OkCzXRm/MNInI/rgp9LS7Uc8gZ8U6CpYUM6fkX6dxEXBK23oINC3oADEd2rGc37Ec29QW9vYN0gb8DmiO5PrEg1d0c000G5j6wyyBuwHN9GtFelmosj4wcDjpSRZYn87zGI5yPae9LxZeaaoSzfBwvry/tBkQFbI9rHMppfC8ZngsYbkINIkQEPRrSPZDRFN/sjQXcWKL2kyIDdEe2WzH2i6FH4XcDfZWVaEvmb4ErFP2+YSDWxNcGnQdI+LibyBtwX0c2Ya4nvj2j2BvEuaVDJG/BlRLcvo/ksopkcBgOK9htmcXk6vikSp4bzA74uKdGyyBvwYoFmTzo2is8jcfbXA9xufpMQ6wyPNRjrJXkDxiVL4FnJ/WzK3P/+dQ3i3JYNMiHZvnoA6yITjuI0yaurayTNx27s19sVZWxDZAwn5r6LNUgHsawoTn3ij5GJ70jdzWiXS65Ar2hnS2yiYH4NG5tN3NUggUPYjlvwEL5ooD1g/m5TN2h3U3SXuRv9LLa3Mul0C18jzGCN5Bdyk2RbrRs9Ryfb4hdJtsUvbGfSXQtMdFtBzDWSK7KQvcXevRjBMx0muRejDeKegZd09ovo7ZshPKr19cIsdjQqPhd7HT4YaAPSRC/BWw2MqOE9rO8g9ojkGNzhgTUgk+wq3IGdeDL9TGJtF2KfI77BORgGlI3kJccrS9aAEJb4IakQqmNy1UHJEJb4UdkQqsPS/4EN2CZ59J7S73wqKioqKioqhot/AedCJIQMIKG9AAAAAElFTkSuQmCC"/></div>
<div class="fluid">A longer text. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatibus magni ipsam facilis laboriosam nesciunt eveniet obcaecati dicta laborum voluptatem reiciendis, possimus vel enim. Dignissimos assumenda ipsa aut. Facere, unde animi.</div>
</div>
.imgBox, .textBox{
float: left;
box-sizing: border-box;
}
.textBox{
height: 70px;
width: 100px;
background-color: grey;
color: white;
text-align: center;
padding-top: 25px;
}
<div>
<div class="imgBox">
<img src="http://www.keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/image1.jpg" width="100" height="70"/>
</div>
<div class="textBox">
your text
</div>
</div>

Video fixed within div

I'm trying to make a website with fixed background video. but I want the background video to be inside one div only and above this video I will write something else. I tried this but didn't work :/
HTML Code:
<body>
<div class="header">
<div class="container-fluid">
<div class="row-fluid">
<div class="holder span12 text-center">
<p><span>somthing</span> here</p>
<p id="p1">- this website is designed by bla bla bla -</p>
</div> <!--End holder class-->
</div><!--End row class-->
</div><!--End container class-->
<video id="bgvideo" autoplay loop poster="imgs/main_img.jpg">
<source src="videos/main.mp4" type="video/mp4">
</video><!--End video tag-->
</div> <!--End header-->
<div class="service">
<div class="container-fluid">
<div class="row-fluid text-center">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eveniet, impedit, fugit. Nisi laboriosam rem optio unde. Saepe harum iusto, provident atque similique nulla dolore ad, sint esse asperiores enim eligendi.</p>
<p>Laborum magnam dolorem perferendis, ut, aut maxime. Quia dolores, sequi id architecto ea incidunt magni, enim maiores provident suscipit repellat voluptate possimus! Deserunt, quisquam non! Harum a architecto, quas tempora.</p>
<p>Ut nemo eligendi consequuntur reprehenderit cupiditate eveniet eos odit ducimus molestiae vitae, maxime ullam, praesentium dolores labore fuga alias eum hic ipsa similique voluptates repellendus. Aliquam facilis, cum fugiat tempora.</p>
</div><!--End row-->
</div><!--End container-->
</div><!--End service-->
</body><!--End body-->
CSS Code:
.header{
position: fixed;
min-width: 100%;
min-height: 100%;
}
#bgvideo{
min-width: 100%;
min-height: 100%;
position: relative;
top: 0;
left: 0;
}
.holder{
position: absolute;
z-index: 3;
font-size: 250%;
line-height: 1;
margin-top: 300px;
color: #fff;
font-family: lucidahand;
text-shadow: 3px 3px 4px rgba(0, 0, 0, 1);
}
.service{
position: absolute;
top: 1000px;
}
Js fiddle of current code.
If you didn't understand me ! this website contain the same idea that I want to make
http://designingmedia.com/html/vizerk/HTML/index-one-video-with-slider-content.html
thanks :D
HTML Code:
<body>
<div class="header">
<video id="bgvideo" autoplay loop poster="imgs/main_img.jpg">
<source src="videos/main.mp4" type="video/mp4">
</video>
</div>
<div class="sitebody">
<div class="firstdiv">
<div class="container-fluid">
<div class="row-fluid">
<p>bla bla bla</p>
<p>bla bla bla</p>
<p>bla bla bla</p>
</div><!-- End row-->
</div><!-- End container-->
</div>
<div class="seconddiv">
<div class="container-fluid">
<div class="row-fluid">
<p>bla bla bla</p>
<p>bla bla bla</p>
<p>bla bla bla</p>
</div><!-- End row-->
</div><!-- End container-->
<div class="thirddiv">
<div class="container-fluid">
<div class="row-fluid">
<p>bla bla bla</p>
<p>bla bla bla</p>
<p>bla bla bla</p>
</div><!-- End row-->
</div><!-- End container-->
</div><!-- End sitebody-->
</body>
CSS Code:
.header{
width: 100%;
position: fixed;
}
#bgvideo{
min-width: 100%;
min-height: 100%;
position: relative;
z-index:-2;
}
.sitebody{/* this class to hold the content so u don't have to set position: absolute for each div or section in your website*/
position: absolute;
width: 100%;
text-align: center;
}
.firstdiv{
margin-top: 900px;
height: 800px;
background-color: #fff;
}
.seconddiv{
/* write whatever u want */
}
.thirdddiv{
/* write whatever u want */
}
Okey, I tried this and worked 4 me , the idea is !! I made fixed header and it's all the time behind your content. so u must set background for each div comes next in your website because if you didn't set a background the video will be shown as background and it's not nice, trust me ☺ ☺
If any one know a better answer please write it down , and if any one can take my answer and make it easier for others I have no problem at all. have a nice day ;)
I see that you are using Bootstrap, which sometimes can be a d*ck;-) In som situations it's easier to
construct your own div and css. That said, try wrapping your video into it's own container and place it above the text you want to display on top of the video. You then have to set the positions to relative in your css, and then you can place your content on top of your video with the margin set to -xxx px. You will haver to play around a bit to get it centered and apply your won desired responsiveness.
here is how I did it:
(note: when you resize the window the text doesn't stay centered, you have to set your own responsive settings, or maybe when you wrap it in a bootstrap container it will do it for you, although in my experience bootstrap doesn't help you that much when centering containers in containers.
Html:
<body>
<div id="wrapper">
<div id="bottom-layer">
<video id="video" preload="auto" src="video/1.mp4"></video>
</div>
<div id="top-layer">
<p>Your Text Here <br />
Hover me!
</p>
</div>
</div>
</body>
CSS:
#bottom-layer {
margin: auto;
max-width: 100%;
max-height: 100%;
background: gray;
position: relative; /* this */
}
#video {
margin-bottom: -4px;
}
#top-layer {
max-width: 100%;
max-height: inherit;
position: relative; /* and this allows you to put the div on top of the video */
margin-top: -640px;
/*Hover Off*/
-o-transition:1.0s;
-ms-transition:1.0s;
-moz-transition:1.0s;
-webkit-transition:1.0s;
transition:1.0s;
}
#top-layer:hover {
/*Hover On*/
background-color: rgba(255,255,255,0.6);
-o-transition:1.0s;
-ms-transition:1.0s;
-moz-transition:1.0s;
-webkit-transition:1.0s;
transition:1.0s;
}
#top-layer p{
text-align: center;
margin: auto;
padding: 320px;
}
img,video,canvas {
width: 100%; /* responsive images,video and canvas elements
}
try this and play around with your own desired settings:)
Good luck!