How to create grid fluid responsive consist of three boxes? - html

I am tired for create responsive grid in css & html,the following image may be easy to figure out. many thanks for help.
Here is my example image:

You might use an excellent framework for it : bootstrap !
They have an excellent grid system :)
You might find everything you need here :
http://getbootstrap.com/css/#grid
Hope that should help :)

Here is my css & Html but I can't write prefect css I am so beginner with css & html.
<div class="wrapper">
<div class="Box1">
Box1
</div>
<div class="container_right">
<div class="Box2">Box2</div>
<div class="Box3">Box 3</div>
<div class="Box4"> Box4</div>
</div>
</div>
CSS:
.wrapper {
overflow:hidden;
width: 1060px;
margin:0 auto;
padding:5px;
}
.wrapper Box1 {
float:left;
margin-right:10px;
width:520px;
padding:5px;
background-color:#808080;
}
.wrapper .container_right {
width:520px;
float:right;
}
.container_right .box2 {
width:100%;
height:200px;
margin:5px;
padding:5px;
background-color:#808080;
}
.container_right .box3 {
width:50%;
height:200px;
padding:5px;
background-color:#808080;
}
.container_right .box4 {
width:50%;
height:200px;
padding:5px;
background-color:#808080;
}

1) Here's how Stack Overflow works: learn, try, fail, then come ask for help here. So you need to show some effort yourself.
2) Anyway, there must be a million ways to build such a layout. Here is a sample with Bootstrap, using images as content. Includes some unfortunate stabbing of the framework, to get rid of the gutter between things.
Fiddle:
https://jsfiddle.net/csy1wypc/1/
HTML:
<div class="container-fluid">
<div class="row">
<div class="col-md-6 col-sm-6 col-xs-6">
<div class="single">
<div class="img-holder">
<img src="http://lorempixel.com/g/900/400/">
</div>
</div>
</div>
<div class="col-md-6 col-sm-6 col-xs-6">
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="double">
<div class="img-holder">
<img src="http://lorempixel.com/g/800/400/">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6 col-sm-6 col-xs-6">
<div class="single">
<div class="img-holder">
<img src="http://lorempixel.com/g/600/400/">
</div>
</div>
</div>
<div class="col-md-6 col-sm-6 col-xs-6">
<div class="single">
<div class="img-holder">
<img src="http://lorempixel.com/g/700/400/">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
CSS:
.col-md-6,
.col-md-12,
.col-sm-6,
.col-sm-12,
.col-xs-6,
.col-xs-12 {
padding: 0;
}
.row {
margin: 0;
}
.single,
.double {
position: relative;
width: 100%;
overflow: hidden;
}
.single {
padding-bottom: 100%;
}
.double {
padding-bottom: 50%;
}
.single .img-holder,
.double .img-holder {
position: absolute;
width: 100%;
text-align: center;
}
.single img,
.double img {
position: relative;
max-height: 100%;
left: 100%;
margin-left: -200%;
}

Related

trying to center html divs on a page [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I am trying to center div tags on a page (content inside is irrelevant). I am able to do it and the page looks great, but it's completely hacked together with arbitrary margins everywhere to get things to align correctly. Can someone point me to a simple .css solution to pull of a page with a structure that looks something like the attached image?
You can use plain CSS without flex or grid layout. Here is an example using Bootstrap:
<div class="container">
<div class="block row"></div>
<div class="clearfix row row2">
<div class="col-sm-6 col"><div class="block"></div></div>
<div class="col-sm-6 col"><div class="block"></div></div>
</div>
<div class="block row"></div>
<div class="clearfix row row4">
<div class="col-sm-4 col"><div class="block"></div></div>
<div class="col-sm-4 col"><div class="block"></div></div>
<div class="col-sm-4 col"><div class="block"></div></div>
</div>
</div>
.block {
background: blue;
height: 30px;
}
.row {
margin-bottom: 20px;
}
.row .col:first-child {
padding-left: 0;
}
.row .col:last-child {
padding-right: 0;
}
.row4 .col {
padding: 0 30px;
}
Here is the jsfiddle.
You can use the percentage width, associated with float property, to do what you want.
Float: https://www.w3schools.com/css/css_float.asp
For example:
HTML:
<div class="header"></div>
<div class="second-container">
<div class="left">
</div>
<div class="right">
</div>
</div>
<div class="third-container">
</div>
<div class="fourth-container">
<div class="left">
</div>
<div class="middle">
</div>
<div class="right">
</div>
</div>
CSS:
.header{
width:90%;
height:50px;
margin:5%;
background-color:blue;
}
.second-container{
height:80px;
width:90%;
margin:5%;
}
.second-container .left{
height:100%;
width:40%;
margin-left:5%;
margin-right:5%;
float:left;
background-color:blue;
}
.second-container .right{
height:100%;
width:40%;
margin-left:5%;
margin-right:5%;
float:left;
background-color:blue;
}
.third-container{
height:50px;
width:90%;
background-color:blue;
margin:5%;
}
.fourth-container{
height:70px;
width:90%;
margin:5%;
}
.fourth-container .left{
background-color:blue;
height:100%;
width:29%;
margin-right:2%;
margin-left:2%;
float:left;
}
.fourth-container .middle{
background-color:blue;
height:100%;
width:30%;
margin-right:2%;
margin-left:2%;
float:left;
}
.fourth-container .right{
background-color:blue;
height:100%;
width:29%;
margin-right:2%;
margin-left:2%;
float:left;
}
Of course, you can play with the values of margin if you want to adjust the way you want. Just take care of having 100% in total for a same line if you want it to look nice.
JSFiddle here : https://jsfiddle.net/zg1u2dnu/
Well... There are many ways to get this result. If you want to do it with pure HTML/CSS, Flexbox is probably the most convenient solution:
#wrapper {
width: 85%;
margin: auto;
display: flex;
flex-direction: column;
}
#wrapper > div {
margin: 10px;
}
.blue {
background-color: #4F81BD;
}
#top, #middle-bottom {
height: 100px;
}
#middle-top, #bottom {
height: 180px;
display: flex;
justify-content: space-between;
}
#middle-top > div {
width: 45%;
}
#bottom > div {
width: 30%;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Flexbox demo</title>
</head>
<body>
<div id="wrapper">
<div id="top" class="blue"></div>
<div id="middle-top">
<div class="blue"></div>
<div class="blue"></div>
</div>
<div id="middle-bottom" class="blue"></div>
<div id="bottom">
<div class="blue"></div>
<div class="blue"></div>
<div class="blue"></div>
</div>
</div>
</body>
</html>
However, like Vanilla JS, this will not work as expected in all web browsers... I recommend you to use front-end frameworks like Bootstrap, Foundation or Semantic UI for optimal results.

hovering over multiple divs

i have 6 divs I want to zoom the div I am currently active on
My code is:
#section1,#section2,#section3 ,#section4,#section5,#section6{
width:200px;
height:200px;
background:#41aacc;
margin:20px;
cursor:pointer;
}
#wrapper{
width:60%;
margin:0 auto;
display:flex;
align-items:center;
justify-content:center;
flex-wrap:wrap;
}
<div id="wrapper">
<div id="section1">
</div>
<div id="section2">
</div>
<div id="section3">
</div>
<div id="section4">
</div>
<div id="section5">
</div>
<div id="section6">
</div>
</div>
i do not want to use multiple selector like #selector1:hover{transform:scale(1.1)}and so on .How can I achieve it without iterating it for all the divs.
Thanks in advance.
You need to write
div[id^="section"] {...}
this selector will get all of divs with id value starting with "section"
or more specific
#wrapper > div[id^="section"] {...}
Look at snippet
#wrapper > div[id^="section"] {
width: 200px;
height: 200px;
background: #41aacc;
margin: 20px;
cursor: pointer;
transition: all .5s ease;
}
#wrapper{
width: 60%;
margin: 0 auto;
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
}
#wrapper > div[id^="section"]:hover
{
transform: scale(1.1);
}
<div id="wrapper">
<div id="section1">
</div>
<div id="section2">
</div>
<div id="section3">
</div>
<div id="section4">
</div>
<div id="section5">
</div>
<div id="section6">
</div>
</div>
Use a CSS class. The following applies the transformation to all block elements directly under the "wrapper" div.
CSS:
#wrapper div {
// applies to all divs under wrapper.
width:200px;
height:200px;
background:#41aacc;
margin:20px;
cursor:pointer;
}
#wrapper .hoverable:hover {
// applies only to "hoverable" class items when hovered.
transform:scale(1.1)
}
HTML:
<div id="wrapper">
<div id="section1" class="hoverable"></div>
<div id="section2" class="hoverable"></div>
<div id="section3" class="hoverable"></div>
<div id="section4" class="hoverable"></div>
<div id="section5" class="hoverable"></div>
<div id="section6" class="hoverable"></div>
</div>

nested float/nested row inside a column

I'm trying align two tables side by side in a floated left div. I think I've got how to horizontally align divs in general with floats but in my example below, once I create 3 columns, all floated left, I can't get the two tables in the 3rd column in the div.nestedHorizontalTables to display side by side. I tried display:inline-block but they still keep stacking vertically.
html
<div class="main-content">
<div class="column1">
<table>table1</table>
</div>
<div id="column2">
<!--I want a group of 4 vertical pie charts here-->
<div id="pie1"></div>
<div id="pie2"></div>
<div id="pie3"></div>
<div id="pie4"></div>
</div>
<div id="column3">
<div class="nestedHorizontalTables">
<table id="tab2">table2</table>
<table id="tab3">table3</table>
</div>
<table>Table4</table>
<div class="nestedHorizontalPieAndTable">
<table>table5</table>
<div id="pie6"></div>
</div>
</div>
</div>
css
#column1{
float:left;
width:40%;
}
#column2{
float:left;
width:20%;
}
#column3{
float:left;
width:40%;
}
.nestedHorizontalTables{
display:inline-block;
}
#tab2{
width:80%;
}
#tab3{
width:20%;
}
thanks
.main-content
{
margin:0;
padding:0;
float:left;
width:100%;
}
.column1 {
margin:0;
float: left;
width: 40%;
}
#column2 {
margin:0;
float: left;
width: 20%;
}
#column3 {
margin:0;
float: left;
width: 40%;
}
.nestedHorizontalTables {
display: inline-block;
}
#tab2 {
width: 80%;
}
#tab3 {
width: 20%;
}
<div class="main-content">
<div class="column1">
<table>table1</table>
</div>
<div id="column2">
<!--I want a group of 4 vertical pie charts here-->
<div id="pie1">hello</div>
<div id="pie2"></div>
<div id="pie3"></div>
<div id="pie4"></div>
</div>
<div id="column3">
<div class="nestedHorizontalTables">
<table id="tab2">table2</table>
<table id="tab3">table3</table>
</div>
<table>Table4</table>
<div class="nestedHorizontalPieAndTable">
<table>table5</table>
<div id="pie6"></div>
</div>
</div>
</div>
You may try this
If you just want the two tables inside nestedHorizontalTables to be displayed side by side, add float:left to both.
#tab2 {
width:80%;
float:left;
}
#tab3 {
width:20%;
float:left;
}
Here is a jsFiddle to help you.

Vertical align a div on the page (using bootstrap?)

I'm trying to align a div within my page so that it sits directly in the centre at all times. I've searched the site, but can't see any solutions for centring in the page rather than just a div.
Using bootstrap (3.2.0) I can centre it horizontally, but not vertically!
Here is my code so far:
HTML
<div class="slide">
<div class="container">
<div class="row">
<div class="logo col-md-4 col-md-offset-4">
<p>Test</p>
</div>
</div>
</div>
</div>
CSS
.logo {
border: solid;
border-color: red;
border-width: 5px;
height: 200px;
}
I tried verticle-align: middle;, margin:auto; & margin-top:auto; margin-bottom:auto; to no effect.
The closest I can get is to use margin-top: 20%; but this doesn't shrink as the page height does.
There is no magical way in bootstrap to do it. You need a helper div wrapper in order to immolate a table structure.
<div class="slide">
<div class="container">
<div class="row">
<div class="logo col-md-4 col-md-offset-4">
<div class="helper">
<span>Test</span>
</div>
</div>
</div>
</div>
</div>
.logo {
border: solid;
border-color: red;
border-width: 5px;
height: 200px;
}
.helper{
background:#ccc;
width:100%;
height:100%;
text-align:center;
display:table;
}
span{
display:table-cell;
vertical-align:middle;
}

auto width div boxes

This has possibly been answered a couple of times before but I just can't find this answer to my specific problem.
I've been working on this: http://jsfiddle.net/LPGGh/
<div class="wrapper">
<div class="project">
<div class="media"></div>
<div class="text">Text</div>
</div>
<div class="project">
<div class="media"></div>
<div class="text">Text</div>
</div>
<div class="project">
<div class="media"></div>
<div class="text">Text</div>
</div>
.media{
width: 300px;
height:200px;
background-color:red;
margin-bottom:1em;
}
.text{
margin-bottom:2em;
}
.project{
display: inline-block;
margin-left: 1em;
margin-right: 1em;
}
.wrapper{
margin-top: 1.65em;
width: 100%;
}
My question is how I get the .media to auto fit in width so the red boxes always uses all of the space available and still keep the margins of course?
Thanks!
I used your fiddle, so the names are a little different in my answer.
Here is a solution by creating a wrapper for the media element:
<div class="project_container_parent">
<div class="project_container_child">
<div class="media_parent"><div class="media"></div></div>
<div class="text">Text</div>
</div>
<div class="project_container_child">
<div class="media_parent"><div class="media"></div></div>
<div class="text">Text</div>
</div>
<div class="project_container_child">
<div class="media_parent"><div class="media"></div></div>
<div class="text">Text</div>
</div>
</div>
And setting the css like this:
.media{
width:100%;
height:200px;
background-color:red;
margin-bottom:1em;
}
.media_parent{
margin-left:1em;
margin-right:1em;
}
.text{
margin-bottom:2em;
}
.project_container_child{
display: inline-block;
width:100%;
}
.project_container_parent{
margin-top: 1.65em;
}
Here is your modified fiddle: http://jsfiddle.net/LPGGh/13/