Apply Focus to tag parent [duplicate] - html

This question already has answers here:
Is there a CSS parent selector?
(33 answers)
Closed 7 years ago.
How to apply if input:focus then parent (div) change color of border?
div {
width: 150px;
height: 26px;
border: 1px solid #ccc;
background: white;
}
input {
outline: none;
border: none;
}
<div>
<input type="text" />
</div>
and div must have border: 1px solid blue; if <input> focused.
jsFiddle

Unfortunately there is currently no 'parent' tag selector in CSS - see this answer here : Is there a CSS parent selector?
The only way to explicitly alter the CSS of the parent div when your input is in focus would be to use JavaScript.
If you're able to use JavaScript in your solution, I can provide an example.

Related

Button Border in CSS [duplicate]

This question already has answers here:
Remove border from buttons
(13 answers)
Closed 1 year ago.
As you can see in the image, when I click the search button on the right there is an orange border, and I would like to remove it. I have tried the following, but it did not work:
.btn-serch:active{
background-color: #92949C;
border:0px solid white;
}
I also tried:
.btn-serch:active{
background-color: #92949C;
border:none;
}
Try this
.btn-serch:active{
background-color: #92949C;
border:none;
outline:none;
}
OR
button:focus {
border: none;
outline: none;
}
You'll want to override the outline property

Why doesnt the hover work on a div that included another div? [duplicate]

This question already has answers here:
What does the "+" (plus sign) CSS selector mean?
(9 answers)
Transitions on the CSS display property
(37 answers)
How to affect other elements when one element is hovered
(9 answers)
Closed 2 years ago.
I just got into html since like 2 weeks and i wanted to create somewhat of a polaroid on which you hover and some information would appear regarding that picture.I think the problem is that i included a div in another one.Also i dont have any program for writing in html yet; just my notepad:)
<style>
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
.info{
position:fixed;
display:none;
align:center;
}
.polaroid {
position: absolute;
box-shadow: 5px 5px 5px 5px rgba(17, 17, 17, 0.35) ;
padding: 7px;
width:220px;
height:inherit;
background-color:white;
transition: 1s;
}
.polaroid:hover+ .info{display:block;}
</style>
<div class="polaroid">
<img src="https://katsosco.gr/media/images/products/images/2_MT_GlacierNP500px-200x200.jpg" align="center">
<div class="info"><p>This is just some random information which should appear extending the polaroid when i hover over it</p>
</div>
</div>
</body>```
+ is a sibling combinator which selects adjacent sibling elements.
You need child combinator > to select .info element inside .polaroid
.polaroid:hover > .info{
display:block;
}

CSS first-of-type applying to all [duplicate]

This question already has answers here:
CSS3 selector :first-of-type with class name?
(10 answers)
Closed 4 years ago.
Having some issues targeting the a div using the CSS :first-of-type and applying the styling to all. Any ideas on where I'm going wrong?
Working example here
.message:first-of-type {
background: purple;
}
If you want purple background only for first .message use below css. Pseudoclass :first-of-type it's only for type (div, p etc), not class.
.message {
background: purple;
}
.message ~ .message {
background: none;
}

How can I get a thicker underline? [duplicate]

This question already has answers here:
Is there any way to make the HTML underline thicker?
(5 answers)
Closed 8 years ago.
I have some bold text and would like to underline to appear bold as well.
HTML
<p>Home Page</p>
CSS
p {
text-decoration: underline;
}
jsFiddle
I tried several thing but they didn't work well.
You can use border-bottom with some padding:
display:inline-block;
border-bottom:solid 2px red;
padding-bottom:2px;
JSFiddle
Edit:
To achieve the effect you want, you can wrap the text with a <span>: JSFiddle
One possible approach is to use pseudo-element :after to mimic border. Benefit in this case is that it's easy to control "border" offset with margin-top. For example:
p {
display: inline-block;
}
p:after {
content: '';
display: block;
height: 2px;
background: red;
margin-top: -1px;
}
<p>Home Page</p>

Pseudo element strange behaviour with img [duplicate]

This question already has answers here:
Does :before not work on img elements?
(16 answers)
Closed 7 years ago.
Trying to make information about image below it. But have A problem... Pseudo element is not visible..
<img info="hey guys" src="http://i024.radikal.ru/1211/4c/809c7c2dfa74.jpg">
<div info="I'm working, but I'm inside the block"></div>
div {
height: 100px;
margin: 10px;
background: yellow;
}
div[info]::after, img[info]::after {
content: attr(info);
display: block;
margin: 3px;
color: black;
font-style: italic;
}
Jsfiddle DEMO
Thanks.
img elements can't have pseudo elements, because they can't have children—::before is inserted within the element. It would look like this:
<img><before></img>
Or at least itt isn't defined by the spec
This specification does not fully define the interaction of :before and :after with replaced elements (such as IMG in HTML). This will be defined in more detail in a future specification.
Pseudo elements are appended/prepended to the element's contents. Since an <img> (and an <input> for instance) has no contents, it cannot have pseudo elements applied on it.