hovering over multiple divs - html

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>

Related

2 columns that resize based on the content in one of the divs

I know this may seem basic, but I am looking for the cleanest solution for this. I have a container DIV with 2 divs located inside of it. I need one to stay on the left and take up approximately 75% of the container, while the right takes up 25%....... but ONLY if there is content in the right div, if not the left div should take up 100% of the container.
What is the easiest, cleanest solution for this?
You just have to use float.
Example with content on the right:
#right {
width: 25%;
float: right;
background: red;
}
#left {
width: 100%;
background: green;
}
<div id="main">
<div id="right">
right
</div>
<div id="left">
left
</div>
</div>
Example without content on the right:
#right {
width: 25%;
float: right;
background: red;
}
#left {
width: 100%;
background: green;
}
<div id="main">
<div id="right">
</div>
<div id="left">
left
</div>
</div>
You should use flexbox and set the min-width of the left container to 75%:
.container {
padding:20px;
background-color:black;
display:flex;
color:white;
}
.left {
flex:1;
height:100px;
background-color:red;
min-width:75%;
}
.right {
height:100px;
background-color:blue;
}
<div class="container">
<div class="left"></div>
<div class="right">
totot
tototo
tititi
tototot
tototoot
</div>
</div>
<div class="container">
<div class="left"></div>
<div class="right">
to
</div>
</div>
<div class="container">
<div class="left"></div>
<div class="right">
</div>
</div>

Make div appear next to other

I have started a huge revision on my css knowledge.
I am trying to do the following:
I want to create a wrapper div that contains to divs with some text and some content.I want each div with class item-2 inside that div to have a width:50%
and appear next to another item-2.
Here is a snippet of my code:
body{
background:rgba(10,10,10,.8);
}
.wrapper{
position:relative;
width:100%;
margin:auto;
}
.item-2{
text-align:center;
display:inline-block;
width:50%;
border:2px solid blue;
}
.demo{
margin:auto;
height:5em;
width:5em;
background:yellow;
}
<div class='wrapper'>
<div class='item-2'>
<h1>Title 1</h1>
<div class='demo'>
</div>
</div>
<div class='item-2'>
<h1>Title 1</h1>
<div class='demo'>
</div>
</div>
</div>
As you can see it's div appears below its previous div.However I want them to be next to each other.How can I achieve this? I would like an explanation to your solution sa as to improve my knowledge
Flex can keep them in one row.
.wrapper {
display: flex;
}
And remove display: inline block for items. If you want in small devices they are under each other add this to .wrapper
flex-wrap: wrap;
And we need a min-width for items. .items: min-width: 250px;. If your device has enough space (500px) they will remain in one line, else the second item goes to next line.
.wrapper display: flex;
.item-2 flex: 1;
Why is this happening?
Using inline-block in this way is perfectly valid and will work but you have two issues that are causing the elements to occupy separate lines:
inline-block items honour the white-space between elements so there is an extra space between the two .item-2 divs
The width of .item-2 is not 50% but 50% + 2px left border + 2px right border
How to fix
There are multiple ways of getting round the white-space issue including setting font-size: 0;, however, as the height and width of .demo use ems you are probably best removing the white-space from between the elements in the HTML instead
To ensure .item-2 actually has a width of 50% you can add box-sizing: border-box; which will make the width and height include the padding and border
body {
background: rgba(10, 10, 10, .8);
}
.wrapper {
margin: auto;
position: relative;
width: 100%;
}
.item-2 {
border: 2px solid blue;
box-sizing: border-box;
display: inline-block;
text-align: center;
width: 50%;
}
.demo {
background: yellow;
height: 5em;
margin: auto;
width: 5em;
}
<div class='wrapper'>
<div class='item-2'>
<h1>Title 1</h1>
<div class='demo'>
</div>
</div><!--You can remove the white-space by adding a comment between the elements
--><div class='item-2'>
<h1>Title 1</h1>
<div class='demo'>
</div>
</div>
</div>
Try this code...
body{
background:rgba(10,10,10,.8);
}
.wrapper{
position:relative;
width:100%;
margin:auto;
}
.item-2{
float:left;
text-align:center;
box-sizing: border-box;
display:inline-block;
width:50%;
border:2px solid blue;
}
.demo{
margin:auto;
height:5em;
width:5em;
background:yellow;
}
<div class='wrapper'>
<div class='item-2'>
<h1>Title 1</h1>
<div class='demo'>
</div>
</div>
<div class='item-2'>
<h1>Title 1</h1>
<div class='demo'>
</div>
</div>
</div>
aside float and flex, there's also:
display:table;
body{
background:rgba(10,10,10,.8);
}
.wrapper{
position:relative;
width:100%;
margin:auto;
display:table;
table-layout:fixed;/* to even cells and keep within width set */
}
.item-2{
text-align:center;
display:table-cell;
border:2px solid blue;
}
.demo{
margin:auto;
height:5em;
width:5em;
background:yellow;
}
<div class='wrapper'>
<div class='item-2'>
<h1>Title 1</h1>
<div class='demo'>
</div>
</div>
<div class='item-2'>
<h1>Title 1</h1>
<div class='demo'>
</div>
</div>
</div>
display:grid;
body{
background:rgba(10,10,10,.8);
}
.wrapper{
position:relative;
width:100%;
margin:auto;
display:grid;
grid-template-columns:50% 50%;
}
.item-2{
text-align:center;
border:2px solid blue;
}
.demo{
margin:auto;
height:5em;
width:5em;
background:yellow;
}
<div class='wrapper'>
<div class='item-2'>
<h1>Title 1</h1>
<div class='demo'>
</div>
</div>
<div class='item-2'>
<h1>Title 1</h1>
<div class='demo'>
</div>
</div>
</div>

How to create grid fluid responsive consist of three boxes?

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%;
}

Vertically aligning selected div

Currently, my div content is in horizontal style, I want to make the another div content to be position vertically. For my case i want to vertically align my content1 element
This is how i want the css to look like
This is my html code:
<div id="binder">
<div id="content">
<div>
<h1>Title</h1>
</div>
<br/>
<div id="map">
</div>
</div>
<div id="content1">
</div>
<div id="sidebar">
</div>
</div>
This the css code:
#binder{
display:-webkit-box;
-webkit-box-orient:horizontal;
}
#content{
font:14px Calibri;
border:1px solid #3EA99F;
-webkit-box-flex:1;
margin:20px;
padding:20px;
}
#sideBar{
border:1px solid #3EA99F;
width:450px;
margin:20px;
padding:30px;
background:#3EA99F;
}
How to do it?
Eventually you can do it without using flexbox too.
Code example:
*{
box-sizing:border-box;
margin:0;
padding:0;
}
.content-wrapper,
#sidebar{
float: left;
}
.content-wrapper{
width:70%;
}
#content,
#content1,
#sidebar {
border: 1px solid red;
}
#sidebar {
width: 30%;
}
<div id="binder">
<div class="content-wrapper">
<div id="content">
<div>
<h1>Content div</h1>
</div>
<br/>
<div id="map">
</div>
</div>
<div id="content1">
<h3>
Content1 div
</h3>
</div>
</div>
<div id="sidebar">
<h3>
Sidebar div
</h3>
</div>
</div>
Notes
I added a .container-wrapper div as parent of both #content and #content1
I placed .container-wrapper and #sidebar next to each other with float:left
In this case the height of the containers is set automatically based on their content, but if you want you can specify a fixed value adding a height:..px to the corresponding class/id
change
#binder{
display:-webkit-box;
-webkit-box-orient:horizontal;
}
to
#binder{
display: flex;
flex-direction: column;
flex-wrap: wrap;
}
as the explanation is not much enough, please check the JsFiddle and please explain if it is not as you expected
EDIT:
Thank you for providing the images.
change the html into
<div id="binder">
<div class="content-wrapper">
<div id="content">
<div>
<h1>Title</h1>
</div>
<br/>
<div id="map">
</div>
</div>
<div id="content1">
CONTENT 1
</div>
</div>
<div id="sidebar">
SIDEBAR
</div>
change the css to
#binder{
display:flex;
flex-direction: row;
}
.content-wrapper{
display:flex;
flex-direction: column;
}
#sidebar{
font:14px Calibri;
border:1px solid #3EA99F;
-webkit-box-flex:1;
margin:20px;
padding:20px;
}
check the jsFiddle for more

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/