My li element has a img as background and the text written to the side. I want to display: none just the text and make it appear only on hovering. However if i apply display: none to the span element having text it takes out the whole li element.please check the images attached.
Li Element with list style image and description
HTML
CSS
You may try this. You will get appear Text on Hover Image using only
css.
body
{
font-family: sans-serif;
}
.image-hover-text-container
{
position: relative;
display: inline-block;
width: auto;
height: auto;
transition: all 0.2s linear;
}
.image-hover-image
{
display: block;
}
/* Make the image round */
.image-hover-image img
{
border-radius: 0%;
width: 300px;
}
.image-hover-text
{
position: absolute;
top: 0;
width: 100%;
height: 100%;
margin: 0 auto;
opacity: 0;
cursor: default;
transition: opacity 0.2s linear;
}
.image-hover-text:hover
{
opacity: 1;
}
.image-hover-text-bubble
{
position: relative;
box-sizing: border-box;
top: 0; left: 0; right: 100%;
height: 100%;
text-align: center;
background: rgba(218, 211, 211, 0.9);
border-radius: 0%;
margin: 0 auto;
padding: 30% 0px;
overflow: hidden;
font-size: 17px;
text-align: center;
word-wrap: break-word;
}
.image-hover-text .image-hover-text-title
{
font-size: 25px;
display: block;
}
<div class="image-hover-text-container">
<li class="image-hover-image">
<img src="http://dummyimage.com/600x400/38acf0/a9e1f2.jpg">
</li>
<div class="image-hover-text">
<div class="image-hover-text-bubble">
<span class="image-hover-text-title">Sample</span>
This Text display on Hover the Image.
</div>
</div>
</div>
Take a look at css selectors
You're using this selector on the post so i think you're not using the same selector on your code to perform display: none;
#fixed ul li a span{
display: none;
}
This will apply the display: none; in a descendant way (Any element matching span that is a descendant of an element matching a, that is a descendant of an element matching li etc.
#fixed > ul > li > a > span{
display: none;
}
This is a more "strict" way to do almost the same (Any element matching span that is a direct child of an element matching a, etc.)
Both should work (see the example below). So if not, you may have an error on your code that applies inheritance of display property or something similar, or your full code has differences between both selectors (maybe you need to select direct childs and you're selecting descendants).
Try first to apply direct child selector simply adding > between descendants, if not work inspect and try to find where inheritance is applied.
Another possible reason is that you may be using js or jquery to apply display none and it's not catching the selector properly so, try to inspect and fins where is the display property applied. (Maybe you coded a $('#fixed').hide();?
ul#first > li > a > span{display: none;}
ul#second li a span{display: none;}
<ul id="first">
<code>ul#first > li > a > span{display: none;}</code>
<li>icon- <span>a</span></li>
<li>icon- <span>b</span></li>
</ul>
<ul id="second">
<code>ul#second li a span{display: none;}</code>
<li>icon- <span>a</span></li>
<li>icon- <span>b</span></li>
</ul>
<ul id="third">
<code>No css applied</code>
<li>icon- <span>a</span></li>
<li>icon- <span>b</span></li>
</ul>
Related
I'm using Wordpress. I am setting some css changes in the additional css field. Since I don't know much about css, I paste the css code directly into the field. How can I color the lists and increase the height between them such as on this website?
Reference Site
Screenshot
li::before {
top: .6rem;
background-color: #272284;
}
I added this code to the additional css field, but there was no change. This is the theme I use. On this page you can see ordered and unordered lists.
Theme
Try this:
HTML:
<ul>
<li>One</li>
<li>Two</li>
</ul>
CSS:
ul {
background-color: #ff0000
}
li {
margin-top: 6rem;
}
(ol instead of ul for ordered lists)
You have not included the content property. Also, this creates the colored dots, so you need to turn off the list style and make each list relative so pseudo elements can position based on them:
li {
list-style: none;
position: relative;
}
li:before {
background-color: red;
content: '';
position: absolute;
width: 0.5rem;
height: 0.5rem;
border-radius: 100%;
left: -1rem;
top: 1rem;
}
I am trying to build a custom dropdown component for React. Unfortunately, my child list's width, which I have set to 100%, is showing up as wider than its parent element.
The DOM:
<div className="dd-wrapper" id={this.state.wrapperID}>
<div className="dd-header" id={this.state.headerID} onClick={() => this.toggleList()}>
<div className="dd-header-title"></div>
</div>
<ul className="dd-list hidden" id={this.state.listID}>
<li className="dd-list-item">Test</li>
<li className="dd-list-item">Test2</li>
<li className="dd-list-item">Test3</li>
</ul>
</div>
the toggleList function removes the hidden class from the list, and adds a border property class dd-border to the wrapper, which is also not behaving properly (the border is wrapping only the header).
It is being called in the parent element like this (I am using Bootstrap grid):
<div className="col-md-3">
<label> Dropdown
<Dropdown id="test-dd"/>
</label>
</div>
Here's the relevant css:
.dd-wrapper {
width: 100%;
margin-top: 8px;
}
.dd-header {
height: 40px;
background-color: #E2E8F2;
background-image: url("assets/images/down-chevron.png");
background-repeat: no-repeat;
background-position: 95% 50%;
}
.dd-list {
list-style-type: none;
background-color: white;
position: absolute;
}
.dd-list li {
height: 40px;
}
.dd-border {
border: 1px solid #3d70b2;
}
label {
display: inline-block;
width: 100%;
font-size: 14px;
}
.hidden {
display: none;
}
The result looks like this:
How can I get the width to match its parent without doing it manually (to ensure it will work for any size of dropdown? And, secondarily, does anyone know a good trick for getting the border to cover the child as well?
A quick note: This is a CSS question so your React logic is just acting as a hurdle for anyone willing to answer. I've extracted the important parts based on your description into a working snippet below without React. I would recommend pulling out anything not crucial to the context of your questions to encourage more prompt answers.
How can I get the width to match its parent without doing it manually (to ensure it will work for any size of dropdown?
I think the main thing you are looking for is position: relative on the parent. Because absolutely positioned elements size and position themselves against the first "positioned" ancestor. As a result, you can then combine this with top, left, right, bottom, width and/or height values (and probably box-sizing: border-box;)
...does anyone know a good trick for getting the border to cover the child as well?
You can fake it by putting the dropdown right up against the bottom and toggling a class on a common parent to hide/show certain borders.
Here's the snippet to demonstrate:
// The toggle logic in vanilla JS just to make the example work
// This, instead of toggling "hidden" on the list, toggles a "dd-closed" class on the wrapper
const wrapperEl = document.querySelector('.js-wrapper')
const headerEl = document.querySelector('.js-header')
if (wrapperEl && headerEl) {
const ancestorLabel = headerEl.closest('label')
const targetEl = ancestorLabel ? ancestorLabel : headerEl
targetEl.addEventListener('click',
() => wrapperEl.classList.toggle('dd-closed')
)
}
.dd-wrapper {
position: relative;
width: 100%;
margin-top: 8px;
}
.dd-header {
position: relative;
height: 40px;
background-color: #E2E8F2;
background-repeat: no-repeat;
background-position: 95% 50%;
border: 1px solid #3d70b2;
border-bottom-width: 0;
padding-right: 3em;
}
.dd-header::before {
position: absolute;
content: '\25B4';
right: 0;
text-align: center;
line-height: 40px;
width: 1em;
top: 0;
bottom: 0;
font-size: 2em;
}
.dd-list {
list-style-type: none;
background-color: white;
position: absolute;
border: 1px solid #3d70b2;
margin-top: 0;
left: 0; right: 0;
padding: 0;
}
.dd-list li {
vertical-align: middle;
padding: 1em;
}
.dd-list li:hover {
background-color: #eee;
}
label {
display: inline-block;
width: 100%;
font-size: 14px;
}
.dd-closed > .dd-header::before {
content: '\25BE';
float: right;
}
.dd-closed > .dd-header {
border-bottom-width: 1px;
}
.dd-closed > .dd-list {
display: none;
}
<!-- Basically what React would render as your output HTML...plus any necessary changes -->
<label> Dropdown
<div class="dd-wrapper dd-closed js-wrapper">
<div class="dd-header js-header">
<div class="dd-header-title"></div>
</div>
<ul class="dd-list">
<li class="dd-list-item">Test</li>
<li class="dd-list-item">Test2</li>
<li class="dd-list-item">Test3</li>
</ul>
</div>
</label>
<p>(Some other content for the dropdown to cover)</p>
<button>(I do nothing)</button>
I'm trying to add a dropdown menu to my nav as detailed in the docs here.
By default, .dropdown-content is set to top: 0;. And here is the default behavior:
If I change the top to 50px in materialize.css it actually moves it up 50 pixels and sets the element style to top: -50px.
Here is the code:
.dropdown-content {
top: 50px;
}
But when it renders, the element looks like this:
<ul id="dropdown1" class="dropdown-content" tabindex="0" style="display: block; width: 139.297px; left: 900.891px; top: -50px; height: 216px; transform-origin: 0px 0px 0px; opacity: 1; transform: scaleX(1) scaleY(1);">
(The key being `top: -50px;)
I tested with multiple values, here is 65:
.dropdown-content {
top: 65px;
}
<ul id="dropdown1" class="dropdown-content" tabindex="0" style="display: block; width: 139.297px; left: 900.891px; top: -65px; height: 216px; transform-origin: 0px 0px 0px; opacity: 1; transform: scaleX(1) scaleY(1);">
(now it is top: -65px)
Here's a screenshot if you care to take a look
Why is it inverting this value? How can I make the dropdown so it doesn't occlude the main menu?
I checked it and i see the best way to do that becuase the styles comes from JS which is have special calc i have checked and if you want to avoid any fixed height maybe you will have padding or anything in the header so the best to give the top:100% and to use !important to be stronger than the JS
give the class .dropdown-content top: 100% !important;
.dropdown-content {
top: 100% !important;
}
Looks like this option has been added in Materialize v1.0.0:
https://materializecss.com/dropdown.html
via the option coverTrigger on instantiation. It defaults to true (must set to false to achieve desired behavior).
Not a solution, but as a workaround I added a "spacer" element to the top of the dropdown:
<li class="spacer"></li>
.dropdown-content {
background: none; //overwrites default materialzie value of white
}
.dropdown-content li > a, .dropdown-content li > span {
background-color: white; //needed now that the whole menu has no background
}
.dropdown-content li:hover, .dropdown-content li.active {
background: none; //no white on hover
}
.dropdown-content li.spacer {
min-height: 65px; //height of the nav element
cursor: default; //so it doesn't look like a menu option
opacity: 0; //the magic
}
And here's the result:
<mat-menu class="abc" #menu="matMenu" [overlapTrigger]="false">
<div mat-menu-item >
11111
</div>
<div mat-menu-item >
22222222
</div>
</mat-menu>
Hope this works
I'm trying to get a ribbon-like banner effect for a header:
My markup is this:
<header>
<div id="logo">
<img src="">
</div>
</header>
I was thinking I could use pseudo :before and :after elements on the <img>, creating extra white space above and below the image to fake the extended `div:
#logo-wrap img:after {
content: '';
display: inline-block;
position: absolute;
left: 10px;
top: 10px;
width: 100px;
height: 100px;
background-color: #000;
}
And then another :before and :afterpseudo elements for the "shadow-fold".
My problem is: if I end up doing it like this, I'll have to insert another div between #logoand <img> in order to add another pair of :before and :after pseudo elements for the bottom "shadow-fold" and I think I'm having problems using the pseudo elements on the <img> element (nothing is appearing).
Can you shed some light and guide me on the right direction, pls? Perhaps, there is a simple way to just "shrink" the <header>?
EDIT
So, :before and :after can't be used with <img>. Thank you for the info :)
What I would like to know is if there is another way to achieve what I desire instead of wrap-wrap-wrap? :P
i.e: is there a way to make the #logo be bigger than <header> despite being its child and its height being the same (since the <header> has always the same height as the <img>)?
Thanks
I think you're on the right track. I would use borders, but I would make your pseudo-elements be behind the logo like so:
body,html {margin: 0; padding: 0;}
header {
background: #eee;
text-align: center;
margin: 1em 0;
}
#logo {
display: inline-block;
vertical-align: top;
position: relative;
margin: -0.5em 0;
}
#logo:before, #logo:after {
content: '';
position: absolute;
width: 100%;
left: -0.25em;
border: 0 solid transparent;
border-width: 0.5em 0.25em;
color: #aaa; /* set so we only have to have the border color in one place.
if not specified, border color is the same as the text
color. */
}
#logo:before {
border-top: none;
border-bottom-color: initial;
top: 0;
}
#logo:after {
border-bottom: none;
border-top-color: initial;
bottom: 0;
}
#logo img {
position: relative;
display:block;
z-index: 1;
}
<header>
<div id="logo">
<img src="//placehold.it/300x100?text=LOGO"/>
</div>
</header>
The concept is that the pseudo-elements are 100% width of the logo with a little bit extra (determined by the border attributes). Then you use both left and right borders simultaneously. There's a few other tricks in that code that help simplify it, but the general idea is to let your pseudo-elements peek out from behind the logo itself.
I have a problem trying to work out a small test menu with the (for me) "new" css3. The menu should be in the footer which always is on the bottom of the View port. However, I would like to mess around with the transition effects css3 offers therefore I want to grow a point of the menu when you :hover it.
The menu points are set to float:left in a relative menu div. The transition does as intended except the height transition enlarges the element downwards and (obviously as it is the footer) out of the page.
Instead I would like the menu points to grow upward. To solve this i could change the float:left to position:absolute and add bottom:0, but I would have to horizontal position every menu point (hyperlink) manually which I would like to avoid. Since the Menu size (number of menu points) should be variable and I also don't want to use and JavaScript, I am clueless.
Here is the css and the html:
<div id="footer">
<div class="menu">
menp1
menp2
menp3
menp4
menp5
menp6
</div>
</div>
and the css:
#footer {
position: absolute;
background-color: #497044;
bottom: 0px;
width: 100%;
height: 45px;
padding: 5px; }
div.menu {
position: relative;
height: 45px;
width: 480px;
left: 50%;
margin-left: -240px; }
div.menu a {
float:left;
width: 80px;
height: 50px;
border: 3px dashed;
margin-left: 5px;
text-align: center;
-moz-transition: height 2s; }
div.menu a:hover {
background-color: white;
height: 100px; }
thanks for the advice!
http://jsfiddle.net/nqCgu/2/
You mean something like this?
You can use a negative margin-top value and margin-top transition to achieve this. Add:
div.menu { ...
transition: margin-top .2s;
-moz-transition: margin-top .2s;}
div.menu a:hover {
margin-top:-50px;
background-color:white;
height: 100px; }