How to overlay div without effecting position of other div elements - html

I am attempting to add the wrapperleft and wrapperright divs inside of the bareEditorial div without it affecting the positioning of any of the elements within the bareEditorial div. I want the cursor to change from the left 50% of the viewport to the right 50% within this div
Does anyone have any suggestions on how to achieve this?
Here is my pen https://codepen.io/anon/pen/XQeGMZ
.wrapperleft {
width: 50vw;
display: inline-block;
cursor: url("data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB3aWR0aD0iNDBweCIgaGVpZ2h0PSIyNnB4IiB2aWV3Qm94PSIwIDAgNDAgMjYiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+CiAgICA8IS0tIEdlbmVyYXRvcjogU2tldGNoIDQxLjEgKDM1Mzc2KSAtIGh0dHA6Ly93d3cuYm9oZW1pYW5jb2RpbmcuY29tL3NrZXRjaCAtLT4KICAgIDx0aXRsZT5TaGFwZTwvdGl0bGU+CiAgICA8ZGVzYz5DcmVhdGVkIHdpdGggU2tldGNoLjwvZGVzYz4KICAgIDxkZWZzPjwvZGVmcz4KICAgIDxnIGlkPSJQYWdlLTEiIHN0cm9rZT0ibm9uZSIgc3Ryb2tlLXdpZHRoPSIxIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPgogICAgICAgIDxwb2x5Z29uIGlkPSJTaGFwZSIgZmlsbD0iIzAwMDAwMCIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMjAuMDAwMDAwLCAxMi44MDIwMDApIHNjYWxlKC0xLCAxKSB0cmFuc2xhdGUoLTIwLjAwMDAwMCwgLTEyLjgwMjAwMCkgIiBwb2ludHM9IjI3LjE5OCAyNS42MDQgMzkuNDk0IDEzLjMwOCA0MCAxMi44MDIgMzkuNDk0IDEyLjI5NiAyNy4xOTggMCAyNi4xODUgMS4wMTIgMzcuMjYgMTIuMDg2IDAgMTIuMDg2IDAgMTMuNTE4IDM3LjI2IDEzLjUxOCAyNi4xODUgMjQuNTkyIj48L3BvbHlnb24+CiAgICA8L2c+Cjwvc3ZnPg=="), auto;
}
.wrapperright {
width: 50vw;
display: inline-block;
float: right;
cursor: url("data:image/svg+xml;base64,PHN2ZyB3aWR0aD0nNDAnIGhlaWdodD0nMjYnIHZpZXdCb3g9JzAgMCA0MCAyNicgeG1sbnM9J2h0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnJz48cGF0aCBkPSdNMjcuMTk4IDI2LjYwNGwxMi4yOTYtMTIuMjk2LjUwNi0uNTA2LS41MDYtLjUwNkwyNy4xOTggMWwtMS4wMTMgMS4wMTJMMzcuMjYgMTMuMDg2SDB2MS40MzJoMzcuMjZMMjYuMTg1IDI1LjU5MnonLz48L3N2Zz4K"), auto;
}
<div class="wrapperleft" onclick="plusSlides(-1)"></div>
<div class="wrapperright" onclick="plusSlides(1)"></div>
<div class="bareEditorial">
<div class="slideshow-container">
<h1>Bare Boutique Campaign</h1>
<div class="mySlides fade">
<div class="image">
<img src="https://static1.squarespace.com/static/5a24d00449fc2b2179f0b620/t/5c7118acc830251242312b94/1550915797860/web+7.jpg?format=2500w" onclick="plusSlides(1)">
</div>
</div>
<div class="mySlides fade">
<div class="image">
<img src="https://static1.squarespace.com/static/5a24d00449fc2b2179f0b620/5c7116541905f442e8f008e0/5c7124951905f442e8f048fd/1550918837321/web+3.jpg?format=1000w" onclick="plusSlides(1)">
</div>
</div>
<div class="mySlides fade">
<div class="image">
<img src="https://static1.squarespace.com/static/5a24d00449fc2b2179f0b620/t/5c711846ec212dd3a55665b8/1550915727165/web+5.jpg?format=2500w" onclick="plusSlides(1)">
</div>
</div>
<div class="nextprevious">
<div class="numbertext">(<span>3</span> / <span>3</span>)</div>
</div>
</div>
</div>

Hi you can use "position: absolute" as the css property to adjust Divs without affecting other elements.
I have edited your css, you can go through it n replace and check once,
.wrapperleft {
width: 50vw;
cursor: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiP…M3LjI2IDEzLjUxOCAyNi4xODUgMjQuNTkyIj48L3BvbHlnb24+CiAgICA8L2c+Cjwvc3ZnPg==), auto;
height: 50px;
background: blue;
position: absolute;
left: 0;
}
.wrapperright {
width: 50vw;
float: right;
cursor: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0nNDAnIGhlaWdodD0nMjYnIHZpZXdCb3g9J…4wMTJMMzcuMjYgMTMuMDg2SDB2MS40MzJoMzcuMjZMMjYuMTg1IDI1LjU5MnonLz48L3N2Zz4K), auto;
height: 50px;
background: red;
position: absolute;
right: 0;
}

Related

How can I make an anchor element cover an entire div element?

I want when clicking anywhere on the div.parent to act as a link without including the tag in the entire div.des
I try to many times but unable to do it.
div.parent {
background-color: gray;
padding: 5px;
}
a {
width: 100px;
height: 100px;
display: block;
background-color: white
}
<div style="display: flex;justify-content: center;gap: 20px">
<div class="parent">
<div class="des">
<p>Title</p>
<i>Price</i>
</div>
</div>
<div class="parent">
<div class="des">
<p>Title</p>
<i>Price</i>
</div>
</div>
</div>
If you don't want to just wrap your div with the anchor we can learn from Bootstrap's stretched links and use an absolutely-positioned pseudo-element on the anchor.
div.parent {
background-color: gray;
padding: 5px;
position: relative;
}
a {
width: 100px;
height: 100px;
display: block;
background-color: white
}
a::after {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
<div style="display: flex;justify-content: center;gap: 20px">
<div class="parent">
<div class="des">
<p>Title</p>
<i>Price</i>
</div>
</div>
<div class="parent">
<div class="des">
<p>Title</p>
<i>Price</i>
</div>
</div>
</div>

How to place card over image in bootstrap?

I'm now working on a website. I tried several times to place the card over the picture. Can you have any suggestions?https://i.stack.imgur.com/goigA.png
one way is set minus margin-top for example: margin-top : -100px
.tag {
position: relative;
left: 0px;
background-color: green;
z-index: 1000;
margin-top: -50px;
width: 100px;
height: 100px;
margin-right: 20px;
}
.d-flex{
display: flex;
}
<div class="container">
<img src="https://homepages.cae.wisc.edu/~ece533/images/arctichare.png">
<div class="d-flex">
<div class="tag">Featured</div>
<div class="tag">Featured</div>
<div class="tag">Featured</div>
<div class="tag">Featured</div>
</div>
</div>

Flexbox square items independent of item count

I use some inline styling in the HTML Doc. I would like to achieve a flexbox with n divisions where divs are squared. Within these divs I want to add certain images (here a placeholder)
I was looking up some other threads where there was padding used as a measure to adjust the box "height" since it is calculated upon width. However this solution only expands the current box in height (outlined with the blue border).
Has anyone a tip on how to avoid this?
EDIT: Apparently the padding solution works while using units like vh and vw instead of percentage and as long as I do not insert an image
.container {
position: relative;
width: 90%;
max-height: 35%;
display: flex;
margin: 5%;
border: 5px solid black;
justify-content: space-around;
}
.box {
position: relative;
width: 100%;
margin: 2.5%;
border: 5px solid blue;
overflow: hidden;
}
.image {
position: relative;
width: 100%;
}
<div class="container">
<div class="box">
<img class="image" src="https://images.unsplash.com/photo-1611817757571-75fe5c08ffd9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80" />
</div>
<div class="box">
<img class="image" src="https://images.unsplash.com/photo-1611817757571-75fe5c08ffd9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80" />
</div>
<div class="box">
<img class="image" src="https://images.unsplash.com/photo-1611817757571-75fe5c08ffd9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80" />
</div>
<div class="box">
<img class="image" src="https://images.unsplash.com/photo-1611817757571-75fe5c08ffd9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80" />
</div>
<div class="box">
<img class="image" src="https://images.unsplash.com/photo-1611817757571-75fe5c08ffd9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80">
</div>
</div>
We now have access to aspect-ratio in CSS although it is poorly supported at the time of writing.
The aspect-ratio CSS property sets a preferred aspect ratio for the box, which will be used in the calculation of auto sizes and some other layout functions.
.container {
width: 90%;
max-height: 35%;
display: flex;
margin: 5%;
border: 5px solid black;
justify-content: space-around;
}
.box {
margin: 2.5%;
flex: 1;
aspect-ratio: 1;
border: 5px solid blue;
overflow: hidden;
}
.image {
max-width: 100%;
display: block;
}
<div class="container">
<div class="box">
<img class="image" src="https://images.unsplash.com/photo-1611817757571-75fe5c08ffd9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80" />
</div>
<div class="box">
<img class="image" src="https://images.unsplash.com/photo-1611817757571-75fe5c08ffd9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80" />
</div>
<div class="box">
<img class="image" src="https://images.unsplash.com/photo-1611817757571-75fe5c08ffd9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80" />
</div>
<div class="box">
<img class="image" src="https://images.unsplash.com/photo-1611817757571-75fe5c08ffd9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80" />
</div>
<div class="box">
<img class="image" src="https://images.unsplash.com/photo-1611817757571-75fe5c08ffd9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80">
</div>
</div>
To manage this, there is a little known trick (tbh I didn't know you could do this) with setting an aspect ratio on divs of unknown/dynamic widths. See this article.
I ended up adding position: absolute for the images to not mess with the height of the divs after applying this 1:1 ratio for your scenario:
.box:before {
content: "";
float: left;
padding-top: 100%; /* initial ratio of 1:1*/
}
This might be what you are trying to do:
.container {
position: relative;
width: 90%;
max-height: 35%;
display: flex;
margin: 5%;
border: 5px solid black;
justify-content: space-around;
}
.box {
position: relative;
width: 100%;
margin: 2.5%;
border: 5px solid blue;
overflow: hidden;
}
.box:before {
content: "";
float: left;
padding-top: 100%; /* initial ratio of 1:1*/
}
.image {
position: absolute;
width: 100%;
}
<div class="container">
<div class="box">
<img class="image" src="https://images.unsplash.com/photo-1611817757571-75fe5c08ffd9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80" />
</div>
<div class="box">
<img class="image" src="https://images.unsplash.com/photo-1611817757571-75fe5c08ffd9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80" />
</div>
<div class="box">
<img class="image" src="https://images.unsplash.com/photo-1611817757571-75fe5c08ffd9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80" />
</div>
<div class="box">
<img class="image" src="https://images.unsplash.com/photo-1611817757571-75fe5c08ffd9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80" />
</div>
<div class="box">
<img class="image" src="https://images.unsplash.com/photo-1611817757571-75fe5c08ffd9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80">
</div>
</div>

Fill flexible container with centered square component

What I try to achieve is shown on following pictures:
Outer rectangle is a div container that can have any size and ratio (it gets resized with browser window resizing), and inside is a component (filled on pictures) that should maintain a 1:1 ratio (square), and should be centered in the container. So its sides are described with the formula min(container_width, container_height).
Any ideas on how to do this?
This can be achieved with a combination of three things:
Flexbox
CSS variables
The calc() function
Flexbox can be used to ensure that the inner element is both horizontally and vertically centered. This is achieved with only three different rules on the container:
display: flex;
align-items: center;
justify-content: center;
The key to making the inner element stay square while the parent has a variable width is to base both thew width and height of the child off of the height of the parent.
In the following, I'm basing both the width and height of the inner square off of the height of the parent container (divided by four). Considering the height and width of the child is defined by the same --value as the height of the parent, it will always remain square and proportionate:
:root {
--value: 200px;
}
.container {
display: flex;
align-items: center;
justify-content: center;
border: 2px solid black;
height: var(--value);
}
.box {
background: black;
height: calc(var(--value) / 4);
width: calc(var(--value) / 4);
}
<div class="container">
<div class="box">
</div>
</div>
Note that this will also work if you base your CSS variable off of the viewport height with the vh unit:
:root {
--value: 50vh;
}
.container {
display: flex;
align-items: center;
justify-content: center;
border: 2px solid black;
height: var(--value);
}
.box {
background: black;
height: calc(var(--value) / 4);
width: calc(var(--value) / 4);
}
<div class="container">
<div class="box">
</div>
</div>
Hope this helps! :)
I think you can achieve your goal with the following code. You will need to set your image as the background of the inner div instead of using a <img> directly.
.wrapper {
width: 100%;
height: 300px;
padding: 10px;
box-sizing: border-box;
border: 1px solid red;
}
.inner {
background: url('http://lorempixel.com/output/abstract-q-c-300-300-7.jpg') no-repeat center center;
background-size: contain;
width: 100%;
height: 100%;
}
<div class="wrapper">
<div class="inner"></div>
</div>
Solution 2: using <img> and set the position to absolute.
.wrapper {
position: relative;
top: 0;
left: 0;
width: 100%;
height: 300px;
border: 1px solid red;
box-sizing: border-box;
}
.wrapper img {
position: absolute;
transform: translate(-50%, -50%);
top: 50%;
left: 50%;
max-width: 100%;
max-height: 100%;
}
<div class='wrapper'>
<img src='http://lorempixel.com/output/abstract-q-c-300-300-7.jpg'>
</div>
You can do it like this:
html, body {width:100%;margin:0}
.container {
position: relative;
height: 300px; /* needs to be at least the height of the image */
max-height: 100vh; /* enables vertical responsiveness */
border: 1px solid Skyblue;
}
img {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%); /* perfectly centered inside the container */
display: block; /* removes bottom margin/white-space */
max-width: 100%; /* horizontal responsiveness */
max-height: 100vh; /* vertical responsiveness */
}
<div class="container">
<img src="http://lorempixel.com/300/300" alt="">
</div>
If the square is an image in this case you can do something like this :
.container {
position:relative;
text-align: center;
border: 1px solid;
background:#f2f2f5;
}
img {
position:absolute;
top:50%;
left:50%;
transform:translate(-50%,-50%);
max-height: 100%;
max-width: 100%;
}
<div class="container" style="width:400px;height:100px;">
<img src="https://lorempixel.com/400/400/" />
</div>
<div class="container" style="width:200px;height:400px;">
<img src="https://lorempixel.com/400/400/" />
</div>
<div class="container" style="width:400px;height:400px;">
<img src="https://lorempixel.com/400/400/" />
</div>
<div class="container" style="width:50px;height:600px;">
<img src="https://lorempixel.com/400/400/" />
</div>
<div class="container" style="width:600px;height:50px;">
<img src="https://lorempixel.com/400/400/" />
</div>
You need to pay attention when using 100% with height as this will depend on the parent of the container and if nothing specified the height will be 0 and thus the image too :
.container {
position: relative;
text-align: center;
border: 1px solid;
background: #f2f2f5;
}
img {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
max-height: 100%;
max-width: 100%;
}
<!-- this one will not show -->
<div class="container" style="height:100%;">
<img src="https://lorempixel.com/400/400/" />
</div>
<div style="height:200px">
<!-- this one will show -->
<div class="container" style="height:100%;">
<img src="https://lorempixel.com/400/400/" />
</div>
</div>
if you want to use a div instead of image you can consider the image inside the div and use fit-content value for the width/height and the trick is to make the image not visible and add another div for text content (or anything else).
Pay attention as fit-content is not a standard so not supported by all browser. So you can consider this solution as a pseudo-solution than a generic one
.container {
position: relative;
text-align: center;
border: 1px solid;
background: #f2f2f5;
}
.content {
display: block;
background: red;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
max-height: 100%;
max-width: 100%;
height: fit-content;
width: fit-content;
}
.content img {
visibility: hidden;
z-index: -999;
position: relative;
max-height: 100%;
max-width: 100%;
}
.text {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
overflow: hidden;
}
<div class="container" style="width:400px;height:100px;">
<div class="content">
<img src="https://lorempixel.com/400/400/" />
<div class="text"> lorem ipsum lorem ipsum </div>
</div>
</div>
<div class="container" style="width:200px;height:400px;">
<div class="content">
<img src="https://lorempixel.com/400/400/" />
<div class="text"> lorem ipsum lorem ipsum </div>
</div>
</div>
<div class="container" style="width:400px;height:400px;">
<div class="content">
<img src="https://lorempixel.com/400/400/" />
<div class="text"> lorem ipsum lorem ipsum </div>
</div>
</div>
<div class="container" style="width:50px;height:600px;">
<div class="content">
<img src="https://lorempixel.com/400/400/" />
<div class="text"> lorem ipsum lorem ipsum </div>
</div>
</div>
<div class="container" style="width:600px;height:50px;">
<div class="content">
<img src="https://lorempixel.com/400/400/" />
<div class="text"> lorem ipsum lorem ipsum </div>
</div>
</div>

Div element to overlap wrapper div into the previous div

I'm trying to get the icon in the second wrapper div to cross up and dissect the previous wrapper div but the half that is supposed to appear in the div above will not appear. Even with a higher z-index. If I change the wrapper div overflow or position styles, it throws everything off. What is the correct way to do this? Here is the html and the css:
.wrapper {
position: relative;
width: 100%;
padding-bottom: 40px;
height: auto;
clear: left;
overflow: auto;
z-index: 1;
}
.process {
width: 100%;
height: 100%;
z-index: 1;
}
.process .icon {
position: relative;
height: 123px;
width: 123px;
margin-top: -60px;
border-radius: 50%;
z-index: 3;
}
<div class="wrapper">
<div class="page-heading">
<div class="col-md-6 col-centered">
</div>
</div>
</div>
<div class="wrapper blue">
<div class="process">
<div class="icon blue border-blue col-centered">
</div>
<div class="col-md-4 col-md-offset-1">
<div class="entry-content">
</div>
</div>
<div class="col-md-7 padding-right-100">
</div>
</div>
</div>
There is no table display necessary. What you need are actual heights for all elements - auto height won't work with no content, and 100% height only works if the parent container's height ( in this case body) is also defined. I made the body 100% and the two wrappers 50% .
The circle DIV has been centered horzontally with margin: 0 auto and pushed up using top: -60px while having: position: relative. The z-indexes remained unchanged 1 for the wrappers, 3 for the circle/icon (could also be 2).
There is also a codepen at http://codepen.io/anon/pen/KgNXmj
html, body {
height: 100%;
margin: 0;
}
.wrapper {
width: 100%;
height: 50%;
z-index: 1;
background: green;
}
.process {
width: 100%;
height: 100%;
z-index: 1;
background: blue;
}
.process .icon {
position: relative;
top: -60px;
margin: 0 auto;
height: 123px;
width: 123px;
background: #f00;
border-radius: 50%;
z-index: 3;
}
<div class="wrapper">
<div class="page-heading">
<div class="col-md-6 col-centered">
</div>
</div>
</div>
<div class="wrapper blue">
<div class="process">
<div class="icon blue border-blue col-centered">
</div>
<div class="col-md-4 col-md-offset-1">
<div class="entry-content">
</div>
</div>
<div class="col-md-7 padding-right-100">
</div>
</div>
</div>
After much research and hair-pulling, I found a solution that works. Not sure WHY, but the parent div had to have display:table and the child div display:table-row. If anyone knows why this works, definitely feel free to share.