I was wondering if someone can help me to work out how to create the below layout using bootstrap.
Large screens the layout is:
and then for small screens the layout would be:
Basically the red will have an image (full height of red box) with and box (yellow) overlapping it. The yellow box will have the same height as the blue box. Then on mobile all four boxes will stack on top of one another.
I've had a play around with the code here:
http://www.bootply.com/6N3RHao0CI
If anyone can help me out it would be appreciated! :-)
Thanks
Well, took me a bit of time, but then I figured out my media queries were smaller than the screensize I was looking at. Turns out I had the solution all along. Of course media sizes are set to what I was tampering with, so do change those to bootstrap sizes.
Settings will have to be changed a bit, but the idea is there.
This is the code used: Bootply link
I gave the div the name floater and gave it the following CSS:
#media(min-width: 1000px) {
.floater {
right: 34%;
position: absolute;
}
}
#media(max-width: 999px) {
.floater {
position: relative;
right: 0px !important;
}
}
Using pure bootstrap. Added some CSS for the sake of demo.
DEMO: http://jsfiddle.net/arshadmuhammed/bkogj3wn/6/
(please don't forget to resize the output screen in fiddle)
HTML
<div class="col-md-10">
<div class="col-md-8 col-md-offset-4 hidden-sm hidden-xs"></div>
</div>
<div class="col-md-12 hai2 hidden-md hidden-lg"></div>
<div class="col-md-2 col-xs-6"></div>
<div class="col-md-2 col-xs-6 hai"></div>
CSS
.col-md-10{
background:url('http://images.all-free-download.com/images/graphiclarge/blue_abstract_background_310971.jpg');
background-size:cover;
height:200px;
padding-right:0px!important;
}
.col-md-8{
background:yellow;
height:100px;
}
.col-md-2{
background:blue;
height:100px;
}
.hai{
background:green;
height:100px;
}
.hai2{
background:yellow;
height:100px;
}
The Bootstrap grid is not really made for this design pattern (equal heights and all). If you want something fluid with equal height text boxes on the right (for the larger viewports), I would roll my own using display:table and table-cell.
DEMO: https://jsbin.com/hufasa
HTML
<div class="hero-feature">
<div class="hero-image">
<div class="intro-text">Text box</div>
</div>
<!-- /.hero-image -->
<div class="feature-box-wrapper">
<div class="feature-box blue">
<div>text</div>
</div><!-- /.feature -->
<div class="feature-box green">
<div>text</div>
</div><!-- /.feature-box -->
</div><!-- /.feature-box-wrapper -->
</div><!-- /.hero-feature -->
CSS
.hero-feature .hero-image {
background-image: url(http://placekitten.com/g/500/500);
background-size: cover;
background-position: center top;
padding-top: 50%;
}
.hero-feature .intro-text {
background: gold;
padding: 5%;
}
.hero-feature .feature-box {
padding: 5%;
color: #fff;
float: left;
width: 50%;
}
.hero-feature .blue {
background-color: blue
}
.hero-feature .green {
background-color: green
}
#media (min-width:768px) {
.hero-feature {
display: table;
width: 100%;
}
.hero-feature .intro-text {
position: absolute;
top: 0;
right: 0;
padding: 5%;
width: 70%;
}
.hero-feature .hero-image {
display: table-cell;
background-image: url(http://placekitten.com/g/500/500);
background-size: 100.5%;
/*disquise the rounding errors in many browsers */
background-position: center center;
height: 400px; /*height of the image*/
padding: 0;
position: relative;
}
.hero-feature .feature-box-wrapper {
display: table-cell;
width: 30%;
}
.hero-feature .feature-box {
display: table;
height: 50%; /* half the height of the .hero-image */
width: 100%;
vertical-align: middle;
float: none;
}
.hero-feature .feature-box > div {
display: table-cell;
vertical-align: middle;
text-align: center;
}
}
Everything not shared by all viewport sizes goes outside the media query.
Related
I'm somewhat new to html but im tyring to have a transparent background image and in the body have div containers that show the background image just not transparently.
I want to say, "do the opposite", but I really need more information (or an example).
If you used one background image and set specific classes up for the divs that can see the image, would you be able to get the effect you want?
CSS example:
html body { background-image: url("myimage.jpg"); }
div { background: #FFFFFF; }
.peek { background: transparent; }
HTML example:
<body>
<div> section with white background (blocks the background image), contains text </div>
<div class="peek"> section that exposes the background image, reveals different aspects of the background when the page is scrolled </div>
Please let me know if I understood what your goal was.
To my understanding you're looking for something like this:
<style>
* {
color: white;
}
.background {
width: 100%;
height: 100%;
position: relative;
background-image: url('https://images.pexels.com/photos/730896/pexels-photo-730896.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260');
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.side {
width: 20%;
height: 100%;
position: relative;
display: inline-block;
float: left;
background-color: red;
}
.main {
width: 60%;
height: 100%;
position: relative;
display: inline-block;
float: left;
background-color: transparent;
}
.top, .spacer, .bottom {
width: 100%;
height: 20%;
position: relative;
display: inline-block;
float: left;
background-color: red;
}
.content {
width: 100%;
height: 20%;
position: relative;
display: inline-block;
float: left;
}
.section-one {
background-color: rgba(0,0,0,0.5);
}
.section-two {
background-color: rgba(0,0,0,0.25);
}
</style>
<div class="background">
<div class="side">THIS IS WHITE</div>
<div class="main">
<div class="top">THIS IS WHITE</div>
<div class="content section-one">THIS HAS A BG IMAGE THAT IS SET TO THE CONTAINER DIV</div>
<div class="spacer">THIS IS WHITE</div>
<div class="content section-two">THIS HAS A BG IMAGE THAT IS SET TO THE CONTAINER DIV</div>
<div class="bottom">THIS IS WHITE</div>
</div>
<div class="side">THIS IS WHITE</div>
</div>
I created a div based table. I'm trying to take a image, put it in top left table cell and make it responsive. I've made it responsive, but its not in the table cell I want it to be. Any help?
JSFiddle:
https://jsfiddle.net/benjones337/3c4fkb78/18/
HTML
<div class="hmTable">
<div class="hmTableRow">
<div class="hmTableCell"><p class="rspimg1"></p></div>
<div class="hmTableCell"><p class="rspimg2"></p></div>
</div>
<div class="hmTableRow">
<div class="hmTableCell">textholder</div>
<div class="hmTableCell">textholder</div>
</div>
</div>
CSS
.hmTable {
margin: 0 auto; /* or margin: 0 auto 0 auto */
display: table;
width: 50%;
}
.hmTableRow {
display: table-row;
}
.hmTableCell, .hmTableHead {
display: table-cell;
width: 50%;
height:100%;
border: 1px solid #999999;
position:relative;
}
.hmTableBody {
display: table-row-group;
}
.rspimg1{
background-image: url("https://upload.wikimedia.org/wikipedia/en/thumb/3/39/Red_triangle_with_thick_white_border.svg/1152px-Red_triangle_with_thick_white_border.svg.png");
background-repeat:no-repeat;
background-size:100% 100%;
width:100%;
height:100%;
position:absolute;
}
.rspnimg2{
}
When using background-image, the div doesn't grow with the image, so you will need to give it a height/width, either to the cell or the image div (btw, I changed your p to div, as p is for text rather than image).
Below sample I'm pretty sure look close to what you are after, and If not, drop me a comment and I'll fix it for you.
html, body {
margin: 0;
height: 100%;
}
.hmTable {
margin: 0 auto;
display: table;
width: 50%;
height: 30%;
}
.hmTableRow {
display: table-row;
height: 10%;
}
.hmTableCell, .hmTableHead {
display: table-cell;
width: 50%;
height:100%;
border: 1px solid #999999;
}
.rspimg1{
background: url("https://upload.wikimedia.org/wikipedia/en/thumb/3/39/Red_triangle_with_thick_white_border.svg/1152px-Red_triangle_with_thick_white_border.svg.png") center no-repeat;
background-size: contain;
width:100%;
height:100%;
}
.rspnimg2{
}
<div class="hmTable">
<div class="hmTableRow">
<div class="hmTableCell">
<div class="rspimg1">triangle</div>
</div>
<div class="hmTableCell">
<div class="rspimg2">square</div>
</div>
</div>
<div class="hmTableRow">
<div class="hmTableCell">textholder</div>
<div class="hmTableCell">textholder</div>
</div>
</div>
Remove position:absolute or add top:0 to .rspimg1.
Result
I want to have a div in the background (100% width of browser) by mouseover on a content-div. Everything works great but i dont know is there a solution to make the background div as height as the parent?
Without using Jquery? Pure CSS would be great!
Thanks!
.content {
/* position: relative; >> will make the absoluted positioned div 100%width of the browser*/
z-index: 1;
}
.background {
position: absolute;
background: aqua;
width: 100%;
right: 0px;
left: 0px;
z-index: -1;
display: none;
}
.post:hover .background {
display: block;
height: 10%;
/* WHAT TO DO? */
}
<div class="post">
<div class="content">
<div class="background"></div>
…content…
</div>
</div>
part of the problem is: the "post" div is in a centerd "main" div with a given width and i want to have a background-div that has 100% width of the viewport
Sorry, it is a bit hard to explain what i need, therefore I make a small sketch here:
This is posible with vw units, look:
* {
margin: 0;
padding: 0;
}
.main {
background: #29D;
margin: 0 auto;
max-width: 800px;
}
.post {
background: #E31;
margin: 3vw 3vw 3vw 12vw;
}
.content {
background: #8D5;
margin: 2vw;
}
.content img {
width: 100vw;
margin-left: -14vw;
display: block;
}
#media(min-width: 800px) {
.content img {
margin-left: calc(800px / 2 - 50vw - 14vw);
}
}
<div class="main">
.main
<div class="post">
.post
<div class="content">
.content
<img src="http://s3.postimg.org/3k8v5p0v7/dragon.jpg">
</div>
<div class="content">
.content
</div>
<div class="content">
.content
</div>
</div>
</div>
First thing you need to know is the max width of your wrapper. In my case it is 800px. You have to substitute all the 800's with your size. Then notice that all your left margins should be in vw units or pixels but not 100%. The trick here is that calc() function and the media query!
I have a responsive fluid width website. For one section I have a title, text and an image.
For larger displays I need the title and text to sit to the right of the image. For smaller displays I want a single column with the title first. (see image)
<div class="cont">
<h1>Here is Title</h1>
<div class="img"></div>
<p>Some text</p>
</div>
.cont {
background: grey;
width: 30%;
margin: auto;
}
.img {
height: 200px;
width: 200px;
background: blue;
}
Is this layout possible? For support reasons I cant use flexbox.
http://codepen.io/anon/pen/JoYMoX
I would use your current CSS as default for smaller screens and then use media queries to adjust the layout for larger ones. You may have to use absolute positioning.
For your example:
#media only screen and (min-width: 720px) {
.img {
position: absolute;
top: 0;
left: -200px;
}
.cont {
margin-left: 200px;
position: relative;
}
}
Edit - Alternative Without Absolute Positioning:
As I mentioned in the comments, you could also place the image in the content twice and then simply hide one as needed with media queries. Not ideal, but at least the browser should only download the image once.
So for example:
.cont-wrap {
background: grey;
width: 60%;
margin: auto;
overflow: hidden;
}
.cont {
float: left;
}
.img {
height: 200px;
width: 200px;
background: blue;
}
.left {
display: none;
float: left;
}
#media only screen and (min-width: 720px) {
.img {
display: none;
}
.img.left {
display: block;
}
}
<div class="cont-wrap">
<div class="img left"></div>
<div class="cont">
<h1>Here is Title</h1>
<div class="img"></div>
<p>Some text</p>
</div>
</div>
with bootstrap you can use the offset parametrics, and the pull or push orders.
with the normal css, you can use media query setting position absolute...
#media all and (max-width:768px){
.title{position: absolute;
top:0; left: 0;
OR
width:100%; float:left; ...}
.bluebox{width:100%;
margin-top:20px;}}
Sorry if the title is confusing. Basically, I'm working on a tumblr theme where I need three adjacent divs wrapped in a fixed-width container. None of their contents are fixed, so they all have variable widths. The middle div should always be centered to the container, while the divs to the left and right will always be "touching" the middle div, and, thus, move around as the middle div's width changes (the left and right s may be images, so text-align doesn't always work). Plus, I may also need to hide the left, right, or both the left and right divs.
Here's a conceptual image:
I can obtain this using flexboxes easily (JFiddle), but flex only has 86% global support.
This is the closest I could get without using flexboxes, but I can't get that middle div (with the text) centered to the title div, while preserving the relative positions of the two images on either side: JFiddle
* {
height: 100%;
position: relative;
}
body {
height: 200px;
}
/* just to get rid of scrollbar */
p {
margin: 0;
}
.title {
background: #aaa;
height: 22px;
width: 450px;
/* for example */
margin: 0 auto;
}
.container {
background: #abc;
float: left;
}
.lr {
transform: translate(0, -100%);
}
.left {
background: green;
float: left;
}
.left img {
transform: translate(-100%);
}
.center {
background: red;
display: inline-block;
z-index: 2;
}
.right {
background: blue;
float: right;
}
.right img {
transform: translate(100%);
}
.left img, .right img {
height: 100%;
}
<div class="title">
<div class="container">
<div class="center">CENTERCENTERCENTERCEN</div>
<div class="lr">
<div class="left">
<img src="http://i.imgur.com/7bvErJN.jpg" />
</div>
<div class="right">
<img src="http://i.imgur.com/q8Mq0YZ.jpg" />
</div>
</div>
</div>
</div>
Other people have mentioned trying to display the title as a table, but that would require centering the middle cell to the whole row, and having the cells to the left and right take up the rest of the space, and I'm not sure if you can do that when their widths aren't fixed.
Anyone know of any other solutions?
If you can change your HTML then apply this:
First move the left and right elements inside center:
<div class="center">
CENTERCENTERCENTERCEN
<div class="left">
testtest<img src="http://i.imgur.com/7bvErJN.jpg" />
</div>
<div class="right">
<img src="http://i.imgur.com/q8Mq0YZ.jpg" />
</div>
</div>
Then on the CSS :
/*Keep the center container on the middle*/
.title {
text-align:center;
}
.center {
position:relative;
display:inline-block;
}
/*Position elements based on the relative center parent*/
.left {
position:absolute;
top:0;left:0;
transform:translateX(-100%)
}
.right {
position:absolute;
top:0;right:0;
transform:translateX(100%)
}
Check this DemoFiddle
Using position: absolute should help in this.
I changed your HTML to following:
<div class="title">
<div class="container">
<img class="left" src="http://i.imgur.com/7bvErJN.jpg" />
<div class="center">CENTERCENTERCENTERCEN</div>
<img class="right" src="http://i.imgur.com/q8Mq0YZ.jpg" />
</div>
</div>
CSS
.title {
background: #aaa;
height: 22px;
width: 450px;
/* for example */
margin: 0 auto;
text-align: center;
}
.container {
background: #abc;
display: inline-block;
margin: 0 auto;
position: relative;
text-align: left;
}
.center {
background: red;
}
.left, .right {
position: absolute;
top: 0px;
}
.left {
right: 100%;
}
.right {
left: 100%;
}
Working Fiddle
Updated to show OP Update
No need for flex here, why not just use percentages? Float all the containers and put the percentages as relative to the sizes you want. (50% for the middle, 25% for the outside containers).
You can use the outside containers as wrappers so you can still use a border on the inner containers without messing up the sizing. Then just float the inner containers within the outside containers (if that makes sense). The example below just floats the inner p tags to the outer containers.
This makes it always hug the inner container, while keeping relative sizes and also keeping the middle centered.
Example below:
Fiddle
HTML
<div class="container">
<div class="flexa">
<div class="left">
<p>leftleft</p>
</div>
<div class="center"><p>CENTERCENTdsfdfdERCENTsdfdfsfERCEN</p></div>
<div class="right">
<p>ri</p>
</div>
</div>
<div class="bottom">BOTTOMOMOM</div>
</div>
CSS
* {
margin: 0;
padding: 0;
}
div {
background: #aaaaaa;
overflow: hidden;
}
p{
border: 1px solid black;
}
.container {
width: 500px;
/* for example */
margin: 0 auto;
}
.right p{ /* This is what makes it work. This could be a div with class of inner or something like that. */
float:left;
}
.left p{
float:right;
}
.flexa div{
float:left;
}
.left {
width:25%;
}
.center {
width: 50%;
}
.right {
width:25%;
}
.bottom {
display: block;
margin: 0 auto;
text-align: center;
}