Making a div expand to all the screen overlaying other divs - html

I have a 2 by 2 grid of divs displaying each time I enter the page that fills the entire browser screen.
I want to make it in a way that if I hover over each of the divs that one will fullscreen expand over the other three, hiding them while those stay still.
What I have right now doesn't quite work because when I hover over one of the divs it moves all the other ones and ruins the screen. I would really appreciate any advice.
HTML (it's just this inside the body):
<div class="box" id="sup-izq"></div>
<div class="box" id="sup-der"></div>
<div class="box" id="inf-izq"></div>
<div class="box" id="inf-der"></div>
CSS:
.box {
box-sizing: border-box;
float: left;
width: 50%;
height: 50%;
z-index: 1;
-webkit-transition: width 1s, height 1s;
transition: width 1s, height 1s;
}
.box:hover {
width: 100%;
height: 100%;
}
#sup-izq {
border-right: 1px solid black;
border-bottom: 1px solid black;
background-color: #8cff66;
}
#sup-der {
border-left: 1px solid black;
border-bottom: 1px solid black;
background-color: #ff751a;
}
#inf-izq {
border-top: 1px solid black;
border-right: 1px solid black;
background-color: #3385ff;
}
#inf-der {
border-top: 1px solid black;
border-left: 1px solid black;
background-color: #d147a3;
}

The best and most performant way to do that is to use transform: scale and transform-origin
The scale(2) will double its size in both directions (width/height) and the transform-origin, which defaults to center center (50% 50%), controls the origin.
Note, for an element to have a height set in precent, its parent need a height, hence I added the html, body rule. Another option would be to use viewport units vw/vh
html, body { /* added rule */
margin: 0;
height: 100%;
}
.box {
position: relative;
box-sizing: border-box;
float: left;
width: 50%;
height: 50%;
z-index: 0;
transition: transform 0.5s, /* changed property */
z-index 0.5s;
}
.box:hover {
transform: scale(2); /* added property */
z-index: 10; /* added so hovered is on top */
}
#sup-izq {
border-right: 1px solid black;
border-bottom: 1px solid black;
background-color: #8cff66;
transform-origin: left top; /* added property */
}
#sup-der {
border-left: 1px solid black;
border-bottom: 1px solid black;
background-color: #ff751a;
transform-origin: right top; /* added property */
}
#inf-izq {
border-top: 1px solid black;
border-right: 1px solid black;
background-color: #3385ff;
transform-origin: left bottom; /* added property */
}
#inf-der {
border-top: 1px solid black;
border-left: 1px solid black;
background-color: #d147a3;
transform-origin: right bottom; /* added property */
}
<div class="box" id="sup-izq"></div>
<div class="box" id="sup-der"></div>
<div class="box" id="inf-izq"></div>
<div class="box" id="inf-der"></div>

This is rough and ready, but works. The approach was to wrap everything in a relatively positioned wrapper, then position the squares absolutely. That way they can have a z-index, which was the crux of the matter.
.wrap {
position: relative;
height: 500px;
}
.box {
display: block;
width: 50%;
height: 50%;
z-index: 1;
-webkit-transition: width 1s, height 1s;
transition: width 1s, height 1s;
position: absolute;
}
.box:hover {
width: 100%;
height: 100%;
z-index: 2;
}
#sup-izq {
top: 0px;
left: 0px;
border-right: 1px solid black;
border-bottom: 1px solid black;
background-color: #8cff66;
}
#sup-der {
top: 0px;
right: 0px;
border-left: 1px solid black;
border-bottom: 1px solid black;
background-color: #ff751a;
}
#inf-izq {
bottom: 0px;
left: 0px;
border-top: 1px solid black;
border-right: 1px solid black;
background-color: #3385ff;
}
#inf-der {
bottom: 0px;
right: 0px;
border-top: 1px solid black;
border-left: 1px solid black;
background-color: #d147a3;
}
<div class="wrap">
<div class="box" id="sup-izq"></div>
<div class="box" id="sup-der"></div>
<div class="box" id="inf-izq"></div>
<div class="box" id="inf-der"></div>
</div>

Related

Tabs with hidden margin: how to solve? [duplicate]

This question already has answers here:
How to remove the space between inline/inline-block elements?
(41 answers)
Closed 1 year ago.
I am trying to implement tabs in our application. I've got a CSS problem where somehow I am adding padding or magin to the right of every tab-item
See my problem in here: JSFiddle
As you can see in the Fiddle, the first tab-item is currently active. However, there is some padding to the right of the item. Because of this padding/margin, the bottom border starts a few pixels too soon.
What am I doing wrong here?
.tabs2 {
border-bottom: 1px solid red;
}
.tabs2-wrap {
margin-bottom: -1px;
position: relative;
}
.tablist {
transform: translateX(0px);
border: 1px solid red;
border-bottom: none;
border-radius: 4px 4px 0 0;
width: max-content;
}
.tabs2-item {
padding: 0 20px;
height: 40px;
line-height: 40px;
display: inline-block;
position: relative;
border-left: 1px solid red;
/* ** Hacky solution ** */
/* margin-left: -4px; */
}
.tabs2-item:first-child {
border-left: none;
}
.tabs2-isActive {
border-bottom: 1px solid #fff;
color: #409eff;
}
<div class="tabs2">
<div class="tabs2-wrap">
<div class="tablist">
<div class="tabs2-item tabs2-isActive">Algemeen</div>
<div class="tabs2-item">Vertrouwelijk</div>
<div class="tabs2-item">Historie</div>
<div class="tabs2-item">Kaasboer</div>
</div>
</div>
</div>
you try with display flex:
But why does this problem occur?
Because the display inline-block considers empty characters and spaces as part of block;
.tabs2 {
border-bottom: 1px solid red;
}
.tabs2-wrap {
margin-bottom: -1px;
position: relative;
}
.tablist {
transform: translateX(0px);
border: 1px solid red;
border-bottom: none;
border-radius: 4px 4px 0 0;
width: max-content;
display:flex;
}
.tabs2-item {
padding: 0 20px;
height: 40px;
line-height: 40px;
display: inline-block;
position: relative;
border-left: 1px solid red;
/* ** Hacky solution ** */
/* margin-left: -4px; */
}
.tabs2-item:first-child {
border-left: none;
}
.tabs2-isActive {
border-bottom: 1px solid #fff;
color: #409eff;
}
<div class="tabs2">
<div class="tabs2-wrap">
<div class="tablist">
<div class="tabs2-item tabs2-isActive">Algemeen</div>
<div class="tabs2-item">Vertrouwelijk</div>
<div class="tabs2-item">Historie</div>
<div class="tabs2-item">Kaasboer</div>
</div>
</div>
</div>
and other solution: remove white-space from html without flex:
.tabs2 {
border-bottom: 1px solid red;
}
.tabs2-wrap {
margin-bottom: -1px;
position: relative;
}
.tablist {
transform: translateX(0px);
border: 1px solid red;
border-bottom: none;
border-radius: 4px 4px 0 0;
width: max-content;
display:flex;
}
.tabs2-item {
padding: 0 20px;
height: 40px;
line-height: 40px;
display: inline-block;
position: relative;
border-left: 1px solid red;
/* ** Hacky solution ** */
/* margin-left: -4px; */
}
.tabs2-item:first-child {
border-left: none;
}
.tabs2-isActive {
border-bottom: 1px solid #fff;
color: #409eff;
}
<div class="tabs2">
<div class="tabs2-wrap">
<div class="tablist">
<div class="tabs2-item tabs2-isActive">Algemeen</div><div class="tabs2-item">Vertrouwelijk</div><div class="tabs2-item">Historie</div><div class="tabs2-item">Kaasboer</div>
</div>
</div>
</div>
Looking at your CSS, you have the left and right padding on all tabs2-item elements set to 20px. Then the CSS under the first-child selector turns off the padding to the left of the first tabs2-item element (leaving the padding on the right).

Make text in the middle of CSS shapes

.myButton {
float: right;
border-top: 40px solid pink;
border-left: 40px solid transparent;
border-right: 0px solid transparent;
width: 25%;
}
<div class="myButton">
Submit
</div>
The above is my code. As you can see I want to design a shape like the image below but I want the word Submit to be in the center but it is pushed down.
Anyone know a solution?
You can use linear-gradient background for this. Techique is based on setting fixed height and then applying padding equals height multiplied by √2:
.my-button {
border: 0;
height: 40px;
background: linear-gradient(45deg, transparent 40px, pink 40px);
padding-left: 56.5691px; /* 40 × √2 ≈ 56.5691 */
}
<button class="my-button">Submit</button>
Also you can achieve this via absolutely position pseudoelement:
.my-button {
background-color: pink;
position: relative;
height: 40px;
margin-left: 40px;
border: 0;
}
.my-button:after {
content: "";
position: absolute;
top: 0;
left: 0;
/* Move pseudoelement to the left to 100% of its width */
transform: translateX(-100%);
border-top: 40px solid pink;
border-left: 40px solid transparent;
border-right: 0px solid transparent;
}
<button class="my-button">Submit</button>
The issue with what you have is that you're using a top border instead of a background so your text naturally won't look to be in the center of your shape. What you can do is use positioning to manually move your text up within the shape:
.myButton {
float: right;
border-top: 40px solid pink;
border-left: 40px solid transparent;
border-right: 0px solid transparent;
width: 25%;
position: relative;
}
.inner {
position: absolute;
top: -30px;
left: 40px;
}
<div class="myButton">
<div class="inner">Submit</div>
</div>

Slider Header using CSS

I have been trying to create an image like this using css.
which I partly achieved like this
<div class="nav-tab">
<div class="arrow-left"></div>
<div class="arrow"></div>
<div class="arrow-right"></div>
</div>
CSS
div {
float: left;
margin: 0;
padding: 0;
}
.arrow {
background-color: green;
height: 60px;
width: 240px;
}
.arrow-right {
width: 0;
height: 0;
border-top: 30px solid transparent;
border-bottom: 30px solid transparent;
border-left: 30px solid green;
}
.arrow-left {
width: 0;
height: 0;
border-top: 30px solid transparent;
border-bottom: 30px solid transparent;
border-left: 30px solid white;
position: relative;
left: 30px;
}
Fiddle: https://jsfiddle.net/codeandcloud/g3cmgw8y/6/
But the design has these problems
1) The arrow-left not having background-color transparent. ( Is it possible as per this design? )
2) What I want is to use it as the image below. When I put each .nav-tab in a ul > li with float:left the output is garbled.
Fiddle: https://jsfiddle.net/g3cmgw8y/7/
What am I doing wrong and how should I fix this.
How about using skew instead?
https://jsfiddle.net/foreyez/1gf3zam3/
<div class='arrow'>
<div class='arrowtop'>
</div>
<div class='arrowbottom'>
</div>
</div>
.arrowtop {
transform: translateX(50px) skewX(45deg);
width:400px;
height:50px;
background:red;
}
.arrowbottom {
transform: translateX(50px) skewX(-45deg);
width:400px;
height:50px;
background:red;
}
Hmm ... maybe this's an answer ?
.arrow-left {
border-top: 30px solid green;
border-bottom: 30px solid green;
border-left: 30px solid transparent;
position:relative;
left: 0px;
}

Transition input width

I have the input search field. When I click on it I need it to become wider performing smooth transition from right to left, i.e. the input is located on the right side of the page and when I click on it it should stretch to the left in some number of pixels and become wider.
Here's my css:
#header #search input {
background: #FFF;
padding: 1px 1px 1px 5px;
width: 178px;
height: 21px;
border: 1px solid #CCCCCC;
border-radius: 6px;
-webkit-transition: all .5s;
-moz-transition: all .5s;
transition: all .5s;
}
#header #search input:focus {
background: #FFF;
padding: 1px 1px 1px 5px;
width: 300px;
height: 21px;
border: 1px solid #CCCCCC;
Could you help me with implementing that?
input[type="search"] {
background: #FFF;
padding: .5rem 1rem;
position: relative;
top: 0;
left: 0;
width: 178px;
height: 40px;
outline: none;
border: 1px solid #CCCCCC;
border-radius: 6px;
transition: all .5s;
}
input[type="search"]:focus {
width: 300px;
top: 0;
right: 100%;
}
<div style="text-align:right;">
<input type="search" id="search" />
</div>
Position the input absolutely and set the right property to zero:
position:absolute;
right:0;
That forces the expansion to the left when focused.
jsFiddle example
Make your containers offset parents using position: relative.
#header, #search {
width: 100%;
position: relative;
}
Then position your input using position: absolute and place it using right.
#header #search input {
position: absolute;
right: 0px;
background: #FFF;
padding: 1px 1px 1px 5px;
width: 178px;
height: 21px;
border: 1px solid #CCCCCC;
border-radius: 6px;
-webkit-transition: all .5s;
-moz-transition: all .5s;
transition: all .5s;
}
#header #search input:focus {
background: #FFF;
padding: 1px 1px 1px 5px;
width: 300px;
height: 21px;
border: 1px solid #CCCCCC;
Your animation will now stretch to the left.

Make a CSS triangle with transparent background on a div with white bg image?

Ok so, I'm trying to replicate the effect you see here at the bottom of the page, with the back to top button: http://www.ppp-templates.de/tilability/ - After the content area for We stay connected.
basically he's using a background image for that and I'd like to replicate it with CSS and keep the same effect.
I know how to create triangles with CSS with borders, but in my case I'd like to use the transparent bg image and not a color so I can't use borders
I removed the background image and used #FFF on the whole div, so it's all white now... I created a new div in which I added the back to top button and added background: transparent to it so it's transparent, but how do I create the triangle via CSS?
Any help is greatly appreciated.
The Fiddle:
http://jsfiddle.net/JaMH9/2/
The HTML:
<div class="bar">
<span class="home">^<br>Home, sweet home!</span>
</div>​
The CSS:
.bar {
position: relative;
width: 90%;
height: 30px;
margin: 0 auto;
}
.home {
position: absolute;
top: 0px;
left: 60%;
width: 20%;
text-align: center;
}
.bar:before, .bar:after {
content:'';
position: absolute;
top: 0;
height: 0;
border-top: 30px solid white;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
box-sizing: border-box;
}
.bar:before {
left: 0;
width: 70%;
border-right: 30px solid transparent;
}
.bar:after {
right:0;
width: 30%;
border-left: 30px solid transparent;
}
​
Here's one way to make a triangle with fairly minimal markup and css:
HTML:
<div class="triangle"></div>
CSS:
.triangle {
width: 0;
height: 0;
border-left: 35px solid transparent;
border-right: 35px solid transparent;
border-bottom: 35px solid gray;
}
http://jsbin.com/iribib/21
Here you go, http://jsfiddle.net/pkUx7/1/
HTML
<body>
<div id = "footer"></div>
<div id = "bottom-line-left"></div>
<div id = "triangle"></div>
<div id = "bottom-line-right"></div>
</body>
CSS
body {
background-color: purple;
}
div {
margin:0;
padding:0;
background-color: violet;
}
#footer {
height: 100px;
}
#bottom-line-left, #bottom-line-right {
display: inline-block;
height: 20px;
}
#bottom-line-left {
width: 61%;
}
#bottom-line-right {
float: right;
width: 37%;
}
#triangle {
margin-left:-6px;
margin-right: -4px;
padding:0;
display: inline-block;
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-bottom: 20px solid purple;
}
I just threw this together, there's probably a better way to achieve this effect.
HTML
<div class="div1">Lorem Ipsum</div>
<div class="div2"></div>
<div class="div3"></div>
<div class="div4"></div>
CSS
body {
background-color: gray;
border: 20px solid gray;
}
.div1 {
background-color: white;
border: 20px solid white;
}
.div2 {
float: right;
border-top: 20px solid white;
border-right: 20px solid white;
border-left: 20px solid transparent;
}
.div3 {
float: right;
margin: 10px -20px;
border-bottom: 20px solid white;
border-right: 20px solid transparent;
border-left: 20px solid transparent;
}
.div4 {
border-top: 20px solid white;
border-right: 20px solid transparent;
margin-right: 40px;
}
See it here.
You can use vector path.
For instance, transparent triangle with green border:
<svg height="151" width="150">
<path d="m0 150 h150 l -75 -150 z" fill="transparent" stroke="green" />
</svg>
See it here.