Centering an absolute element until ranges without js - html

I have a dropdown which has title and content. Content should be centered is relatively to title, if only there is empty place for it. If there is no empty place, content should cuddle to the parent's border.
I've prepared a DEMO. This demo has a follow significant code:
.dropdown {
position: relative;
left: 100px;
}
.dropdown_content {
position: absolute;
left: 50%;
transform: translateX(-50%);
width: 150px;
height: 200px;
margin-top: 15px;
background-color: white;
border: 1px solid #ccc;
border-radius: 5px;
}
<div class="container">
<div class="dropdown">
<div class="dropdown_button"></div>
<div class="dropdown_content"></div>
</div>
</div>
Now .dropdown_content floats beyond the borders when second input[type="range"] has a small value. This behaviour is bad. I want in this case .dropdown_content to cuddle to the left border.
Desired result

I removed the absolute positioning see: https://jsfiddle.net/v9amen50/.
That seems to work.
body {
margin: 20px;
}
.block {
margin-bottom: 10px;
}
.container {
display: flex;
padding: 20px 0;
}
.dropdown {
position: relative;
}
.dropdown_button {
cursor: pointer;
text-align: center;
}
.dropdown_content {
display: block;
margin: 15px auto;
width: 150px;
height: 200px;
background-color: white;
border: 1px solid #ccc;
border-radius: 5px;
}
.dropdown_content::before {
position: absolute;
top: 0px;
left: 50%;
transform: translateX(-50%);
width: 0;
height: 24px;
content: "";
border-right: 10px solid transparent;
border-bottom: 10px solid #ccc;
border-left: 10px solid transparent;
}
<div class="block">
<input type="range" name="title" min="1" max="100" , value="5">
</div>
<div class="block">
<input type="range" name="position" min="0" max="500" , value="0">
</div>
<div class="container">
<div class="dropdown">
<div class="dropdown_button"></div>
<div class="dropdown_content"></div>
</div>
</div>

Related

Can't put icons into the search bar

I've only been doing HTML and CSS for a total of one month. I'm currently trying to replicate a Google search bar, but the problem is that I can't seem to fit the search icon and the voice icon inside the search bar. I've read that you're supposed to put the search bar's position as relative and the icons' as absolute, but I've apparently screwed up the code somewhere and can't figure it out. Thank you <3
My code (HTML and CSS):
input {
color: rgba(0,0,0,.87);
width: 600px;
padding: 15px;
border-radius: 50px;
border: 1px solid #dcdcdc;
outline-color: none;
cursor: text;
background-color: transparent;
z-index: -1;
}
input:focus {
outline: none;
}
input:hover {
box-shadow: 1px 1px 8px 1px #dcdcdc;
}
.voice {
height:20px;
top: 5px;
left: 10px;
position: absolute;
margin-right: 30px;
}
.search-icon {
color: rgb(154, 160, 166);
position: absolute;
z-index: 0;
}
.wrapper {
position: relative;
}
<form id="search-form">
<div class="wrapper">
<img class="search-icon" src="data:image/svg+xml;utf8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pgo8IS0tIEdlbmVyYXRvcjogQWRvYmUgSWxsdXN0cmF0b3IgMTkuMC4wLCBTVkcgRXhwb3J0IFBsdWctSW4gLiBTVkcgVmVyc2lvbjogNi4wMCBCdWlsZCAwKSAgLS0+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4PSIwcHgiIHk9IjBweCIgdmlld0JveD0iMCAwIDU2Ljk2NiA1Ni45NjYiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDU2Ljk2NiA1Ni45NjY7IiB4bWw6c3BhY2U9InByZXNlcnZlIiB3aWR0aD0iMTZweCIgaGVpZ2h0PSIxNnB4Ij4KPHBhdGggZD0iTTU1LjE0Niw1MS44ODdMNDEuNTg4LDM3Ljc4NmMzLjQ4Ni00LjE0NCw1LjM5Ni05LjM1OCw1LjM5Ni0xNC43ODZjMC0xMi42ODItMTAuMzE4LTIzLTIzLTIzcy0yMywxMC4zMTgtMjMsMjMgIHMxMC4zMTgsMjMsMjMsMjNjNC43NjEsMCw5LjI5OC0xLjQzNiwxMy4xNzctNC4xNjJsMTMuNjYxLDE0LjIwOGMwLjU3MSwwLjU5MywxLjMzOSwwLjkyLDIuMTYyLDAuOTIgIGMwLjc3OSwwLDEuNTE4LTAuMjk3LDIuMDc5LTAuODM3QzU2LjI1NSw1NC45ODIsNTYuMjkzLDUzLjA4LDU1LjE0Niw1MS44ODd6IE0yMy45ODQsNmM5LjM3NCwwLDE3LDcuNjI2LDE3LDE3cy03LjYyNiwxNy0xNywxNyAgcy0xNy03LjYyNi0xNy0xN1MxNC42MSw2LDIzLjk4NCw2eiIgZmlsbD0iIzAwMDAwMCIvPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8L3N2Zz4K" />
<input class="search" type="text">
<img class="voice" src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/e8/Google_mic.svg/716px-Google_mic.svg.png" title="Search by Voice">
</div>
</form>
So what you need to do is that it's not the text field that has the rounded corners and shadows, with the icons on top, but it's the wrapper that needs to have the rounded corners and borders and every, then the three elements all go inside of it.
so what I did is that I took your styles for the input, and moved it too the wrapper, then make the border:none, so the input is basically invisible.
then I removed all of your position styles because they aren't needed, so now we are basically done, except the elements are slightly off center, and the input doesn't fill the whole width.
I just decided to use display:flex on the wrapper, with flex-direction:row to make all of it horizontal, with align-items: center to center everything. I also added flex-grow:1 to the input so it fills the entire width.
input {
color: rgba(0,0,0,.87);
outline-color: none;
background-color: transparent;
border:none;
height:100%;
flex-grow:1;
font-size: 15px;
}
input:focus {
outline: none;
}
.voice {
height:20px;
margin: 0px 5px;
}
.search-icon {
color: rgb(154, 160, 166);
margin: 0px 5px;
}
.wrapper {
width: 600px;
height: 30px;
padding: 2px;
border-radius: 50px;
border: 1px solid #dcdcdc;
outline-color: none;
cursor: text;
background-color: transparent;
display:flex;
flex-direction: row;
align-items: center;
}
.wrapper:hover{
box-shadow: 1px 1px 8px 1px #dcdcdc;
}
<form id="search-form">
<div class="wrapper">
<img class="search-icon" src="data:image/svg+xml;utf8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pgo8IS0tIEdlbmVyYXRvcjogQWRvYmUgSWxsdXN0cmF0b3IgMTkuMC4wLCBTVkcgRXhwb3J0IFBsdWctSW4gLiBTVkcgVmVyc2lvbjogNi4wMCBCdWlsZCAwKSAgLS0+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4PSIwcHgiIHk9IjBweCIgdmlld0JveD0iMCAwIDU2Ljk2NiA1Ni45NjYiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDU2Ljk2NiA1Ni45NjY7IiB4bWw6c3BhY2U9InByZXNlcnZlIiB3aWR0aD0iMTZweCIgaGVpZ2h0PSIxNnB4Ij4KPHBhdGggZD0iTTU1LjE0Niw1MS44ODdMNDEuNTg4LDM3Ljc4NmMzLjQ4Ni00LjE0NCw1LjM5Ni05LjM1OCw1LjM5Ni0xNC43ODZjMC0xMi42ODItMTAuMzE4LTIzLTIzLTIzcy0yMywxMC4zMTgtMjMsMjMgIHMxMC4zMTgsMjMsMjMsMjNjNC43NjEsMCw5LjI5OC0xLjQzNiwxMy4xNzctNC4xNjJsMTMuNjYxLDE0LjIwOGMwLjU3MSwwLjU5MywxLjMzOSwwLjkyLDIuMTYyLDAuOTIgIGMwLjc3OSwwLDEuNTE4LTAuMjk3LDIuMDc5LTAuODM3QzU2LjI1NSw1NC45ODIsNTYuMjkzLDUzLjA4LDU1LjE0Niw1MS44ODd6IE0yMy45ODQsNmM5LjM3NCwwLDE3LDcuNjI2LDE3LDE3cy03LjYyNiwxNy0xNywxNyAgcy0xNy03LjYyNi0xNy0xN1MxNC42MSw2LDIzLjk4NCw2eiIgZmlsbD0iIzAwMDAwMCIvPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8L3N2Zz4K" />
<input class="search" type="text">
<img class="voice" src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/e8/Google_mic.svg/716px-Google_mic.svg.png" title="Search by Voice">
</div>
</form>
I also changed some padding and stuff slightly to make it work better but I guess that's optional
input {
font-size:20px;
width: 88%;
border:none;
margin-left:60px;
height:30px;
padding:0;
}
input:focus {
outline: none;
}
.wrapper:hover {
box-shadow: 1px 1px 8px 1px #dcdcdc;
}
.voice {
height:20px;
top: 10px;
left: 40px;
position: absolute;
margin-right: 30px;
}
.search-icon {
color: rgb(154, 160, 166);
position: absolute;
z-index: 0;
left: 15px;
top: 10px;
cursor:default;
}
.wrapper {
position: relative;
color: rgba(0,0,0,.87);
width: 600px;
padding:5px;
border-radius: 50px;
border: 1px solid #dcdcdc;
outline-color: none;
cursor: text;
background-color: transparent;
}
<form id="search-form">
<div class="wrapper">
<img class="search-icon" src="data:image/svg+xml;utf8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pgo8IS0tIEdlbmVyYXRvcjogQWRvYmUgSWxsdXN0cmF0b3IgMTkuMC4wLCBTVkcgRXhwb3J0IFBsdWctSW4gLiBTVkcgVmVyc2lvbjogNi4wMCBCdWlsZCAwKSAgLS0+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4PSIwcHgiIHk9IjBweCIgdmlld0JveD0iMCAwIDU2Ljk2NiA1Ni45NjYiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDU2Ljk2NiA1Ni45NjY7IiB4bWw6c3BhY2U9InByZXNlcnZlIiB3aWR0aD0iMTZweCIgaGVpZ2h0PSIxNnB4Ij4KPHBhdGggZD0iTTU1LjE0Niw1MS44ODdMNDEuNTg4LDM3Ljc4NmMzLjQ4Ni00LjE0NCw1LjM5Ni05LjM1OCw1LjM5Ni0xNC43ODZjMC0xMi42ODItMTAuMzE4LTIzLTIzLTIzcy0yMywxMC4zMTgtMjMsMjMgIHMxMC4zMTgsMjMsMjMsMjNjNC43NjEsMCw5LjI5OC0xLjQzNiwxMy4xNzctNC4xNjJsMTMuNjYxLDE0LjIwOGMwLjU3MSwwLjU5MywxLjMzOSwwLjkyLDIuMTYyLDAuOTIgIGMwLjc3OSwwLDEuNTE4LTAuMjk3LDIuMDc5LTAuODM3QzU2LjI1NSw1NC45ODIsNTYuMjkzLDUzLjA4LDU1LjE0Niw1MS44ODd6IE0yMy45ODQsNmM5LjM3NCwwLDE3LDcuNjI2LDE3LDE3cy03LjYyNiwxNy0xNywxNyAgcy0xNy03LjYyNi0xNy0xN1MxNC42MSw2LDIzLjk4NCw2eiIgZmlsbD0iIzAwMDAwMCIvPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8L3N2Zz4K" />
<input class="search" type="text">
<img class="voice" src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/e8/Google_mic.svg/716px-Google_mic.svg.png" title="Search by Voice">
</div>
</form>
input {
color: rgba(0,0,0,.87);
width: 600px;
padding: 15px;
border-radius: 50px;
border: 1px solid #dcdcdc;
outline-color: none;
cursor: text;
background-color: transparent;
}
input:focus {
outline: none;
}
input:hover {
box-shadow: 1px 1px 8px 1px #dcdcdc;
}
.voice {
height:20px;
top: 10;
right: 40;
position: absolute;
margin-right: 30px;
}
.search-icon {
color: rgb(154, 160, 166);
position: absolute;
right:20;
top:10;
}
.wrapper {
width:600px;
position: relative;
}
<form id="search-form">
<div class="wrapper">
<img class="search-icon" src="data:image/svg+xml;utf8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pgo8IS0tIEdlbmVyYXRvcjogQWRvYmUgSWxsdXN0cmF0b3IgMTkuMC4wLCBTVkcgRXhwb3J0IFBsdWctSW4gLiBTVkcgVmVyc2lvbjogNi4wMCBCdWlsZCAwKSAgLS0+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4PSIwcHgiIHk9IjBweCIgdmlld0JveD0iMCAwIDU2Ljk2NiA1Ni45NjYiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDU2Ljk2NiA1Ni45NjY7IiB4bWw6c3BhY2U9InByZXNlcnZlIiB3aWR0aD0iMTZweCIgaGVpZ2h0PSIxNnB4Ij4KPHBhdGggZD0iTTU1LjE0Niw1MS44ODdMNDEuNTg4LDM3Ljc4NmMzLjQ4Ni00LjE0NCw1LjM5Ni05LjM1OCw1LjM5Ni0xNC43ODZjMC0xMi42ODItMTAuMzE4LTIzLTIzLTIzcy0yMywxMC4zMTgtMjMsMjMgIHMxMC4zMTgsMjMsMjMsMjNjNC43NjEsMCw5LjI5OC0xLjQzNiwxMy4xNzctNC4xNjJsMTMuNjYxLDE0LjIwOGMwLjU3MSwwLjU5MywxLjMzOSwwLjkyLDIuMTYyLDAuOTIgIGMwLjc3OSwwLDEuNTE4LTAuMjk3LDIuMDc5LTAuODM3QzU2LjI1NSw1NC45ODIsNTYuMjkzLDUzLjA4LDU1LjE0Niw1MS44ODd6IE0yMy45ODQsNmM5LjM3NCwwLDE3LDcuNjI2LDE3LDE3cy03LjYyNiwxNy0xNywxNyAgcy0xNy03LjYyNi0xNy0xN1MxNC42MSw2LDIzLjk4NCw2eiIgZmlsbD0iIzAwMDAwMCIvPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8L3N2Zz4K" />
<input class="search" type="text">
<img class="voice" src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/e8/Google_mic.svg/716px-Google_mic.svg.png" title="Search by Voice">
</div>
</form>

CSS: Horizontally centering text between two arrows

I am working on a HTML/CSS project. I have the following code:
category-arrows.html:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>CSS Arrows</title>
<link rel="stylesheet" type="text/css" href="category-arrows.css">
</head>
<body>
<div class="arrows-container">
<div class="up-arrow"></div>
<div class="category-rank">
<p>2</p>
</div>
<div class="down-arrow"></div>
</div>
</body>
</html>
category-arrows.css:
.up-arrow {
width: 60px;
height: 60px;
border-top: 15px solid #000000;
border-right: 15px solid #000000;
transform: rotate(-45deg);
margin: 50px;
border-radius: 15%;
}
.up-arrow:hover, .down-arrow:hover {
border-top: 15px solid #28bfa6;
border-right: 15px solid #28bfa6;
cursor: pointer;
}
.down-arrow {
width: 60px;
height: 60px;
border-top: 15px solid #000000;
border-right: 15px solid #000000;
transform: rotate(135deg);
margin: 50px;
border-radius: 15%;
position: relative;
top: -105px;
}
.category-rank {
position: relative;
top: 50%;
transform: translateY(-50%);
right: -69px;
margin-top: -36px;
font-size: 60px;
font-family: Helvetica;
}
The result of the above code is the following:
When the number between the arrows is -1, I get the following:
When the number between the arrows is negative (e.g. -1), the text is not fully horizontally centred between the arrows. I am using the CSS right property to centre the text between the arrows. This works fine when the number between the arrows does not have a negative sign in front of it.
I would like the text between the arrows to always be horizontally centred. However, I am not sure what the best way to do this is. Any insights are appreciated.
One solution would be to check if number < 0, and then use str.substring(1) to remove the first character of that number (the minus sign), and then display a minus sign next to it in fixed position in a span for example or whatever.
That way the number would always be centered, and if negative that minus sign would show itself and not move the number itself.
Your layout is all broken if you'd just add borders and some padding you'll see everything is miss aligned.
body * {
border: 1px solid;
padding: 10px;
}
.up-arrow {
width: 60px;
height: 60px;
border-top: 15px solid #000000;
border-right: 15px solid #000000;
transform: rotate(-45deg);
margin: 50px;
border-radius: 15%;
}
.up-arrow:hover,
.down-arrow:hover {
border-top: 15px solid #28bfa6;
border-right: 15px solid #28bfa6;
cursor: pointer;
}
.down-arrow {
width: 60px;
height: 60px;
border-top: 15px solid #000000;
border-right: 15px solid #000000;
transform: rotate(135deg);
margin: 50px;
border-radius: 15%;
position: relative;
top: -105px;
}
.category-rank {
position: relative;
top: 50%;
transform: translateY(-50%);
right: -69px;
margin-top: -36px;
font-size: 60px;
font-family: Helvetica;
}
<div class="arrows-container">
<div class="up-arrow"></div>
<div class="category-rank">
<p>-1</p>
</div>
<div class="down-arrow"></div>
</div>
You should instead relay on the changing element, the p is the one that changes so we align the arrows according to it.
display:inline-flex to the container will make it shrink to fit the widest element which the p tag, and we apply align-items: center; to center horizontally the arrows.
/* remove unnecessary padding and margin */
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
.arrows-container {
padding: 20px; /* just to be safe */
display: inline-flex;
flex-direction: column;
align-items: center;
}
.up-arrow {
width: 60px;
height: 60px;
border-top: 15px solid #000000;
border-right: 15px solid #000000;
transform: rotate(-45deg);
border-radius: 15%;
}
.up-arrow:hover,
.down-arrow:hover {
border-top: 15px solid #28bfa6;
border-right: 15px solid #28bfa6;
cursor: pointer;
}
.down-arrow {
width: 60px;
height: 60px;
border-top: 15px solid #000000;
border-right: 15px solid #000000;
transform: rotate(135deg);
border-radius: 15%;
}
.category-rank {
font-size: 60px;
font-family: Helvetica;
}
/* For the red line to show center, Not needed */
.arrows-container {
position: relative;
}
.arrows-container:before {
content: '';
position: absolute;
height: 100%;
width: 2px;
background: red;
top: 0;
}
<div class="arrows-container">
<div class="up-arrow"></div>
<div class="category-rank">
<p>-1</p>
</div>
<div class="down-arrow"></div>
</div>
<div class="arrows-container">
<div class="up-arrow"></div>
<div class="category-rank">
<p>1</p>
</div>
<div class="down-arrow"></div>
</div>
<div class="arrows-container">
<div class="up-arrow"></div>
<div class="category-rank">
<p>58</p>
</div>
<div class="down-arrow"></div>
</div>
I tried cleaning the code a little bit.

CSS3 : a div on text box

I have a textbox with having character limit box on it. What I want is. the text that is to be input should be upto the length of visible part of textbox.
I have tried this code.
.add_caption_div input[type="text"] {
border: thin #dee5e7 solid;
width: 190px;
border-top-left-radius: 0;
border-top-right-radius: 0;
display: inline-block;
float: left;
padding: 7px 12px;
}
.add_caption_div .image_galley_char_limit_div {
display: inline-block;
height: 31px;
width: 50px;
font-size: 9px;
color: #999999;
position: relative;
z-index: 100001;
background:#f6f8f8;
top:-6px;
right:51px;
}
.add_caption_div .form-control:focus {
border: thin #66afe9 solid;
}
.add_caption_div span {
position: relative;
top: 10px;
}
<div class="add_caption_div" >
<input type="text" class="form-control" placeholder="Enter Caption">
<div class="image_galley_char_limit_div text-center">
<span> 0/30</span>
</div>
</div>
When I type input then it goes behind the character_limit_div.
How can I prevent it?
Any help would be great.
Thank You.
.add_caption_div {
position: relative;
width: 190px;
}
.add_caption_div input[type="text"] {
border: thin #dee5e7 solid;
width: 190px;
border-top-left-radius: 0;
border-top-right-radius: 0;
display: inline-block;
float: left;
padding: 7px 12px;
}
.add_caption_div .form-control {
padding-right: 60px !important;
}
.add_caption_div .image_galley_char_limit_div {
display: inline-block;
height: 31px;
width: 50px;
font-size: 9px;
color: #999999;
position: absolute;
z-index: 100001;
top: 1px;
right: -73px;
background:#f6f8f8;
}
.add_caption_div .form-control:focus {
border: thin #66afe9 solid;
}
.add_caption_div span {
position: relative;
top: 10px;
}
<div class="add_caption_div" >
<input type="text" class="form-control" placeholder="Enter Caption">
<div class="image_galley_char_limit_div text-center">
<span> 0/30</span>
</div>
</div>
Is this the same that you are looking for?
Hope this helps.
you can give padding-right for input, something like this:
.add_caption_div input[type="text"] {
border: thin #dee5e7 solid;
width: 190px;
border-top-left-radius: 0;
border-top-right-radius: 0;
display: inline-block;
float: left;
padding: 7px 12px;
}
.add_caption_div .image_galley_char_limit_div {
display: inline-block;
height: 31px;
width: 50px;
font-size: 9px;
color: #999999;
position: relative;
z-index: 100001;
background:#f6f8f8;
top:-6px;
right:51px;
}
.add_caption_div .form-control:focus {
border: thin #66afe9 solid;
}
.add_caption_div span {
position: relative;
top: 10px;
}
.form-control{
padding-right: 70px !important;
}
<div class="add_caption_div" >
<input type="text" class="form-control" placeholder="Enter Caption">
<div class="image_galley_char_limit_div text-center">
<span> 0/30</span>
</div>
</div>

CSS/HTML: Tooltip pushing content down

I have a custom CSS Tooltip that when it appears, it pushes the other content down. I know that I need to add position: absolute to get it working right, but I can't seem to figure out where...
HTML:
<p>Fluff</p>
<p>Fluff</p>
<p>Fluff</p>
<p>Fluff</p>
<p>Fluff</p>
<div class="outer">
<a class="tippy" href="">
ICON<img src="" class="icon"/>
</a>
<div class="tooltip">
STUFF<br/>
STUFF<br/>
STUFF<br/>
STUFF<br/>
STUFF<br/>
</div>
</div><!-- Container -->
<p>FluffFluffFluffFluffFluffFluffFluffFluffFluff</p>
<p>FluffFluffFluffFluffFluffFluffFluffFluffFluff</p>
<p>FluffFluffFluffFluffFluffFluffFluffFluffFluff</p>
<p>FluffFluffFluffFluffFluffFluffFluffFluffFluff</p>
CSS:
.outer {
width: 350px;
}
.tippy {
text-decoration: none;
}
a.tippy:hover + div {
display:block;
float: right;
}
.tooltip {
margin-left: 5px;
margin-top: -15px;
padding: 10px;
width: 265px;
height: 110px;
background-color: #ccc;
position: relative;
border: 2px solid #333;
display: none;
}
.tooltip:after, .tooltip:before {
border: solid transparent;
content:' ';
height: 0;
right: 100%;
position: absolute;
width: 0;
}
.tooltip:after {
border-width: 11px;
border-right-color: #ccc;
top: 13px;
}
.tooltip:before {
border-width: 14px;
border-right-color: #333;
top: 10px;
}
Fiddle:
You need to change position:relative to position:absolute in the .tooltip CSS block.
You will also need to modify the CSS for positioning the tooltip due to this change.
If you modify .outer to have position:relative this is as simple as setting .tooltip as
left:55px;
top:-15px;
The resulting CSS (showing only the blocks that have changed):
.outer {
width: 350px;
position:relative;
}
.tooltip {
left: 55px;
top: -15px;
padding: 10px;
width: 265px;
height: 110px;
background-color: #ccc;
position: absolute;
border: 2px solid #333;
display: none;
}
And finally a jsFiddle showing it in action.

make progress bar dynamically change width to size of the rest of the container

I have an audio player that i built with jquery. The markup and css is relatively simple but I cannot get the progress bar to change width with the width of the whole container.
It is set as a percentage but does not behave as a child of the container div. I am guessing it is something to do with the position being absolute but if i change that the whole thing goes wrong.
Here is the markup
<div class="container gradient">
<div style="width:100px; overflow:hidden; display:inline-block;"><img src="" class="artwork" height="100%"></div>
<div class="name">
<p1><br>
<b></b></p1>
</div>
<div class="logo" style="font-size:12px; text-align:right; font-weight:bold;">
<br>
<br>
</div>
<div class="player gradient">
<a class="controls gradient" id="play" href="" title=""></a>
<input type="range" id="seek" value="0" max=""/>
</div><!-- / player -->
</div><!-- / Container-->
And the css
.gradient {
border: 1px solid #C4C4C4;
background: #F2F2F2;
}
.container {
position: absolute;
width: 100%;
height: 122px;
top: 0%;
left: 0%;
padding: 10px;
.artwork {height:100px; overflow:hidden; margin-left:auto; margin-right:auto;}
.containerLarge {
height: 427px;
}
.name {left:120px; position:absolute; top:7px}
.player {
box-sizing: border-box;
position:absolute;
width:91%;
bottom: 10px;
left:120px;
border-radius: 3px;
padding: 5px;
}
.controls {
border-radius:1em;
background-color:#0485bf;
display: block;
width: 34px;
height: 34px;
background-image: url(../player/src/images/sprite.png);
background-repeat: no-repeat;
float: left;
margin-right: 5px;
}
.controls:hover {background-color:#005b85}
#play {
background-position: 6px 5px;
}
#pause {
background-position: -32px 5px;
}
input[type="range"] {
width: 250px;
margin-top: -5px;
}
#close {
float: right;
background-position: -146px 5px;
display: none;
}
.volume {
position: absolute;
height: 100px;
width: 34px;
border: 1px solid black;
background-color: #242323;
top: -97px;
display: none;
}
input{
display:none\9!important;
}
input[type="range"] {
border: 1px solid #C4C4C4;
position: absolute;
top: 18px;
display: block;
width: 95%;
height: 15px;
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
background-color: #DBDBDB;
left: 50px;
}
input::-webkit-slider-thumb {
-webkit-appearance: none;
width: 20px;
height: 20px;
border:1px solid #C4C4C4;
-webkit-border-radius: 10px;
border-radius: 10px;
background: #0485bf;
}
input::-webkit-slider-thumb: hover {opacity : 0.3;filter: alpha(opacity=30)}
.logo {float:right; }
.embed {width:100%; background-color:black }
The main elements in question are .container, .controls, .player and the input type range.
Hard to see what's going on from the markup. Which element is the progress bar? If something is positioned absolutely and set to 100% width, it will fill fill the width of the screen, rather than its parent element (unless it's parent is set to position:relative).