Custom Dropdown pushing content downwards - html

I created a dropdown with just pure css, but the problem is that it is pushing the other content downwards. Can someone help out?
HTML:
<div class="select">
<input id="is-focus" type="radio" name="item" />
<label for="is-focus"><span class="label"></span></label>
<ul class="options">
<li>
<input type="radio" name="item" value="pie" id="pie" />
<label for="pie" data-title="Pie">Pie</label>
</li>
<li>
<input type="radio" name="item" value="cake" id="cake" />
<label for="cake" data-title="Cake">Cake</label>
</li>
</ul>
</div>
CSS:
.select {
position: relative;
overflow: hidden;
}
.select .label {
padding: 8px;
max-width: 150px;
}
.select .label:after {
content: "";
position: absolute;
left: 12px;
top: 14px;
border: 8px solid transparent;
border-top-color: #999;
}
.select label {
max-width: 150px;
display: block;
border: 1px solid rgba(0, 0, 0, 0.1);
border-radius: 3px;
padding: 8px;
cursor: pointer;
}
.select .options {
max-width: 220px;
margin: 0;
padding: 0;
color: #666;
height: 0;
border-right: 1px dotted #999;
border-left: 1px dotted #999;
border-radius: 5px;
max-height: 162px;
overflow-y: auto;
overflow-x: hidden;
}
.select .options:hover {
height: auto;
border-bottom: 2px solid #999;
}
.select .options li label {
text-align: left;
display: block;
padding: 6px 220px 6px 15px;
cursor: pointer;
overflow: hidden;
box-sizing: border-box;
}
.select .options li label:hover {
background-image: linear-gradient(rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0));
}
.select .options li [type="radio"] {
position: absolute;
display: block;
left: -999px;
}
.select .options li [type="radio"]:checked ~ label:after {
content: attr(data-title);
display: block;
position: absolute;
top: 6px;
left: 20px;
padding: 5px 25px;
color: #666;
pointer-events: none;
font-size: 80%;
overflow: hidden;
}
.select #is-focus {
position: absolute;
display: block;
opacity: 0;
left: 150px;
}
.select #is-focus:focus ~ label span.label:after {
border-top-color: transparent;
border-bottom-color: #999;
top: 0.3em;
}
.select #is-focus:focus ~ .options {
height: auto;
border-bottom: 2px solid #999;
}
Here is a codepen link for what I am trying to do:
http://codepen.io/anon/pen/ogYKzQ
Thank You

Change the .options position from static to fixed
and add a white background to the menu labels.

Figured it out. Set the position of .select to absolute, set the background of label to white, and added a z-index to it.

Related

Content Moves on Opening Select Dropdown

I need help with the Select Dropdown. It moves the content (Hello World) when opened. I have used Radio Input to select the specfic option when performing a Search. If there is any other better solution for this type of functionality, please assist.
HTML
<span class="dropdown-el">
<input type="radio" name="sortType" value="Relevance" checked="checked" id="sort-relevance"><label for="sort-relevance">Relevance</label>
<input type="radio" name="sortType" value="Popularity" id="sort-best"><label for="sort-best">Product Popularity</label>
<input type="radio" name="sortType" value="PriceIncreasing" id="sort-low"><label for="sort-low">Price Low to High</label>
<input type="radio" name="sortType" value="PriceDecreasing" id="sort-high"><label for="sort-high">Price High to Low</label>
<input type="radio" name="sortType" value="ProductBrand" id="sort-brand"><label for="sort-brand">Product Brand</label>
<input type="radio" name="sortType" value="ProductName" id="sort-name"><label for="sort-name">Product Name</label>
</span>
<h1> Hello World</h1>
CSS
body {
text-align: center;
background: #ebf4fb;
min-height: 95vh;
margin: 0;
padding: 0;
border-bottom: 5vh solid #3694d7;
font-family: "Myriad Pro", "Arial", sans;
font-size: 24px;
}
.dropdown-el {
margin-top: 20vh;
min-width: 12em;
position: relative;
display: inline-block;
margin-right: 1em;
min-height: 2em;
max-height: 2em;
overflow: hidden;
top: 0.5em;
cursor: pointer;
text-align: left;
white-space: nowrap;
color: #444;
outline: none;
border: 0.06em solid transparent;
border-radius: 1em;
background-color: #cde4f5;
transition: 0.3s all ease-in-out;
}
.dropdown-el input:focus + label {
background: #def;
}
.dropdown-el input {
width: 1px;
height: 1px;
display: inline-block;
position: absolute;
opacity: 0.01;
}
.dropdown-el label {
border-top: 0.06em solid #d9d9d9;
display: block;
height: 2em;
line-height: 2em;
padding-left: 1em;
padding-right: 3em;
cursor: pointer;
position: relative;
transition: 0.3s color ease-in-out;
}
.dropdown-el label:nth-child(2) {
margin-top: 2em;
border-top: 0.06em solid #d9d9d9;
}
.dropdown-el input:checked + label {
display: block;
border-top: none;
position: absolute;
top: 0;
width: 100%;
}
.dropdown-el input:checked + label:nth-child(2) {
margin-top: 0;
position: relative;
}
.dropdown-el::after {
content: "";
position: absolute;
right: 0.8em;
top: 0.9em;
border: 0.3em solid #3694d7;
border-color: #3694d7 transparent transparent transparent;
transition: 0.4s all ease-in-out;
}
.dropdown-el.expanded {
border: 0.06em solid #3694d7;
background: #fff;
border-radius: 0.25em;
padding: 0;
box-shadow: rgba(0, 0, 0, 0.1) 3px 3px 5px 0px;
max-height: 15em;
}
.dropdown-el.expanded label {
border-top: 0.06em solid #d9d9d9;
}
.dropdown-el.expanded label:hover {
color: #3694d7;
}
.dropdown-el.expanded input:checked + label {
color: #3694d7;
}
.dropdown-el.expanded::after {
transform: rotate(-180deg);
top: 0.55em;
}
JQuery
$('.dropdown-el').click(function(e) {
e.preventDefault();
e.stopPropagation();
$(this).toggleClass('expanded');
$('#'+$(e.target).attr('for')).prop('checked',true);
});
$(document).click(function() {
$('.dropdown-el').removeClass('expanded');
});
https://codepen.io/libsys/pen/bGKomaE
Please assist.

css input corner triangle label with border radius

I would like to create an triangle label inside input (text) element exactly like this:
What I managed to do so far is this:
How can I put this triangle "under" the input border to, let's just say, keep border radius from input cutting the edge of this triangle?
This is my code:
<div class="input">
<label>email adress</label>
<div class="note">
<p>*</p>
<input type="text" placeholder="Enter your email adress">
</div>
</div>
.input {
display: flex;
flex-direction: column;
width: 100%;
}
.note > input {
width: 515px;
height: 48px;
border-radius: 5px;
border: 1px solid #7d7d7d;
box-shadow:inset 0 0 5px 1px lightgray;
padding-left: 20px;
color: #acacac;
-webkit-color: #acacac;
-moz-color: #acacac;
-ms-color: #acacac;
-o-color: #acacac;
font-size: 16px;
background-color: rgba(211, 211, 211, 0.50);
}
.note > input:focus {
outline: none;
background-color: #f9f9f9;
}
.note {
position: relative;
display: inline-block;
}
.note:after {
content: "";
position: absolute;
top: 0;
right: 0;
width: 0;
height: 0;
display: block;
border-left: 35px solid transparent;
border-bottom: 35px solid transparent;
border-top: 35px solid #0094bb;
}
I imagine there is no way to give border-radius to this triangle itself without losing its shape, am I right?
I added position absolute for your P tag and postioned it in the corner.
The border radius is achieved by adding a border radius to your .note wrapper and setting overflow:hidden.
.note > input {
width: 515px;
height: 48px;
border-radius: 5px;
border: 1px solid #7d7d7d;
box-shadow:inset 0 0 5px 1px lightgray;
padding-left: 20px;
color: #acacac;
-webkit-color: #acacac;
-moz-color: #acacac;
-ms-color: #acacac;
-o-color: #acacac;
font-size: 16px;
background-color: rgba(211, 211, 211, 0.50);
}
.note > input:focus {
outline: none;
background-color: #f9f9f9;
}
.note {
position: relative;
display: inline-block;
border-radius: 5px;
overflow:hidden;
}
.note:after {
content: "";
position: absolute;
top: 0;
right: 0;
width: 0;
height: 0;
display: block;
border-left: 35px solid transparent;
border-bottom: 35px solid transparent;
border-top: 35px solid #0094bb;
z-index:0;
}
.note p{
position: absolute;
right: 5px;
top: 5px;
color:white;
z-index:1;
margin:0;
padding:0;
}
label {
display:block;
}
<div class="input">
<label>email address</label>
<div class="note">
<p>*</p>
<input type="text" placeholder="Enter your email adress">
</div>
</div>
Consider declaring the pseudo-element to a nested element of .note instead.
This will allow you to specify the required border-radius property on the containing element rather than the pseudo-element. With an overflow: hidden rule declared on this new containing element in addition, the top-right corner of the pseudo-element will be "cut-off" from view, conveying the impression that this is an element nested within the input field.
Code Snippet Demonstration:
.note > input {
width: 515px;
height: 48px;
border-radius: 5px;
border: 1px solid #7d7d7d;
box-shadow:inset 0 0 5px 1px lightgray;
padding-left: 20px;
color: #acacac;
-webkit-color: #acacac;
-moz-color: #acacac;
-ms-color: #acacac;
-o-color: #acacac;
font-size: 16px;
background-color: rgba(211, 211, 211, 0.50);
}
.note > input:focus {
outline: none;
background-color: #f9f9f9;
}
.note {
position: relative;
display: inline-block;
}
/* additional */
.note .required {
position: absolute;
top: 0;
right: 0;
z-index: 1;
color: white;
padding: 5px;
box-sizing: border-box;
border-top-right-radius: 5px;
overflow: hidden;
width: 35px;
height: 35px;
text-align: right;
}
.note .required:after {
content: "";
position: absolute;
top: 0;
right: 0;
width: 0;
height: 0;
display: block;
border-left: 35px solid transparent;
border-bottom: 35px solid transparent;
border-top: 35px solid #0094bb;
z-index: -1;
}
<div class="input">
<label>email adress</label>
<div class="note">
<span class="required">*</span>
<input type="text" placeholder="Enter your email adress">
</div>
</div>
The closest i could get with your solution. But I found other ways you're satisfied with this okay...
.note > input {
width: 515px;
height: 48px;
border-radius: 5px;
border: 1px solid #7d7d7d;
box-shadow:inset 0 0 5px 1px lightgray;
padding-left: 20px;
color: #acacac;
-webkit-color: #acacac;
-moz-color: #acacac;
-ms-color: #acacac;
-o-color: #acacac;
font-size: 16px;
background-color: rgba(211, 211, 211, 0.50);
}
.note > input:focus {
outline: none;
background-color: #f9f9f9;
}
.note {
position: relative;
display: inline-block;
}
.note:after {
content: "";
position: absolute;
top: 0;
right: 0;
width: 0;
height: 0;
display: block;
line-height: 48px;
text-align: top;
border-left: 35px solid transparent;
border-bottom: 35px solid transparent;
border-top: 35px solid #0094bb;
}
.note::before {
content: "*";
position: absolute;
right: 7px;
z-index: 1;
top: 5px;
color: white;
}
<div class="input">
<label>email adress</label>
<div class="note">
<input type="text" placeholder="Enter your email adress">
</div>
</div>

CSS Tooltip (tooltip display even if display none)

I try to make a tooltip (hide/unhide span) when a div is hovered.
I don't know where is the problem because the span is always visible and if i add display:none, all content will be hidden.
Thank you very much!
CSS:
.tooltip {
display:relative;
}
.tooltip span:before {
content:'';
display:none;
border-right: 8px solid #000000;
border-top: 8px solid transparent;
border-bottom: 8px solid transparent;
position:absolute;
z-index:8;
font-size:0;
line-height:0;
width:0;
height:0;
top: 30%;
left: 83%;
}
.tooltip span:after {
display:none;
position:absolute;
top:0%;
left:89%;
padding:5px 8px;
background: #000000;
color:#fff;
z-index:9;
font-size: 0.75em;
height:auto;
opacity: 0.8;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
white-space:nowrap;
word-wrap:normal;
}
.tooltip span:hover:before,
.tooltip span:hover:after {
display:block;
}
HTML:
<div class="tooltip">
<span>tooltip text</span>
<input type="button" class="button active" value = "HOVER ME" >
</div>
https://jsfiddle.net/dy6bjvbm/1/
Start with something like the following:
.tooltip {
position: relative;
display: inline-block;
}
.tooltip span {
display: none;
position: absolute;
top: 30px;
border: 1px solid #ccc;
padding: 5px;
background: #eee;
}
.tooltip:hover span {
display: block;
}
<div class="tooltip">
<span>tooltip text</span>
<input type="button" class="button active" value = "HOVER ME" >
</div>
See this fork of your fiddle: https://jsfiddle.net/b60fcyu1/
If you're up for a JavaScript/jQuery solution, you can use mouseover and mouseout with hide() and show() element.
$(document).ready(function() {
$("input.button").mouseover(function() {
$('div span').hide();
});
$("input.button").mouseout(function() {
$('div span').show();
});
});
.tooltip {
display: relative;
}
.tooltip span:before {
content: '';
display: none;
border-right: 8px solid #000000;
border-top: 8px solid transparent;
border-bottom: 8px solid transparent;
position: absolute;
z-index: 8;
font-size: 0;
line-height: 0;
width: 0;
height: 0;
top: 30%;
left: 83%;
}
.tooltip span:after {
display: none;
position: absolute;
top: 0%;
left: 89%;
padding: 5px 8px;
background: #000000;
color: #fff;
z-index: 9;
font-size: 0.75em;
height: auto;
opacity: 0.8;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
white-space: nowrap;
word-wrap: normal;
}
.tooltip span:hover:before,
.tooltip span:hover:after {
display: block;
}
<script src="https://code.jquery.com/jquery-3.1.1.js"></script>
<div class="tooltip">
<span>tooltip text</span>
<br>
<input type="button" class="button active" value="HOVER ME">
</div>
If you have constant values, you can do it like this. (for more effective with multiple rows)
.tooltip {
position: relative;
width: 300px;
height: 30px;
}
.tooltip span {
opacity: 0;
pointer-events: none;
transition: 0.3s;
width: 100%;
position: absolute;
background-color: rgba(0, 0, 0, 0.6);
color: #ffffff;
line-height: 30px;
bottom: 40px;
border-radius: 5px;
padding: 0 5px;
}
.tooltip span:after {
top: 100%;
left: 50%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
border-color: rgba(0, 0, 0, 0);
border-top-color: rgba(0, 0, 0, 0.6);
border-width: 6px;
margin-left: -6px;
}
.tooltip:hover span {
opacity: 1;
pointer-events: inherit;
}
<p style="height:100px;">
<!-- for seperate -->
</p>
<div class="tooltip">
<span>tooltip text tooltip text tooltip text tooltip text tooltip text tooltip text tooltip text tooltip text</span>
<input type="button" class="button active" value="HOVER ME" style="width:100%;height:30px">
</div>

how to give input border left and right small length

I need to display the input field and i need give border bottom , left and right. But here i want only small portion border left side and right side.
.solid {
border-style: solid;
border-left-style: dashed;
border-top: none;
border-right-style: dashed;
}
<input class="solid">
You can use box-shadow to create this type of border.
input {
width: 300px;
border: none;
margin: 50px;
height: 35px;
box-shadow: 13px 13px 0px -10px #000000, -13px 13px 0px -10px #000000;
outline: none;
font-size: 22px;
background: none;
}
<input type="text">
Here you go. I had to add a div element outside the input field to use the before and after selectors.
.field {
position: relative;
display: inline-block;
}
.solid {
border: none;
border-bottom: 2px solid #000;
padding: 5px;
}
.solid:focus {
outline: none;
}
.field::after {
content: '';
width: 2px;
height: 10px;
position: absolute;
background: #000;
bottom: 0;
right: 0;
}
.field::before {
content: '';
width: 2px;
height: 10px;
position: absolute;
background: #000;
bottom: 0;
left: 0;
z-index: 1;
}
<div class="field">
<input class="solid" type="text">
</div>
Here is how you can give input border left and right of small length
Html
<input type="text">
CSS
input[type="text"] {
padding: 20px;
background: linear-gradient(#000, #000), linear-gradient(#000, #000),linear-gradient(#000, #000);
background-size: 1px 20%, 100% 1px, 1px 20%;
background-position: bottom left, bottom center, bottom right;
background-repeat: no-repeat;
border: none;
color: #999;
}
Find the working fiddle
Reference
html,body,input {
padding: 0;
margin: 0;
border: 0;
background-color: transparent;
}
.input-block {
position: relative;
width: 216px;/* important to define input width;width of input + 2x padding*/
margin: 0 auto;
}
input {
width: 208px;
padding: 0 4px;
outline: none;
border-bottom: 1px solid black;
}
.input-lr-border {
position: absolute;
width: 1px;
background-color: black;
bottom: 0;
height: 4px;
}
.left-border-input {
left: 0;
}
.right-border-input {
right: 0;
}
<div class="input-block">
<div class="left-border-input input-lr-border"></div>
<input/>
<div class="right-border-input input-lr-border"></div>
</div>
li{
list-style: none;
width: 200px;
border-bottom: 2px solid #000;
position: relative;
padding: 2px 5px;
margin: 0 0 10px;
}
li:before, li:after{
background: #000;
content: '';
position: absolute;
bottom: 0;
width: 2px;
height: 5px;
}
li:before{
left: 0;
}
li:after{
right: 0;
}
input{
border:0;
outline: none;
}
<ul>
<li><input type="text" placeholder="First Name" /></li>
<li><input type="text" placeholder="Last Name" /></li>
<li><input type="text" placeholder="Email" /></li>
</ul>

CSS content Property not working as expected in firefox

What i am doing is that in search box when user enter a search term, i display a close button ('x' character to be specific, embedded as content after reset button) to clear the contents of search box.
It works fine in both Chrome and IE but not in firefox.
Any kind of help would be highly appreciated.
.search-box,.close-icon,.search-wrapper {
position: relative;
padding: 10px;
}
.search-wrapper {
width: 500px;
margin: auto;
margin-top: 50px;
}
.search-box:focus {
box-shadow: 0 0 15px 5px #b0e0ee;
border: 2px solid #bebede;
}
.close-icon {
border:1px solid transparent;
background-color: transparent;
display: inline-block;
vertical-align: middle;
outline: 0;
cursor: pointer;
}
.close-icon:after {
content: "X";
display: block;
width: 15px;
height: 15px;
position: absolute;
z-index:1;
right: 35px;
top: 0;
bottom: 0;
margin: auto;
padding: 2px;
border-radius: 50%;
text-align: center;
color: black;
font-weight: normal;
font-size: 12px;
cursor: pointer;
}
.search-box:not(:valid) ~ .close-icon {
display: none;
}
<div class="search-wrapper">
<form>
<input type="text" name="focus" required class="search-box" placeholder="Enter search term" />
<button class="close-icon" type="reset"></button>
</form>
</div>
This code should help you
.search-box,.search-wrapper {
position: relative;
padding: 10px;
}
.search-wrapper {
width: 500px;
margin: auto;
margin-top: 50px;
}
.search-box
{
width:300px;
}
.search-box:focus {
box-shadow: 0 0 15px 5px #b0e0ee;
border: 2px solid #bebede;
}
.close-icon {
border:1px solid transparent;
background-color: transparent,
display: inline-block;
vertical-align: middle;
outline: 0;
position: absolute;
top:19px;
left:305px;
z-index:1;
padding: 1px 2px;
border-radius: 50%;
text-align: center;
color: black;
font-weight: normal;
font-size: 12px;
cursor: pointer;
}
.search-box:not(:valid) ~ .close-icon {
display: none;
}
<div class="search-wrapper">
<form>
<input type="text" name="focus" required class="search-box" placeholder="Enter search term" />
<button class="close-icon" type="reset">X</button>
</form>
</div>
NOTE : set your .search-box width and according to it set left of your .close-icon
Try this code: Hope this solve your problem. Adjust "outer_box" class for width.
<style>
.search-box, .search-wrapper {
padding: 10px;
box-sizing: border-box;
}
.search-box {
position:relative;
width:100%;
}
.outer_boxs{
position:relative;
width:60%;
}
.search-wrapper {
width: 500px;
margin: auto;
margin-top: 50px;
}
.search-box:focus {
box-shadow: 0 0 15px 5px #b0e0ee;
border: 2px solid #bebede;
}
.close-icon {
border:1px solid transparent;
background-color: transparent,
display: inline-block;
vertical-align: middle;
outline: 0;
cursor: pointer;
position: absolute;
right:5px;
top: 10px;
background:#f2f2f2;
}
.search-box:not(:valid) ~ .close-icon {
display: none;
}
</style>
<div class="search-wrapper">
<form>
<div class="outer_boxs" >
<input type="text" name="focus" required class="search-box" placeholder="Enter search term" />
<button class="close-icon" type="reset">X</button>
</div>
</form>
</div>