Hover on child element <button> without hover effect on parent <h2>
.parent {
display: block;
text-align: center;
font-weight: 700;
font-size: 31px;
letter-spacing: normal;
position: relative;
}
.parent:hover {
color: orange;
}
span {
line-height: unset;
vertical-align: baseline;
top: 0;
left: 0;
position: absolute;
color: transparent;
box-shadow: none;
z-index: 5;
}
span button {
position: absolute;
left: 0;
top: -20px;
color: #fff;
width: 30px;
height: 30px;
min-width: 30px;
min-height: 30px;
z-index: 5;
background: #0085ba !important;
border-radius: 50%;
border: 2px solid #fff;
box-sizing: border-box;
padding: 3px;
display: inline-block;
overflow: hidden;
}
<h2 class="parent">
Title
<span class="child">
<button>+</button>
</span>
</h2>
This can be helpful
example
.html
<div class="parent1">
<div class="child1">
/*.....*/
.css
.parent1:hover{
cursor: pointer;
}
.parent1:hover .child1{
/*......*/
}
snippet
.parent:hover .child {
/* ... */
}
Add the below:
parent:hover {
cursor:pointer
}
It's a little tricky.
First you need to get the parent from the child :
const _parent = document.querySelector('selectorOfParentFromChild')
After you have to add the class on child and remove on parent. You need to do it one child event : 'onMouseOver'.
SO:
[child, parent].forEach(node=>node.addEvenListener('onmouseover', (event)=>{
event.stopPropagation();
const _parent = document.querySelector('selectorOfParentFromChild')
node.classlist.add(wanted)
_parent.classlist.remove(wanted)
})
This has been asked before, and answers seem to come within the span of: "css can't do that", "you should probably restructure your divs" and "here's a trick".
hover on child without hover effect on parent
Now I don't have the experience to say if a structure that neccesitates this is actually bad, but in either case, there is now a straight-forward solution with :has()
.parent {
display: block;
text-align: center;
font-weight: 700;
font-size: 31px;
letter-spacing: normal;
position: relative;
}
.parent:not(:has(.child:hover)):hover {
color: orange;
}
span {
line-height: unset;
vertical-align: baseline;
top: 0;
left: 0;
position: absolute;
color: transparent;
box-shadow: none;
z-index: 5;
}
span button {
position: absolute;
left: 0;
top: -20px;
color: #fff;
width: 30px;
height: 30px;
min-width: 30px;
min-height: 30px;
z-index: 5;
background: #0085ba !important;
border-radius: 50%;
border: 2px solid #fff;
box-sizing: border-box;
padding: 3px;
display: inline-block;
overflow: hidden;
}
<h2 class="parent">
Title
<span class="child">
<button>+</button>
</span>
</h2>
This is what that selector is saying in English:
Select all elements ".parent" - except the ones who have any child elements ".child" being hovered on - when they are hovered on.
You will have to delete the CSS for parent:hover and if you only want the hover effect on the button then the parent shouldn't have a hover effect in your CSS.
.parent {
display: block;
text-align: center;
font-weight: 700;
font-size: 31px;
letter-spacing: normal;
position: relative;
}
span {
line-height: unset;
vertical-align: baseline;
top: 0;
left: 0;
position: absolute;
color: transparent;
box-shadow: none;
z-index: 5;
}
span button {
position: absolute;
left: 0;
top: -20px;
color: #fff;
width: 30px;
height: 30px;
min-width: 30px;
min-height: 30px;
z-index: 5;
background: #0085ba !important;
border-radius: 50%;
border: 2px solid #fff;
box-sizing: border-box;
padding: 3px;
display: inline-block;
overflow: hidden;
}
button:hover {
color: orange;
}
Related
I am trying to style a select drop down box. The custom select box has rounded corners and a dropdown list (a box that drops down with the options) that shows on focus. I used the css below to style the select box. I have also substituted the html select with DIV elements.
Here is the code I have used so far:
document.querySelector('.custom-select-wrapper').addEventListener('click', function() {
this.querySelector('.custom-select').classList.toggle('open');
for (const option of document.querySelectorAll(".custom-option")) {
option.addEventListener('click', function() {
if (!this.classList.contains('selected')) {
this.parentNode.querySelector('.custom-option.selected').classList.remove('selected');
this.classList.add('selected');
this.closest('.custom-select').querySelector('.custom-select__trigger span').textContent = this.textContent;
}
})
}
})
.custom-select-wrapper {
position: relative;
user-select: none;
width: 188px;
z-index: 30000000000;
}
.custom-select {
position: relative;
display: flex;
flex-direction: column;
}
.custom-select__trigger {
position: relative;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 10px;
height: 27px;
background: #ffffff;
cursor: pointer;
border: 1px solid #707070;
border-radius: 8px;
}
.custom-options {
position: absolute;
display: block;
top: 100%;
left: 0;
right: 0;
border: 1px solid #707070;
border-bottom-left-radius: 8px;
border-bottom-right-radius: 8px;
background: #fff;
transition: all 0.5s;
opacity: 0;
visibility: hidden;
pointer-events: none;
z-index: 2;
}
.custom-select.open .custom-options {
opacity: 1;
visibility: visible;
pointer-events: all;
}
.custom-option {
position: relative;
display: block;
padding: 0 10px 0 10px;
line-height: 25px;
cursor: pointer;
transition: all 0.5s;
}
.arrow {
position: relative;
top: 15px;
right: 15px;
}
.arrow::before,
.arrow::after {
content: "\f0d7";
font-family: "Font Awesome 5 Free";
font-size: 20px;
font-weight: 700;
color: #394a6d;
position: absolute;
bottom: 0px;
}
<div class="custom-select-wrapper">
<div class="custom-select">
<div class="custom-select__trigger">
<span>Option 1</span>
<div class="arrow"></div>
</div>
<div class="custom-options">
<span class="custom-option selected" data-value="tesla">Option 2</span>
<span class="custom-option" data-value="volvo">Option 3</span>
</div>
</div>
</div>
The styles I have applied to the select tag are coming into effect, but the problem is that the dropdown box top border does not blend with the select box itself on focus. Is it only possible to change the SELECT input style on focus from a round border to a square border?
Would someone with some more knowledge in this regard please take a few minutes to suggest a solution?
It depends on what you mean by "blending", but if you want to achieve a more harmonious look, you can do the following:
Set the border-bottom-left-radius and border-bottom-right-radius of the trigger element to 0px when the dropdown is open, so that the select trigger visually continues to the dropdown that is visible
Remove the top border of the dropdown, so that you don't have a doubly-thick border separating the trigger and the dropdown
See proof-of-concept below:
document.querySelector('.custom-select-wrapper').addEventListener('click', function() {
this.querySelector('.custom-select').classList.toggle('open');
for (const option of document.querySelectorAll(".custom-option")) {
option.addEventListener('click', function() {
if (!this.classList.contains('selected')) {
this.parentNode.querySelector('.custom-option.selected').classList.remove('selected');
this.classList.add('selected');
this.closest('.custom-select').querySelector('.custom-select__trigger span').textContent = this.textContent;
}
})
}
})
.custom-select-wrapper {
position: relative;
user-select: none;
width: 188px;
z-index: 30000000000;
}
.custom-select {
position: relative;
display: flex;
flex-direction: column;
}
.custom-select__trigger {
position: relative;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 10px;
height: 27px;
background: #ffffff;
cursor: pointer;
border: 1px solid #707070;
border-radius: 8px;
transition: all 0.5s;
}
.custom-options {
position: absolute;
display: block;
top: 100%;
left: 0;
right: 0;
border: 1px solid #707070;
border-top: none;
border-bottom-left-radius: 8px;
border-bottom-right-radius: 8px;
background: #fff;
transition: all 0.5s;
opacity: 0;
visibility: hidden;
pointer-events: none;
z-index: 2;
}
.custom-select.open .custom-select__trigger {
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
}
.custom-select.open .custom-options {
opacity: 1;
visibility: visible;
pointer-events: all;
}
.custom-option {
position: relative;
display: block;
padding: 0 10px 0 10px;
line-height: 25px;
cursor: pointer;
transition: all 0.5s;
}
.arrow {
position: relative;
top: 15px;
right: 15px;
}
.arrow::before,
.arrow::after {
content: "\f0d7";
font-family: "Font Awesome 5 Free";
font-size: 20px;
font-weight: 700;
color: #394a6d;
position: absolute;
bottom: 0px;
}
<div class="custom-select-wrapper">
<div class="custom-select">
<div class="custom-select__trigger">
<span>Option 1</span>
<div class="arrow"></div>
</div>
<div class="custom-options">
<span class="custom-option selected" data-value="tesla">Option 2</span>
<span class="custom-option" data-value="volvo">Option 3</span>
</div>
</div>
</div>
The above code is a solution strictly from a styling point of view. But as per #CBroe remarks, from a usability point of view (for example using the select via keyboard is impossible), the code is not optimal.
This is why I came up with a solution that uses the jQuery plugin Select2
If anyone is interested here is a link to the code
https://www.codeply.com/p/Z999PpuSOK
I need to achieve this button.
Here is my code so far:
.button {
border-color: red;
border-radius: 8px
}
.button::after {
content: '';
background-color: red;
display: block;
width: inherit;
height: 3px;
}
<button class="button">Click me </button>
The problem is that the width covers 100% of the screen, and I need the width of the button; I can't give a specific width to this button because it will receive dynamic text.
You just need to wrap the button in a div with display: inline-block to prevent it going full-width and relative positioning so it can contain an absolutely positioned element inside and from the looks of your image some padding on that element as well to create some space between the button and the line below. Then make your :after pseudo element absolutely positioned and give it width: 100%.
div {
position: relative;
padding: .75rem .5rem;
box-sizing: border-box;
display: inline-block
}
button {
background: transparent;
border-radius: .5rem;
border: 3px solid #EF544F;
padding: .5rem;
color: #EF544F;
font-weight: 600;
font-size: 1.2rem
}
button::after {
content: '';
background-color: #EF544F;
display: block;
position: absolute;
width: inherit;
height: 4px;
width: 100%;
bottom: 0;
left: 0;
border-radius: 999px;
}
<div>
<button>Click me</button>
</div>
This seems to be like on picture:
.button
{
border-radius: 0.5em;
padding: 0.4em 0.8em 0.2em 0.8em;
color: red;
font-weight: bold;
border: 2px solid red;
background-color: transparent;
}
.button::after
{
content: '';
background-color:red;
display: block;
height: 3px;
position: relative;
left: -1.3em;
bottom: -1em;
width: calc(100% + 2.6em);
}
<button class="button">Tab Tile</button>
you can try min-width
.button::after{
content: '';
background-color:red;
display: inline-block;
width: auto;
height: 3px;
min-width:100px;
}
I want to make a line between two circles, for that, I have used the below code by using pseudo-element CSS. I would like to make the line between these two circles responsive, now it's intersecting with circle in some other devices like mobile, etc. How to make it responsive or any other solution that does the same design? Please help.
.cart_header_tab {
display: flex;
margin-top: 35px;
}
.cart_header_tab > div {
text-align: center;
margin-right: 100px;
cursor: pointer;
}
.cart_header_tab h6 {
color:#02b5f9;
font-weight: 400;
}
.cart_header_tab div:last-child h6 {
color:#ccc
}
span.circle_one::after {
content: "";
width: 152px;
height: 1px;
background: #eee;
position: absolute;
top: 6px;
left: 14px;
}
.cart_header_tab span.circle_one {
border: 1px solid #2fe4ba;
}
.cart_header_tab span {
display: inline-block;
width: 16px;
height: 16px;
border: 1px solid #ccc;
border-radius: 100%;
position: relative;
}
<div class="cart_header_tab">
<div>
<span class="circle_one"></span>
<h6>Order Details</h6>
</div>
<div>
<span class="circle_two"></span>
<h6>Freight Options</h6>
</div>
</div>
You can start tweaking the code something like this:
Be aware that if you wanted to change the size or width of the circle you have to tweak the other property in the css, hope that is not an issue here.
#cart_header_tab {
position: relative;
display: inline-block;
}
#cart_header_tab::after {
content: "";
position: absolute;
width: 50%;
z-index: -1;
top: 20%;
left: 25%;
border: 1px solid gray;
/* line between circles */
}
#cart_header_tab div {
display: inline-block;
font-size: 12px;
text-align: center;
min-width: 150px;
}
#cart_header_tab span {
color: white;
background: white;
display: block;
height: 15px;
margin: 0 auto 10px;
padding-top: 20px;
width: 30px;
border-radius: 50%;
border: 1px solid #22A7F2;
}
<div id="cart_header_tab">
<div><span class="circle_one"></span>
<h6>Order Details</h6>
</div>
<div><span class="circle_two"></span>
<h6>Freight Options</h6>
</div>
</div>
Using flex i insert that line between circle as separator itself is a child of flex and hen using margin adjust that according to circles
.cart_header_tab {
display: flex;
margin-top: 35px;
}
.cart_header_tab>div {
text-align: center;
cursor: pointer;
}
.cart_header_tab h6 {
color: #02b5f9;
font-weight: 400;
}
.cart_header_tab div:last-child h6 {
color: #ccc
}
.cart_header_tab {
position: relative
}
.sep {
width: 100%;
height: 1px;
background: #eee;
margin: 9px -21px 0;
}
.cart_header_tab span.circle_one {
border: 1px solid #2fe4ba;
background: #fff;
z-index: 1;
}
.circle_two {
background: #fff;
z-index: 1;
}
.cart_header_tab span {
display: inline-block;
width: 16px;
height: 16px;
border: 1px solid #ccc;
border-radius: 100%;
position: relative;
}
<div class="cart_header_tab">
<div>
<span class="circle_one"></span>
<h6>Order Details</h6>
</div>
<div class="sep"></div>
<div>
<span class="circle_two"></span>
<h6>Freight Options</h6>
</div>
</div>
I am in the learning of coding so I'm very new to this. But I'm pretty sure I could set up my code a much better way than i have done, could anyone tell me what I can do better? Reason for asking is to be better on it.
HTML Code:
<div class="infobox">
<h3>Pinstripe Suit Jacket</h3>
<div class="suggested">
<div class="sug-text">
<h4 class="opskinsug">OPSkins Suggested:</h4>
<h4 class="survivorsug">Survivor's Suggested:</h4>
</div>
<div class="sug-price">
<h4 class="opssug">$0.26</h4>
<h4 class="survsug">$0.27</h4>
</div>
</div>
<div class="cheap" id="pinstripe-jacket">
<p> 44</p>
</div>
<img src="images/pinstripesuitjacket.png" width="300" >
</div>
CSS Code:
.infobox {
background-color: rgba(0, 0, 0, 0.3);
position: relative;
text-align: center;
border-style: solid;
border-color: orange;
border-width: 1px;
border-radius: 25px;
width: 250px;
height: 300px;
display: inline-block;
margin-left: 20px;
}
.infobox a:link {
color: #fff;
text-decoration: none;
}
.infobox a:visited {
color: #fff;
}
.infobox a:hover {
color: black;
}
.infobox h3 {
background-color: orange;
}
.infobox img {
position: relative;
top: -232px;
left: 15px;
z-index: 0;
}
.opskinsug {
font-size: 13px;
text-align: center;
width: 100px;
position: relative;
left: -20px;
z-index: 1;
display: inline-block;
}
.survivorsug {
position: relative;
text-align: center;
left: 20px;
font-size: 13px;
width: 100px;
z-index: 1;
display: inline-block;
}
.opssug {
position: relative;
text-align: center;
width: 100px;
left: -20px;
font-size: 20px;
color: #fff;
top: -40px;
z-index: 1;
display: inline-block;
}
.survsug {
text-align: center;
position: relative;
width: 100px;
font-size: 20px;
left: 20px;
top: -40px;
color: #fff;
z-index: 1;
display: inline-block;
}
.suggested {
background-color: rgba(255, 165, 0, 0.4);
height: 70px;
position: relative;
z-index: 1;
}
.sug-text {
position: relative;
top: -5px;
}
.sug-price {
position: relative;
top: -8px;
}
.cheap {
position: relative;
z-index: 1;
font-size: 52px;
display: inline-block;
left: -70px;
color: #fff;
}
on my screen its looking like this:
preview
Here's an updated HTML. I've replaced the inner <div>s with a definition list <dl>, which isn't entirely meant for this use, but since you're having 1 on 1 relationship with heading and price, it can be used for this. I also removed the <p> inside the last <div>, since that is not a paragraph in any way, and you can position it inside the <div> (no need for a wrapper, really). I didn't do the CSS, but it should be fairly simple to reformat it to fit the new HTML.
<div class="infobox">
<h3>Pinstripe Suit Jacket</h3>
<div class="suggested">
<dl>
<dt>OPSkins Suggested:</dt>
<dd>$0.26</dd>
</dl>
<dl>
<dt>Survivor's Suggested:</dt>
<dd>$0.27</dd>
</dl>
</div>
<div class="cheap" id="pinstripe-jacket">
44
</div>
<img src="images/pinstripesuitjacket.png" width="300">
</div>
I've got an <input>-element. I'd like to precede it with a search-icon using the :before selector including a SVG-font I created.
.icon-search:before {
content: "\f109";
text-indent: -2em;
}
My problem is that the pseudo-selector :beforedoesn't seem to work with <input> Can you tell me how to make this work in the most elegant way?
This is how I want it to look once I'm done.
The before/after pseudo element is contained inside the element but input can't have that, so you have to use another selector like span or div. This is an implementation similar to what bootstrap does...
FIDDLE
HTML:
<div class="wrapper">
<div class="inputgroup"> <span class="innericon searchicon"></span>
<input type="text" class="search" placeholder="search..." />
</div>
</div>
CSS:
body {
color: gray;
}
.wrapper {
margin: 20px auto;
width: 40%;
}
* {
box-sizing: border-box;
}
.inputgroup {
position:relative;
display: inline-block;
height: 30px;
line-height: 30px;
vertical-align: middle;
}
.search {
border-radius: 8px;
height: 30px;
line-height: 30px;
padding: 3px 6px 3px 32px;
border: none;
font-size: 13px;
display: inline-block;
vertical-align: middle;
border: 1px solid #CCC;
box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.075) inset;
}
.inputgroup .innericon {
position: absolute;
top: 4px;
left: 8px;
z-index: 2;
display: block;
text-align: center;
pointer-events: none;
}
.searchicon:before {
content: "\f109";
}
Here is one way to achieve this: http://jsfiddle.net/n9gjb3kr/
You need to put your input inside a div:
<div class="icon-search"><input type="text"></input></div>
.icon-search:before {
content: "\f109";
position: absolute;
left: 0;
top: 0;
height: 24px;
width: 24px;
margin-left: .5em;
width: 0;
overflow: visible;
display: inline-block;
line-height: 24px;
z-index: 1;
}
.icon-search {
position: relative;
line-height: 24px;
}
.icon-search > input {
border-radius: 12px;
height: 24px;
border: 1px solid black;
margin: 0;
padding: 0;
padding-left: 32px;
}
You can wrap the input into span, setting the span with position:relative and
then add to input and icon position:absolute and play with margins and z-index to create the same effect. This is pretty solid for responsive as well, if you style the span and the input the right way taking the responsive design in account.
OR
Using jquery as already mentioned in the comments