I'm new at CSS and front-end programming. I want to display two icons next to a button after the button is hovered. But in my code, the icons are not displaying after hover effect. Can you help please ?
#submit-btn {
padding: 15px 50px;
background-color: whitesmoke;
color: #333;
border: none;
font-weight: 700;
transition: background-color .3s;
}
#submit-btn:hover {
background-color: #870F02;
color: whitesmoke;
box-shadow: 10px 10px 8px #62F0AA;
}
.fa-hand-point-right,
.fa-hand-point-left {
display: none;
}
#submit-btn:hover .fa-hand-point-left,
#submit-btn:hover .fa-hand-point-right {
display: block;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css" integrity="sha512-MV7K8+y+gLIBoVD59lQIYicR65iaqukzvf/nwasF0nqhPay5w/9lJmVM2hMDcnK1OnMGCdVK+iQrJ7lzPJQd1w==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<div class="col-12 mt-5 submit-input d-flex justify-content-center align-items-center">
<i class="fa-solid fa-2xl fa-hand-point-right me-3"></i>
<button id="submit-btn" class="btn" type="submit">PROJEYİ GÖNDER</button>
<i class="fa-solid fa-2xl fa-hand-point-left ms-3"></i>
</div>
You've implemented descendant selectors, but the icons are siblings of the button. Since there are no previous sibling selectors in CSS, you have a few options:
Use a wrapping element as a hover target.
Place the icons inside the button element.
Use JavaScript to enact the hover effect on specific elements.
Here I demonstrate the first option. I'm loading Bootstrap to leverage the d-inline-block class, which makes the div shrink to the size of the elements inside. I've also used opacity instead of display, as display: none removes the elements from the document flow. This can cause ugly shifting of things on hover. Since your button is centered it doesn't, but it easily could if your alignment changed. Also, you can animate opacity to match your button styles.
The drawback to this approach is that the effect occurs when hovering over the hidden icons also. The same would be true for option 2.
#submit-btn {
padding: 15px 50px;
background-color: whitesmoke;
color: #333;
border: none;
font-weight: 700;
transition: background-color .3s;
}
#submit-btn:hover {
background-color: #870F02;
color: whitesmoke;
box-shadow: 10px 10px 8px #62F0AA;
}
.fa-hand-point-right,
.fa-hand-point-left {
opacity: 0;
transition: opacity 0.3s;
}
.hover-target:hover .fa-hand-point-left,
.hover-target:hover .fa-hand-point-right {
opacity: 1;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.3/dist/css/bootstrap.min.css" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css" integrity="sha512-MV7K8+y+gLIBoVD59lQIYicR65iaqukzvf/nwasF0nqhPay5w/9lJmVM2hMDcnK1OnMGCdVK+iQrJ7lzPJQd1w==" crossorigin="anonymous" referrerpolicy="no-referrer"
/>
<div class="col-12 mt-5 submit-input d-flex justify-content-center align-items-center">
<div class="d-inline-block hover-target">
<i class="fa-solid fa-2xl fa-hand-point-right me-3"></i>
<button id="submit-btn" class="btn" type="submit">PROJEYİ GÖNDER</button>
<i class="fa-solid fa-2xl fa-hand-point-left ms-3"></i>
</div>
</div>
Related
I am having an issue with my hero. For some reason this is appearing: https://gyazo.com/08edee1edcd0469d50da4883498a7f0a
This is my html (using bootstrap 5) and CSS. I've not styled it to do that, so I have no idea.
I've tried removing outline and border and it has not worked.
.hero-btn {
background-color: rgba(0, 0, 0, 0.6);
color: whitesmoke;
width: 18rem;
height: 5rem;
margin: 15px;
border-radius: 25px;
font-size: larger;
}
.hero-btn:hover {
color: white;
text-transform: uppercase;
font-weight: bold;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.3/dist/css/bootstrap.min.css" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<div class="pt-3">
<h1 style="font-weight: 600;">West Yorkshire Roleplay</h1>
<br>
<h4>Welcome to West Yorkshire Roleplay!</h4>
</div>
<div class="mx-auto my-auto">
<a href="https://storm.westyorkshireroleplay.com/signup">
<button class="btn hero-btn">Apply Now</button>
</a>
<a href="https://storm.westyorkshireroleplay.com/communityinfo">
<button class="btn hero-btn">About Us</button>
</a>
</div>
<a href="#contact">
<img src="https://i.imgur.com/uvPeSwr.png" alt="" style="width:auto; height: 70px; position: relative; bottom: -45%;">
</a>
You have added <button> tag inside <a> tag which is wrong. The blue line is because of <a> shows hyper link style to text place inside it, in your case its assuming white space as text and thus showing blue dash.
As you have shared image for reference, it displays default css style for <button> tag.
Check if this css styling suits your need.
.hero-btn {
background-color: rgba(0, 0, 0, 0.6);
color: whitesmoke;
width: 18rem;
height: 5rem;
letter-spacing: normal;
word-spacing: normal;
line-height: 4;
text-align: center;
appearance: auto;
border-width: 2px;
border-style: outset;
border-color: buttonborder;
cursor: default;
box-sizing: border-box;
margin: 15px;
border-radius: 25px;
text-decoration: none;
font-size: larger;
}
.hero-btn:hover {
color: white;
text-transform: uppercase;
font-weight: bold;
}
<div class="pt-3">
<h1 style="font-weight: 600;">West Yorkshire Roleplay</h1>
<br>
<h4>Welcome to West Yorkshire Roleplay!</h4>
</div>
<div class="mx-auto my-auto">
<a class="btn hero-btn" href="https://storm.westyorkshireroleplay.com/signup">
Apply Now
</a>
<a class="btn hero-btn" href="https://storm.westyorkshireroleplay.com/communityinfo">
About Us
</a>
</div>
<a href="#contact">
<img src="https://i.imgur.com/uvPeSwr.png" alt="" style="width:auto; height: 70px; position: relative; bottom: -45%;">
</a>
What you're seeing is whitespace styled as a link due to your faulty HTML. Buttons have no business inside anchors. They each have a particular purpose (buttons for action, anchors for navigation) and should never be used together. If you want anchors styled as buttons, use the appropriate button classes. If you want buttons styled as text links, do the same.
Other advice...
Don't use inline styles. It's a pain for you and it's a pain for us and it's a pain for everyone who comes after. Use Bootstrap classes where you can (border radius, font size, font weight), and use custom classes with CSS everywhere else.
And don't use line breaks for spacing. That's not their purpose. Use margin or padding.
The my-auto class probably isn't doing what you think it's doing. Look into flexbox if you want to center things vertically. Of course you have to provide space in which to center.
Always strive for the simplest implementation possible. That means knowing what your library offers, and applying styling directly to elements when possible, as opposed to container elements that aren't necessary. Recognize that almost everything has relative position by default.
Finally, keep visual effects like hover changes subtle. This isn't Nintendo World. You don't want to nauseate your users with obnoxious behavior. A soft shadow or slight movement with animation to be easier on the eyes is often best.
body {
background: #ddd !important;
}
.hero-btn {
background-color: rgba(0, 0, 0, 0.6);
color: whitesmoke;
width: 18rem;
height: 5rem;
margin: 15px;
border-radius: 25px;
font-size: larger;
}
.hero-btn:hover {
color: white;
text-transform: uppercase;
font-weight: bold;
}
.fw-600 {
font-weight: 600;
}
.down-img {
width: auto;
height: 70px;
bottom: -45%;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.3/dist/css/bootstrap.min.css" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<h1 class="pt-3 pb-2 fw-600">West Yorkshire Roleplay</h1>
<h4>Welcome to West Yorkshire Roleplay!</h4>
<div class="mx-auto my-auto">
Apply Now
About Us
</div>
<a href="#contact">
<img src="https://i.imgur.com/uvPeSwr.png" class="down-img" alt="">
</a>
I have a html (with bootstrap) and a CSS, and in my html I have an <hr> tag which has a class, then in my CSS I have it styled with border. It is translucent, you can see the white, but it isn't "solid". I want it to be completely solid, and not like pale I guess.
body { background-color: #1b3b3c !important; color: white !important; }
.hr-left-bold {
border: 0.2rem solid #fff;
border-radius: 100rem;
width: 20rem;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.3/dist/css/bootstrap.min.css" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<h3>Kérdés Cím</h3>
<hr class="hr-left-bold">
<p>Nem kéne így hagyni...</p>
<hr class="hr-left-bold">
<img src="./src/upvote.png" alt="like" class="img-fluid vote-img px-1">
<img src="./src/downvote.png" alt="like" class="img-fluid vote-img px-1">
Here's what it looks like:
I tried to style it with border-top, color, everything to be honest and nothing works.
Here's how I want it to look:
In newer bootstrap versions there are special "vertical rule" classes / rules which have some transparency.
To avoid that, add opacity: 1.0; to your CSS rule.
body {
background-color: #1b3b3c !important;
color: white !important;
}
.hr-left-bold {
border: 0.2rem solid #fff;
border-radius: 100rem;
width: 20rem;
opacity: 1.0;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.3/dist/css/bootstrap.min.css" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<h3>Kérdés Cím</h3>
<hr class="hr-left-bold">
<p>Nem kéne így hagyni...</p>
<hr class="hr-left-bold">
<img src="./src/upvote.png" alt="like" class="img-fluid vote-img px-1">
<img src="./src/downvote.png" alt="like" class="img-fluid vote-img px-1">
I put the web into the IOS app as a webview.
When I use the <detail> tag of html 5, I want to change it's display to flex not block,in web it can work but it cannot work on the phone
This is my code, is there any mistake?
details summary::-webkit-details-marker {
display: none;
}
details{
width:100%;
}
details summary {
width: 100%;
/* padding: 0.5rem 0; */
border-bottom: 1px solid #dddddd;
position: relative;
cursor: pointer;
font-size: 1.25rem;
font-weight: 300;
list-style: none;
float:left;
}
details summary:after {
content: "click me";
color: black;
right: 0;
transform-origin: center;
transition: 200ms linear;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
<details style="display: flex; ">
<summary class="d-flex">
<div class="mr-3 w-75">
<p class="font-weight-bold mb-0">title</p>
</div>
<div class="mr-3 w-75">
<p class="font-weight-bold mb-0">date</p>
<span class="t-12">time</span>
</div>
</summary>
<p>
<pre class="d-inline">content</pre>
</p>
</details>
This issue is documented here: https://github.com/philipwalton/flexbugs#flexbug-9
The following workaround was proposed there:
The simple solution to this problem is to use a wrapper element that can be a flex container (like a ) directly inside of the element that can't. Demos 9.1.b and 9.2.b show workaround for the and elements, respectively.
In your case you should wrap your elements that should be displayed as flex in a wrapper element like a div.
I also faced a similar issue: the flex properties were not working with the summary tags in a WebView, otherwise working on a normal browser. The only workaround I found was to recreate the details-summary tag functionality with javascript by changing the display property.
document.querySelector('.summary').addEventListener('click', function() {
let collapsible = this.nextElementSibling
collapsible.classList.toggle('d-block')
})
section {
width: 100%;
}
.collapsible {
display: none;
overflow: hidden;
}
.summary {
width: 100%;
/* padding: 0.5rem 0; */
border-bottom: 1px solid #dddddd;
position: relative;
cursor: pointer;
font-size: 1.25rem;
font-weight: 300;
list-style: none;
}
.summary::after {
content: "click me";
color: black;
right: 0;
transform-origin: center;
transition: 200ms linear;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet" />
<section>
<div class="d-flex summary">
<div class="mr-3 w-75">
<p class="font-weight-bold mb-0">title</p>
</div>
<div class="mr-3 w-75">
<p class="font-weight-bold mb-0">date</p>
<span class="t-12">time</span>
</div>
</div>
<div class="collapsible">
<pre class="d-inline">content</pre>
</div>
</section>
i have meet same issue.when i use flex in ssummary tag.i think a good way is not to use flex instead of using other css layout ways.
position:absolute;
use trandition css to manage our child
I have a list of users, with two inline elements: a "contact me" button ('a' element with a fontawesome icon) and a tag showing the type of user (span element).
Not all users have a tag, and whenever there is a tag, the 'a' element is giving to the icon more width than it needs. This is how it looks like:
As you can see, the bottom one fits correctly, while the blue space of the top one is bigger on the right. They have the exact same classes and attributes (this is generated from a loop, so it's the same code).
This is the HTML code for the link+span:
.item-title {
margin-bottom: 10px;
}
.item-btn-contact {
margin-left: 10px;
padding: 3px 10px;
border-radius: 5px;
background-color: #1b95e0;
font-size: 80%;
color: #fff;
text-decoration: none;
}
.item-type-tag {
margin-left: 10px;
padding: 3px 5px;
border-radius: 5px;
background-color: #dedede;
font-weight: bold;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css" rel="stylesheet"/>
<div class="item-title">
xxxx
<a href="" class="item-btn-contact" title="Contattami">
<i class="fas fa-envelope"></i>
</a>
<span class="item-type-tag">Allenatore</span>
</div>
<div class="item-title">
xxxx
<a href="" class="item-btn-contact" title="Contattami">
<i class="fas fa-envelope"></i>
</a>
</div>
I tried checking if there was any difference in the cumputed styles of the two elements through javascript (maybe there was a ":last-child" selector somewhere), but their maps looks exactly the same (checked using getComputedStyle on both elements).
Whenever I change the span element display property to block, flex, or other not-inline options, the other element resize itself in the correct way.
The only option I found is to change the icon width to .8em (currently 1em), and then add a last-child selector to resize it correctly to 1em when there is no span on the right, but it's not a real solution...
Could anyone help me figure out why, or at least how to fix it?
Set the display on item-btn-contact to inline-block. Seems like the default display of a (inline) is messing with the sizing.
.item-title {
margin-bottom: 10px;
}
.item-btn-contact {
margin-left: 10px;
padding: 3px 10px;
border-radius: 5px;
background-color: #1b95e0;
font-size: 80%;
color: #fff;
text-decoration: none;
display: inline-block;
}
.item-type-tag {
margin-left: 10px;
padding: 3px 5px;
border-radius: 5px;
background-color: #dedede;
font-weight: bold;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css" rel="stylesheet"/>
<div class="item-title">
xxxx
<a href="" class="item-btn-contact" title="Contattami">
<i class="fas fa-envelope"></i>
</a>
<span class="item-type-tag">Allenatore</span>
</div>
<div class="item-title">
xxxx
<a href="" class="item-btn-contact" title="Contattami">
<i class="fas fa-envelope"></i>
</a>
</div>
I have five links at the bottom of my page. Next to each link is an <i></i> with a Font Awesome heart icon class attribute. I am trying to have the icons not be displayed until the links are hovered over. I have a few questions/issues:
1) Display: hidden would not work on the icons. Is that normal? Visibility: hidden did make them disappear, but as with the visibility property, it did not remove them from the document flow.
2) I could not get the icons to reappear when hovering over the links. The only way I could get them to reappear on hover is by using:
.main-nav__link-container:hover .main-nav__link__icon {
visibility: initial;
}
The problem with the above CSS is that the entire div being hovered over will show the heart, which means I can hover over an area that is not a link (the area where the icon is), and the icon will pop up, but not be clickable. I only want the icon to show up when the actual link is hovered over. Any idea how to do this?
Codepen with full html/css (code associated with question is at the bottom of both the html and css). I have commented out visibility: hidden for the icons so that you can see where they are:
https://codepen.io/pmc222/pen/jvJRyg
HTML
/* Styles link flex items */
.main-nav__link {
text-decoration: none;
color: rgb(0, 0, 0);
font-family: "Montserrat", sans-serif;
font-size: 0.9rem;
letter-spacing: 0.2em;
padding-bottom: 5px;
text-transform: uppercase;
}
/* Styles icon font next to nav links */
.main-nav__link__icon {
display: none;
font-size: 0.9em;
color: rgba(0, 0, 0, 0.6);
margin-right: 3px;
visibility: hidden;
}
*unsure what selector to put here* .main-nav__link__icon {
visibility: initial;
}
/* Adds underline to links on mouse over */
.main-nav__link:hover {
border-bottom: 2px solid rgb(42, 136, 212);
}
<link href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" rel="stylesheet" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous"/>
<footer id="main-footer">
<nav id="main-nav">
<div class="main-nav__link-container">
<i class="fas fa-heart main-nav__link__icon"></i>
<a class="main-nav__link" href="wedding-party.html">Wedding Party</a>
</div>
<div class="main-nav__link-container">
<i class="fas fa-heart main-nav__link__icon"></i>
<a class="main-nav__link" href="venue-information.html">Venue Information</a>
</div>
<div class="main-nav__link-container">
<i class="fas fa-heart main-nav__link__icon"></i>
<a class="main-nav__link" href="accommodations.html">Accommodations</a>
</div>
<div class="main-nav__link-container">
<i class="fas fa-heart main-nav__link__icon"></i>
<a class="main-nav__link" href="event-information.html">Event Information</a>
</div>
<div class="main-nav__link-container">
<i class="fas fa-heart main-nav__link__icon"></i>
<a class="main-nav__link" href="registry.html">Registry</a>
</div>
</nav>
</footer>
From looking at the code, the issue is that you are trying to display and hide the icons using the link class (which comes after the fa icon), whereas if you targeted the container which holds both the heart and the link, the show/hide would be successful.
If you set the visibility to hidden in your __link__icon class and then display it on hover like so:
.main-nav__link-container:hover .main-nav__link__icon {
visibility:visible;
}
it should display.
Fiddle
You should use display:none and display:block CSS rules instead display:hidden.
Some like this:
.main-nav__link {
display:none;
}
.main-nav__link: hover {
display:block;
}