I want to make the width of an image relative to it's parent div and still the highlighted box properly alinged on the words. But when I give image 100% width, it will not properly aligned.
Fiddle: https://jsfiddle.net/cv7g149k/3/
.summary {
background-color: #fff;
border: 2px solid #9197ae;
width: 700px;
padding: 15px;
margin: auto;
z-index: 1;
text-align: left;
box-shadow: 0 0 3px #000;
}
.image-results {
max-width: 700px;
margin: auto;
}
.image-holder {
display: block;
position: relative;
}
.word-highlight {
background-color: rgba(240, 45, 58, 0.3);
border: 1px solid rgba(240, 45, 58, 0.4);
position: absolute;
border-radius: 4px;
margin: -2px -4px;
padding: 2px 4px;
box-sizing: initial !important;
}
<div class="summary align-items-center">
<div class="px-2">
Number of Detected Words:<span>64</span>
</div>
<div class="px-2">
Detected words: <span>Python, Javascript</span>
</div>
</div>
<div class="image-results">
<div class="image-holder">
<img src="https://miro.medium.com/max/1400/0*GV5Xm8Ve-tb_qAAs" class="iimg-width-banned-words">
<div class="word-highlight" style="left: 171px; top: 173px; width: 70px; height: 22px;"></div>
<div class="word-highlight" style="left: 141px; top: 241px; width: 100px; height: 22px;"></div>
</div>
</div>
Instead of specifying exact px for the position of word-highlight classes, you may want to use % to define the position
.summary {
background-color: #fff;
border: 2px solid #9197ae;
width: 700px;
padding: 15px;
margin: auto;
z-index: 1;
text-align: left;
box-shadow: 0 0 3px #000;
}
.image-results {
max-width: 700px;
margin: auto;
}
.image-holder {
display: block;
position: relative;
}
.word-highlight {
background-color: rgba(240, 45, 58, 0.3);
border: 1px solid rgba(240, 45, 58, 0.4);
position: absolute;
border-radius: 4px;
margin: -2px -4px;
padding: 2px 4px;
box-sizing: initial !important;
}
img {
width: 100%;
}
<div class="summary align-items-center">
<div class="px-2">
Detected words:<span>64</span>
</div>
</div>
<div class="image-results">
<div class="image-holder">
<img src="https://miro.medium.com/max/1400/0*GV5Xm8Ve-tb_qAAs" class="iimg-width-banned-words">
<div class="word-highlight" style="left: 12%; top: 19%; width: 5.5%; height: 4%;"></div>
<div class="word-highlight" style="left: 10%; top: 26.5%; width: 8%; height: 4%;"></div>
</div>
</div>
Add width: 100%; and height: 100%: to your image class so that it fills 100% of the parent div. Then you will have to adjust your values for word-highlight.
.summary {
background-color: #fff;
border: 2px solid #9197ae;
width: 700px;
padding: 15px;
margin: auto;
z-index: 1;
text-align: left;
box-shadow: 0 0 3px #000;
}
.image-results {
max-width: 700px;
margin: auto;
}
.image-holder {
display: block;
position: relative;
}
.word-highlight {
background-color: rgba(240, 45, 58, 0.3);
border: 1px solid rgba(240, 45, 58, 0.4);
position: absolute;
border-radius: 4px;
margin: -2px -4px;
padding: 2px 4px;
box-sizing: initial !important;
}
.img-width-banned-words {
height: 100%;
width: 100%;
}
<div class="summary align-items-center">
<div class="px-2">
Number of Detected Words:<span>64</span>
</div>
<div class="px-2">
Detected words: <span>Python, Javascript</span>
</div>
</div>
<div class="image-results">
<div class="image-holder">
<img src="https://miro.medium.com/max/1400/0*GV5Xm8Ve-tb_qAAs" class="img-width-banned-words">
<div class="word-highlight" style="left: 80px;top: 83px;width: 44px;height: 20px;"></div>
<div class="word-highlight" style="left: 73px; top: 117px; width: 47.5px; height: 20px;"></div>
</div>
</div>
I am building this calculator, which made me go insane this afternoon. I am using for the first time Grid, till now I only used flex-box...
The problem is that the buttons are going outside the div (calculator). I am building this mainly for mobile. On the mobile simulator on Chrome looked perfect, but as soon as I uploaded it and looked on it on my phone, the buttons are going WAY outside the div...I've build dozens test websites and never had this problem, everything stayed where shoul've been staying.
What am I doing wrong? I've been here for 2 hours trying to make it work and I beggining to feel stupid.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Montserrat', sans-serif;
}
body {
background: linear-gradient(90deg, rgba(0,244,147,.7), rgba(30,144,255,.7));
}
.calculator {
border: 1px solid rgb(0,0,0,.3);
width: 80vw;
height: 80vh;
margin: auto;
position: relative;
top: 50vh;
transform: translateY(-50%);
border-radius: 10px;
background: rgb(225,225,225);
box-shadow: 0 0 10px rgb(0,0,0,.7), -5px -5px 10px rgb(0,0,0,.3) inset, 5px 5px 5px rgb(255,255,255) inset;
}
.name {
width: 100%;
height: 3%;
position: absolute;
}
h5 {
display: flex;
justify-content: center;
align-items: center;
font-size: .8em;
color: rgb(0,0,0,.5);
position: relative;
top: 50%;
transform: translateY(-50%);
}
.output {
width: 90%;
height: 25%;
margin: auto;
margin-top: 5.5%;
background: white;
box-shadow: 0 0 5px rgb(0,0,0,.7) inset ;
border-radius: 3px;
}
.previous {
width: 100%;
height: 40%;
border-bottom: .5px solid rgb(0,0,0,.5);
}
.current {
width: 100%;
height: 60%;
}
.keyboardparent {
width: 90%;
height: 75%;
margin: auto;
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
border:3px solid red;
}
.keyboard {
width: 100%;
height: 90%;
margin: auto;
border:3px solid black;
}
.top {
display: grid;
grid-template-columns: 2fr 1.5fr 1fr;
grid-gap: .5em;
-webkit-gap: .5em;
}
.rest {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
grid-gap: .5em;
-webkit-grid-gap: .5em;
margin-top: .5em;
}
button {
cursor: pointer;
font-size: 1.5em;
padding: 10px;
border-radius: 10px;
border: none;
box-shadow: 0 0 3px rgba(0,0,0,.5), -3px -3px 5px rgba(0,0,0,.3) inset, 3px 3px 5px rgba(255,255,255,.8) inset;
outline: none;
background: rgba(250,250,250,.8);
}
.color {
background: rgba(0,200,197,.3);
}
button:active {
transform: scale(.95);
}
<div class="calculator">
<div class="name">
<h5>Matthew Industries INC</h5>
</div>
<div class="output">
<div class="previous"></div>
<div class="current"></div>
</div>
<div class="keyboardparent">
<div class="keyboard">
<div class="top">
<button class="colorc">C</button>
<button class="color"><img src="delete.svg" class="delete" width="20px" alt=""></button>
<button class="color">%</button>
</div>
<div class="rest">
<button>7</button>
<button>8</button>
<button>9</button>
<button class="color">/</button>
<button>4</button>
<button>5</button>
<button>6</button>
<button class="color">x</button>
<button>1</button>
<button>2</button>
<button>3</button>
<button class="color">-</button>
<button class="color">.</button>
<button>0</button>
<button class="color">=</button>
<button class="color">+</button>
</div>
</div>
</div>
</div>
I found it.
I removed the height from .calculator, gave height: 120px; to .output and added padding: 30px 0; to .keyboardparent.
Thank you for the previous solutions, I didn't think the height of the .calculator set in vh could do some damage.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Montserrat', sans-serif;
}
body {
background: linear-gradient(90deg, rgba(0,244,147,.7), rgba(30,144,255,.7));
}
.calculator {
border: 1px solid rgb(0,0,0,.3);
width: 80vw;
margin: auto;
position: relative;
top: 50vh;
transform: translateY(-50%);
border-radius: 10px;
background: rgb(225,215,215);
box-shadow: 0 0 10px rgb(0,0,0,.7), -5px -5px 10px rgb(0,0,0,.3) inset, 5px 5px 5px rgb(255,255,255) inset;
}
.name {
width: 100%;
height: 3%;
position: absolute;
}
h5 {
display: flex;
justify-content: center;
align-items: center;
font-size: .8em;
color: rgb(0,0,0,.5);
position: relative;
top: 50%;
transform: translateY(-50%);
}
.output {
width: 90%;
height: 120px;
margin: auto;
margin-top: 5.5%;
background: rgba(180,200,180);
box-shadow: 0 0 5px rgb(0,0,0,.7) inset ;
border-radius: 3px;
}
.previous {
width: 100%;
height: 40%;
border-bottom: .5px solid rgb(0,0,0,.5);
}
.current {
width: 100%;
height: 60%;
}
.keyboardparent {
width: 90%;
height: 75%;
margin: auto;
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
padding: 30px 0;
}
.keyboard {
width: 100%;
height: 90%;
margin: auto;
}
.top {
display: grid;
grid-template-columns: 1.5fr 1.5fr 1fr;
grid-gap: .5em;
-webkit-gap: .5em;
}
.rest {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
grid-gap: .5em;
-webkit-grid-gap: .5em;
margin-top: .5em;
}
button {
cursor: pointer;
font-size: 1.5em;
padding: 10px;
border-radius: 10px;
border: none;
box-shadow: 0 0 3px rgba(0,0,0,.5), -3px -3px 5px rgba(0,0,0,.3) inset, 3px 3px 5px rgba(255,255,255,.8) inset;
outline: none;
background: rgba(250,250,250,.8);
text-align: center;
vertical-align: ;
}
.color {
background: rgba(0,200,207,.3);
}
button:active {
transform: scale(.95);
}
.clearall {
background: rgba(255,0,50,.7);
}
.cancel {
background: rgba(255,0,0,.5);
}
<div class="calculator">
<div class="name">
<h5>Matthew Industries INC</h5>
</div>
<div class="output">
<div class="previous"></div>
<div class="current"></div>
</div>
<div class="keyboardparent">
<div class="keyboard">
<div class="top">
<button class="clearall">C</button>
<button class="cancel"><img src="delete.svg" class="delete" width="23px" alt=""></button>
<button class="color">%</button>
</div>
<div class="rest">
<button>7</button>
<button>8</button>
<button>9</button>
<button class="color">/</button>
<button>4</button>
<button>5</button>
<button>6</button>
<button class="color">x</button>
<button>1</button>
<button>2</button>
<button>3</button>
<button class="color">-</button>
<button class="color">.</button>
<button>0</button>
<button class="color equal">=</button>
<button class="color">+</button>
</div>
</div>
</div>
</div>
height of .calculator the unit vh to % that is
change this
.calculator{
height: 80vh;
}
to
.calculator{
height: 80%;
}
like this height: 50px; to .output instead of height:25%
Also added a margin-bottom to .keyboardparent
.keyboardparent { margin-bottom: 5.5%;} // you already given margin-top: 5.5%; to output
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Montserrat', sans-serif;
}
body {
background: linear-gradient(90deg, rgba(0,244,147,.7), rgba(30,144,255,.7));
}
.calculator {
border: 1px solid rgb(0,0,0,.3);
width: 80vw;
height: 80%;
margin: auto;
position: relative;
top: 50vh;
transform: translateY(-50%);
border-radius: 10px;
background: rgb(225,225,225);
box-shadow: 0 0 10px rgb(0,0,0,.7), -5px -5px 10px rgb(0,0,0,.3) inset, 5px 5px 5px rgb(255,255,255) inset;
}
.name {
width: 100%;
height: 3%;
position: absolute;
top:10px;
}
h5 {
display: flex;
justify-content: center;
align-items: center;
font-size: .8em;
color: rgb(0,0,0,.5);
position: relative;
top: 50%;
transform: translateY(-50%);
}
.output {
width: 90%;
height: 50px;
margin: auto;
margin-top: 5.5%;
background: white;
box-shadow: 0 0 5px rgb(0,0,0,.7) inset ;
border-radius: 3px;
}
.previous {
width: 100%;
height: 40%;
border-bottom: .5px solid rgb(0,0,0,.5);
}
.current {
width: 100%;
height: 60%;
}
.keyboardparent {
width: 90%;
height: 75%;
margin: auto;
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
border:3px solid red;
margin-bottom: 5.5%;
}
.keyboard {
width: 100%;
height: 90%;
margin: auto;
border:3px solid black;
}
.top {
display: grid;
grid-template-columns: 2fr 1.5fr 1fr;
grid-gap: .5em;
-webkit-gap: .5em;
}
.rest {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
grid-gap: .5em;
-webkit-grid-gap: .5em;
margin-top: .5em;
}
button {
cursor: pointer;
font-size: 1.5em;
padding: 10px;
border-radius: 10px;
border: none;
box-shadow: 0 0 3px rgba(0,0,0,.5), -3px -3px 5px rgba(0,0,0,.3) inset, 3px 3px 5px rgba(255,255,255,.8) inset;
outline: none;
background: rgba(250,250,250,.8);
}
.color {
background: rgba(0,200,197,.3);
}
button:active {
transform: scale(.95);
}
<div class="calculator">
<div class="name">
<h5>Matthew Industries INC</h5>
</div>
<div class="output">
<div class="previous"></div>
<div class="current"></div>
</div>
<div class="keyboardparent">
<div class="keyboard">
<div class="top">
<button class="colorc">C</button>
<button class="color"><img src="delete.svg" class="delete" width="20px" alt=""></button>
<button class="color">%</button>
</div>
<div class="rest">
<button>7</button>
<button>8</button>
<button>9</button>
<button class="color">/</button>
<button>4</button>
<button>5</button>
<button>6</button>
<button class="color">x</button>
<button>1</button>
<button>2</button>
<button>3</button>
<button class="color">-</button>
<button class="color">.</button>
<button>0</button>
<button class="color">=</button>
<button class="color">+</button>
</div>
</div>
</div>
</div>
I have a horizontal bar that has 4 items or maybe more. What I am trying to do is that when the browser is resized each item of the horizontal bar with its respective element, however, I am using twitter-bootstrap 4, but it doesn't seem to work either by default
.post-content-wrapper {
padding: 20px;
margin-bottom: 2em;
position: relative;
max-width: 900px;
margin-left: auto;
margin-right: auto;
background-color: #f7f7f7;
border-radius: 7px;
box-sizing: border-box;
}
.flex7 {
display: flex;
height: 300px;
justify-content: space-between;
align-items: flex-end;
}
.flex {
background-color: #f7f7f7;
border-radius: 3px;
padding: 20px;
}
.flex7-child-1 {
height: 40%;
position: relative;
}
.flex7-child-1:before {
content: '';
position: absolute;
background-image: url('https://via.placeholder.com/50.png');
background-repeat: none;
background-position: center center;
background-size: contain;
top: -60px;
left: 0;
right: 0;
margin: 0 auto;
display: block;
width: 50px;
height: 50px;
}
.flex7-child-2:before {
content: '';
position: absolute;
background-image: url(https://via.placeholder.com/50.png);
background-repeat: none;
background-position: center center;
background-size: contain;
top: 88px;
left: -170px;
right: 0;
margin: 24px auto;
display: block;
width: 50px;
height: 50px;
}
.flex7-child-3:before {
content: '';
position: absolute;
background-image: url(https://via.placeholder.com/50.png);
background-repeat: none;
background-position: center center;
background-size: contain;
top: 85px;
left: 0;
right: 0;
margin: 0 auto;
display: block;
width: 50px;
height: 50px;
}
.flex7-child-4:before {
content: '';
position: absolute;
background-image: url(https://via.placeholder.com/50.png);
background-repeat: none;
background-position: center center;
background-size: contain;
top: 85px;
left: 170px;
right: 0;
margin: 106px auto;
display: block;
width: 50px;
height: 50px;
}
.flex7-child-5:before {
content: '';
position: absolute;
background-image: url(https://via.placeholder.com/50.png);
background-repeat: none;
background-position: center center;
background-size: contain;
top: 58px;
left: 166px;
right: -174px;
margin: 106px auto;
display: block;
width: 50px;
height: 50px;
}
.flex7-child {
width: 14%;
}
.child {
border-radius: 3px;
background-color: #A2CBFA;
border: 1px solid #4390E1;
box-sizing: border-box;
box-shadow: 0 2px 2px rgba(0,90,250,0.05), 0 4px 4px rgba(0,90,250,0.05), 0 8px 8px rgba(0,90,250,0.05), 0 16px 16px rgba(0,90,250,0.05);
}
.flex7-child-2 {
height: 50%;
}
.flex7-child-3 {
height: 60%;
}
.flex7-child-4 {
height: 20%;
}
.flex7-child-5 {
height: 30%;
}
<div class="post-content-wrapper">
<div class="flex flex7">
<div class="child flex7-child flex7-child-1"></div>
<div class="child flex7-child flex7-child-2"></div>
<div class="child flex7-child flex7-child-3"></div>
<div class="child flex7-child flex7-child-4"></div>
<div class="child flex7-child flex7-child-5"></div>
</div>
</div>
before toggle
after toggle, I am expecting to have the same position even when I resize the layout without breaking the elements
Here's a better way to achieve responsive consistent styles for your horizontal bars. Note that individual styles for each .flex7-child-#:before has been removed, and all .flex7-child elements now use flexbox.
.post-content-wrapper {
padding: 20px;
margin-bottom: 2em;
position: relative;
max-width: 900px;
margin-left: auto;
margin-right: auto;
background-color: #f7f7f7;
border-radius: 7px;
box-sizing: border-box;
}
.flex7 {
display: flex;
height: 300px;
justify-content: space-between;
align-items: flex-end;
}
.flex {
background-color: #f7f7f7;
border-radius: 3px;
padding: 20px;
}
/* Pay attention to below */
.flex7-child {
display: flex;
flex-direction: row;
justify-content: center;
}
.flex7-child:before {
content: '';
position: relative;
background-image: url('https://via.placeholder.com/50.png');
background-repeat: none;
background-position: center center;
top: -70px;
background-size: contain;
display: block;
width: 50px;
height: 50px;
}
/* Pay attention to above */
.flex7-child {
width: 14%;
}
.child {
border-radius: 3px;
background-color: #A2CBFA;
border: 1px solid #4390E1;
box-sizing: border-box;
box-shadow: 0 2px 2px rgba(0,90,250,0.05), 0 4px 4px rgba(0,90,250,0.05), 0 8px 8px rgba(0,90,250,0.05), 0 16px 16px rgba(0,90,250,0.05);
}
.flex7-child-1 {
height: 40%;
}
.flex7-child-2 {
height: 50%;
}
.flex7-child-3 {
height: 60%;
}
.flex7-child-4 {
height: 20%;
}
.flex7-child-5 {
height: 30%;
}
This isn't an exact example, but I would wrap your thumbnails and bars together something like this:
#container{
margin: auto;
width: 800px;
height: 400px;
border: 3px solid gainsboro;
border-radius: 5px;
display: flex;
justify-content: space-around;
}
.flex-item{
height: 100%;
display: flex;
flex-direction: column-reverse;
}
.flex-item > .bar{
border-radius: 5px;
width: 80px;
background-color: mediumpurple;
border: 1px solid blue;
margin-top: 10px;
}
.flex-item:after{
display: block;
content: '';
height: 80px;
width: 80px;
background-image: url("https://via.placeholder.com/80.png")
}
<div id="container">
<div class="flex-item">
<div class="bar" style="height:40%"></div>
</div>
<div class="flex-item">
<div class="bar" style="height:20%"></div>
</div>
<div class="flex-item">
<div class="bar" style="height:60%"></div>
</div>
<div class="flex-item">
<div class="bar" style="height:50%"></div>
</div>
<div class="flex-item">
<div class="bar" style="height:70%"></div>
</div>
</div>
I am trying to set three divs side by side with each equal width and height.
I am unable to remove that extra space at right at right most div. If I set its margin-right to 0 the rightmost div becomes bigger than other two.
Here is the fiddle.
Css:
.recordpopup {
position: fixed;
z-index: 10000;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-color: rgba( 0, 0, 0, .8);
background-position: 50% 50%;
background-repeat: no-repeat;
display: block;
}
.recordpopup .retry {
background-color: black;
border: 1px solid white;
xborder-radius: 8px;
box-sizing: border-box;
color: white;
font-family: ProximaNova-Regular;
font-size: 16px;
font-weight: bold;
xheight: 50px;
margin-left: auto;
margin-right: auto;
padding-top: 0px;
position: relative;
text-align: center;
top: 30%;
width: 40%;
z-index: 15000;
border-radius: 8px;
padding: 20px 10px;
background-image: url('images/gray_bar.png');
background-repeat: repeat-x;
background-color: white;
}
#product-wrapper {
overflow: hidden;
margin-top: 25px;
}
.product {
float: left;
width: 33%;
display: table-cell;
width: 33.33333333%;
}
.product .container {
margin-right: 10px;
padding: 10px;
background-color: #000;
}
.product .container img {
display: block;
margin: 0 auto;
width: 100%;
}
#closeRecord {
background: black none repeat scroll 0 0;
border: 2px solid white;
border-radius: 50%;
color: white;
cursor: pointer;
height: 25px;
right: -15px;
left: right;
position: absolute;
top: -10px;
width: 25px;
}
Html:
<div class="recordpopup">
<div class="retry">
<div id="closeRecord">x</div>
<div style="width: 100%;text-align: left;margin: 5px 0;font-size: 12px;color:#333;"><span class="TitleText">Lorem Ipsum Lorem Ipsum</span> </div>
<div id="product-wrapper">
<div class="product">
<div class="container">
<img src="images/circle.png">
<p>Dummy</p>
</div>
</div>
<div class="product">
<div class="container">
<img src="images/circle.png">
<p>Dummy</p>
</div>
</div>
<div class="product">
<div class="container">
<img src="images/circle.png">
<p>Dummy</p>
</div>
</div>
</div>
</div>
</div>
Here is my solution.
The key is removing the margin-right: 10px and adding
.product:nth-child(1) .container{
margin-right:5px;
}
.product:nth-child(2) .container{
margin: 0 5px 0 5px;
}
.product:nth-child(3) .container{
margin-left: 5px;
}
JSFiddle ===> https://jsfiddle.net/kjkk3f9d/1/
The margin-right: 10px was pushing out your divs, replace it with margin: 0 5px to give a uniform look
.product .container {
margin: 0px 5px;
padding: 10px;
background-color: #000;
}
https://jsfiddle.net/kjkk3f9d/3/
check out my fiddle:
https://jsfiddle.net/kjkk3f9d/2/
the important styles are
#product-wrapper {
overflow: hidden;
margin-top: 25px;
display: flex;
justify-content: space-between;
}
.product {
flex-basis:0;
flex: 1 1 auto;
margin: 5px;
}