I am trying to achieve the similar display for the highlighted part in the picture with yellow and black background. The three boxes displaying half in the yellow and half in the black bg.
Can anybody help me deal with it in CSS BOOTSTRAP.
Thanks in advance.
http://i.stack.imgur.com/yPj0w.png
The 3 boxes are simply positioned absolutely over a background image.
See this-
#bgbox {
background-color: black;
border-left: 50px solid yellow;
width:50px;
height:100px;
}
#top {
position:absolute;
top:40px;
left:40px;
width:30px;
height:30px;
background-color:blue;
}
<div id="bgbox">
</div>
<div id="top">
</div>
use position for doing this.Demo
<div class="top">
<div class="inner"></div>
</div>
<div class="buttom">
</div>
.top{
position:relative;
width:100%;
height:300px;
background-color:yellow;
}
.inner{
position:absolute;
width:300px;
height:300px;
top:50px;
left:100px;
background-color:red;
z-index:3;
}
.buttom
{
position:relative;
width:100%;
height:300px;
background-color:black;
}
Use the Bootstrap class and arrange the boxes by margin top value . look the code below. run it on full screen
.yellowbg { background-color: #beb333; height: 300px; }
.blackbg { background-color: #000; height: 300px; }
.yellowboxes { height: 182px; margin-top: -118px; background-color: #e3cf00; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-xs-12">
<div class="yellowbg">
</div>
<div class="blackbg">
<div class="row">
<div class="col-lg-2 col-lg-offset-3 col-md-2 col-md-offset-3 col-sm-offset-3 col-sm-2">
<div class="yellowboxes">
Box 1
</div>
</div>
<div class="col-lg-2 col-md-2 col-sm-2">
<div class="yellowboxes">
Box 2
</div>
</div>
<div class="col-lg-2 col-md-2 col-sm-2">
<div class="yellowboxes">
Box 3
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Related
I made an example to represent my current issue.
I want this structure. I tried height: 100% on the blue part but it didn't work, so I gave height: 80vh.
This is an issue because nothing is aligned anymore and gets worse if you make the windows smaller or bigger (not responsive).
How do I make the left and right side of the content aligned at the top and bottom with a margin-top of 5px to the black part?
.red {
background: red;
}
.blue {
background: blue;
height: 80vh;
}
.green {
background: green;
}
img {
width: 100%;
height: 100%;
}
.black {
background: black;
margin-top: 5px;
}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-xs-6">
<div class="row">
<div class="col-xs-12">
<div class="red">
<img src="https://www.w3schools.com/w3images/fjords.jpg" />
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="green">
<img src="https://www.w3schools.com/w3images/fjords.jpg" />
</div>
</div>
</div>
</div>
<div class="col-xs-6">
<div class="blue">
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="black">
Hi
</div>
</div>
</div>
</div>
I tackled something similar to this and whipped up a jQuery solution to it that you might want to try, it's been working great for me.
Basically the function gets the height of the column you know is going to be the tallest. If that content is larger than the others it sets the height of the others to the same of the taller piece of content.
$(document).ready(function () {
var tallest = $(".red").height();
var shortcolumn1 = $(".blue").height();
if (tallest >= shortcolumn1) {
$(".blue").css("height",""+ tallest +"px");
$(".green").css("height",""+ tallest +"px");
}
else {
}
});
Change CSS, Your Footer height 25px;
.red {
background: red;
height:calc(50vh - 12.5px);
}
.blue {
background: blue;
height:calc(100vh - 25px);
}
.green {
background: green;
height:calc(50vh - 12.5px);
}
.red {
background: red;
height:calc(50vh - 12.5px);
}
.blue {
background: blue;
height:calc(100vh - 25px);
}
.green {
background: green;
height:calc(50vh - 12.5px);
}
img {
width: 100%;
height: 100%;
}
.black {
background: black;
margin-top: 5px;
}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-xs-6">
<div class="row">
<div class="col-xs-12">
<div class="red">
<img src="https://www.w3schools.com/w3images/fjords.jpg" />
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="green">
<img src="https://www.w3schools.com/w3images/fjords.jpg" />
</div>
</div>
</div>
</div>
<div class="col-xs-6">
<div class="blue">
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="black">
Hi
</div>
</div>
</div>
</div>
add display:flex for the main row, min-height:100% for the col-xs-6 and height:100% for the blue box the code should look like:
.red {
background: red;
}
.blue {
background: blue;
height: 100%;
}
.green {
background: green;
}
img {
width: 100%;
height: 100%;
}
.black {
background: black;
margin-top: 5px;
}
.d-flex{
display: -webkit-box;
display: -ms-flexbox;
display: flex;
}
.mh-100{
min-height:100%;
}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="container">
<div class="row d-flex">
<div class="col-xs-6 mh-100">
<div class="row">
<div class="col-xs-12">
<div class="red">
<img src="https://www.w3schools.com/w3images/fjords.jpg" />
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="green">
<img src="https://www.w3schools.com/w3images/fjords.jpg" />
</div>
</div>
</div>
</div>
<div class="col-xs-6 mh-100">
<div class="blue">
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="black">
Hi
</div>
</div>
</div>
</div>
How can I make responsive layout like this?
I need only few tips how to do it. I dont need full source code. Sorry for my english.
My code:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<div class="col-md-6">
<img src='https://via.placeholder.com/350x150' />
</div>
<div class="col-md-6">
CONTENT
</div>
</div>
<div class="row">
<div class="col-md-6">
CONTENT
</div>
<div class="col-md-6">
<img src='https://via.placeholder.com/350x150' />
</div>
</div>
</div>
I want img to be half page size.
Check fiddle and snippet below. It is fully responsive and it is working in any device.
body {
padding:15px 0;
}
.content-box {
position:relative;
width:100%;
min-height:350px;
background:#ccc;
margin:15px 0;
}
.img-box.left {
position:absolute;
top:-15px;
right:-15px;
bottom:-15px;
width:calc( 50vw - 15px );
background:red;
}
.img-box.right {
position:absolute;
top:-15px;
left:-15px;
bottom:-15px;
width:calc( 50vw - 15px );
background:red;
}
#media only screen and (max-width: 768px) {
.img-box.left, .img-box.right {
position:absolute;
top:0px;
left:0px;
right:0px;
bottom:0px;
width:100%;
background:red;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<body>
<div class=container>
<div class="row">
<div class="col-md-6">
<div class="content-box">
<div class="img-box left">
image
</div>
</div>
</div>
<div class="col-md-6">
<div class="content-box">
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="content-box">
</div>
</div>
<div class="col-md-6">
<div class="content-box">
<div class="img-box right">
image
</div>
</div>
</div>
</div>
</div>
</body>
https://jsfiddle.net/Sampath_Madhuranga/tfz87bqe/18/
This works for you...Check and let me know if need any help.
Thanks.
here's your layout with bootstrap 4. put image into box--wide but keep in mind pink divs are absolutely positioned so they will not resize the parent - they will take full parent's height which depends on content in gray box
to make this responsive - my suggestion is to wrap images into .col-12and for desktop set it's to position static while images are absolute so they will align inside .container, not .col-12 and on mobile images should be just static
.container {
background: #5f408c;
padding: 20px;
}
.container h1 {
text-align: center;
color: white;
}
.box {
min-height: 200px;
display: flex;
justify-content: center;
align-items: center;
color: white;
font-weight: bold;
text-transform: uppercase;
font-size: 40px;
}
.box--wide {
position: absolute;
left: 15px;
right: calc(50% + 15px);
}
.box--wide:last-child {
right: 15px;
left: calc(50% + 15px);
}
.box--pink {
background: #ec008c;
}
.box--gray {
background: #272827;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-12">
<h1>TITLE</h1>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="box box--pink box--wide">image</div>
<div class="col-12 col-md-6 offset-md-6 ">
<div class="box box--gray">content</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-12 col-md-6">
<div class="box box--gray">content</div>
</div>
<div class="box box--pink box--wide">image</div>
</div>
</div>
How can I design this image below using Bootstrap 3.3.6, those are div CSS? I am just a new programmer, hope you can help me.
Here's what you can do using divs.
<html>
<head>
<body>
<div style="border:3px solid black; width:auto; padding:10px;">
<div style="border:3px solid blue; width:auto; padding:10px; text-align:center;">
<div style="width:100px; display:inline-block; border:3px solid pink; margin:10px; height:10px; padding:10px;">
</div>
<div style="width:100px; display:inline-block; border:3px solid green; margin:10px; height:10px; padding:10px;">
</div>
</div>
</div>
</body>
</head>
<html>
To get the two inner-most divs floating side-by-side, we use display:inline-block; property.
use this. this is a bootstrap code.
<div class="container">
<div class="row">
<div class="col-md-6"></div>
<div class="col-md-6"></div>
</div>
</div>
Your structure should look like that :
<div class="container">
<div class="row">
<div class="div-1 col-md-12">
<div class="div-2 col-md-12">
<div class="div-3 col-md-6">
</div>
<div class="div-4 col-md-6">
</div>
</div>
</div>
</div>
</div>
After that the css will do the trick
OK Im using bootstrap and i have main content and inside main content i have left and right side. On left side its content and on right side i have 8 boxes. I tried everything but i cant get equal left and right side.
.main-content{
float: left;
width: 100%;
position: relative;
}
.main-content .right-box.col-md-4{
width: 37.5%;
padding-left:0;
padding-right:0;
float:right;
position:absolute;
top:0;
bottom:0;
right: 0;
}
.main-content .left-box.col-md-8{
width:62.5%;
padding-left:0;
padding-right: 0;
background-color: #fff;
float: left;
position: relative;
}
FIDDLE: https://jsfiddle.net/rvqg3fd7/
and last div on right side need to be same height like div on left side..
I tried this but without succes.
Height is an element you shouldn't force in a Bootstrap powered website, simply because Bootstrap relies on it's vertical flexibility to respond to smaller devices. After all, this is the main purpose why anyone would use Bootstrap. Yet, if you do insist, then you must give each element a definite height and control such height with paddings.
You didn't provide a code we could use (not even the fiddle) so I'll post my demo so you can see the bootstrap classes architecture you need to achieve this;
Here is the HTML
<div class="container">
<div class="row main-content">
<div class="col-xs-12 col-sm-6 col-md-6">
<div class="row">
<div class="box left">
</div>
</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-6">
<div class="row">
<div class="box right">
<div class=" innerbox col-xs-12">
1
</div>
<div class=" innerbox col-xs-12">
2
</div>
<div class=" innerbox col-xs-12">
3
</div>
<div class=" innerbox col-xs-12">
4
</div>
<div class=" innerbox col-xs-12">
5
</div>
<div class=" innerbox col-xs-12">
6
</div>
<div class=" innerbox col-xs-12">
7
</div>
<div class=" innerbox col-xs-12">
8
</div>
</div>
</div>
</div>
</div>
</div>
And the CSS
.box.left{
background:red;
text-align:center;
color: white;
height:350px;
}
.box.right{
background:blue;
text-align:center;
color: white;
height:350px;
padding:10px
}
.innerbox{
background:lightgray;
text-align:center;
color: black;
height:30px;
margin-top:10px;
}
.main-content{
float: left;
width: 100%;
position: relative;
}
And the link to the DEMO
So i need to create layout with 3 or 4 squares centered in it. As now many different screens are (i at the moment have 21 philips, macbook 13 and ipad) and on all of them the squares are different.
So i need it centered in any screens. Here some of my code:
Some CSS:
#main{
border: 1px solid red;
margin: auto;
}
#block{
display: inline-block;
padding: 110px;
border: 1px solid red;
margin: 10px 10px;
overflow:hidden;
}
Some HTML:
<div id="wrapper">
<div id="header">
header
</div>
<div id="main">
<div id="block">main</div>
<div id="block">main</div>
<div id="block">main</div>
<div id="block">main</div>
<div id="block">main</div>
<div id="block">main</div>
<div style="clear:both"></div>
</div>
</div>
I tried different ways with some extra div...
So i need that this squares would automatically centered in any screens
Since you're just using inline-block, you can center the text of the container.
Also, use classes for non-unique elements.
Fiddle: http://jsfiddle.net/LWTNB/3/
Updated HTML:
<div id="wrapper">
<div id="header">
header
</div>
<div id="main">
<div class="block">main</div>
<div class="block">main</div>
<div class="block">main</div>
<div class="block">main</div>
<div class="block">main</div>
<div class="block">main</div>
<div class="block">main</div>
<div class="block">main</div>
<div class="block">main</div>
<div class="block">main</div>
<div class="block">main</div>
</div>
</div>
Updated CSS:
#main{
border:1px solid red;
text-align:center; /* solution */
}
.block{
display:inline-block;
padding:110px;
border:1px solid red;
margin:10px 10px;
overflow:hidden;
}