I do not know if this is possible, but I'm trying to indent the <li> in red to wrap underneath itself with CSS. I've used text-indent, padding, margin, and cannot get it to work. The <li> in red seems to be set at the same x/y coordinate as the green text. It only lets me push it away from the time (in green).
I can use a table, but I'm trying to accomplish this with CSS.
The image above is where I am at. The image below is what I am after.
HTML
<div class="agendaList">
<ul>
<li>Day, Month Date</li>
<ul>
<li>0:00 am</li>
<li>This is where the event description will appear. I would like for it to wrap under itself and not under the time. How do I start the wrap at the first word in the first sentence (This) of this <li>.</li>
</ul>
</ul>
<ul>
<li>Day, Month Date</li>
<ul>
<li>0:00 am</li>
<li>This is where the event description will appear. I would like for it to wrap under itself and not under the time. How do I start the wrap at the first word in the first sentence (This) of this <li>.</li>
</ul>
</ul>
</div>
CSS
.agendaList ul ul {
list-style: disc;
/* list-style-image: url(bullet.gif); */
margin-left: 0;
padding-left: 0;
}
.agendaList ul ul li {
display: inline;
list-style: none;
color: green;
}
.agendaList ul ul li:last-child {
display: inline;
color: red;
list-style-position: inside;
padding: 10px 0 10px 20px;
text-indent: -1em;
}
Here are two options:
Absolutely position the first li element and then use a margin to add space to the second list item.
Example Here
.agendaList ul ul li:first-child {
position: absolute;
}
.agendaList ul ul li:last-child {
display: inline-block;
color: red;
list-style-position: inside;
margin-left: 65px;
}
Alternatively, a better option would be to set the display of both li elements to table-cell. Add white-space:nowrap to the first li in order to prevent the text from wrapping.
Example Here
.agendaList ul ul li {
display:table-cell;
list-style:none;
color:green;
}
.agendaList ul ul li:first-child {
white-space:nowrap;
}
.agendaList ul ul li:last-child {
color: red;
list-style-position: inside;
padding-left:20px;
}
Related
This is my following CSS piece of code
ol{
padding-left:0;
list-style: inside decimal;
}
ol li :first-child{
display: inline;
}
<ol>
<li>
<p>Item 1</p>
</li>
<li>
Item 2
</li>
</ol>
Whenever HTML is rendered into a browser there is a white-space being added, Any specific reason for that?
There are a few ways of getting around this problem:
Use Flexbox to create the horizontal list of items instead of trying an inline-block solution. This handles everything for you, and is definitely the preferred solution:
ul {
list-style-type: none;
margin: 0;
padding: 0;
display: flex;
}
If you need to rely on inline-block, you could set the font-size of the list to 0. This only works if your blocks are not sized with ems (based on the font-size, so the block size would also end up being 0). rems would be a good choice here:
ul {
font-size: 0;
...
}
li {
display: inline-block;
width: 2rem;
height: 2rem;
...
}
Or you could set negative margin on the list items:
li {
display: inline-block;
width: 2rem;
height: 2rem;
margin-right: -0.25rem;
}
You can also solve this problem by putting your list items all on the same line in the source, which causes the whitespace nodes to not be created in the first place:
<li></li><li></li><li></li><li></li><li></li>
Credits :https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Whitespace
display:inline is not apply to p tag
ol{
padding-left: 0;
list-style: inside decimal;
}
ol li:first-child{
display: inline;
background: red;
}
ol li:first-child > p {
background: blue;
}
<ol>
<li>
<p>Item 1</p>
</li>
<li>
Item 2
</li>
</ol>
use display:inline to p tag also..
ol{
padding-left:0;
list-style: inside decimal;
}
ol li :first-child{
display: inline;
background: red;
}
ol li:first-child > p{
display: inline;
background: blue;
}
<ol>
<li>
<p>Item 1</p>
</li>
<li>
Item 2
</li>
</ol>
also you can add below code for removing default margin & padding for all html tag ...
*,*::after, *::before{
box-sizing: border-box;
margin: 0;
padding: 0;
}
I have a horizontal list in my markup with the following CSS:
ul li {
display: inline;
list-style: circle;
list-style-type: circle;
}
When I remove the display: inline; it works fine. But I can't get it to work on the horizontal one.
The list decorators will only be displayed if you don't override the display type for the list item. Rather than setting display: inline, apply a float: left and give some margin to prevent the circles from colliding into the previous element.
ul li {
float: left;
margin-left: 30px;
list-style: circle;
list-style-type: circle;
}
Here is an example.
ul li {
float: left;
margin-left: 30px;
list-style: circle;
list-style-type: circle;
}
/* this bit is optional, it only removes the left padding from the first item */
ul li:nth-of-type(1) {
margin-left: 0;
}
<ul>
<li> item 1 </li>
<li> item 2 </li>
<li> item 3 </li>
<li> item 4 </li>
</ul>
well, if you do that it won't shw because you're basically declaring "stop displaying the element in its default display method list-item and use inline instead" . To learn more about display methods, please take a look do DISPLAY PROPERTY.
Now, if you want to have bullets AND still display it inline, there are many ways to do it. You can use a :before pseudo-selector, you can use a background, etc.
For example:
ul li {
display: inline;
}
ul li:before {
content: "• ";
}
or
ul li{
display: inline-block;
}
ul li{
padding-left:30px; background:url(images/bullet.png) no-repeat 0 50% ;
}
but as long as you "kill" the list-item display method, you'll need to find some ways to override the DOM display of list types
Instead of inline, use:
li {
float:left
}
or
li {
display:inline-block
}
I'm trying to center a horizontal list of image links, though it seems that the left of the images are being centered. As you can see, the center of the list of images (which are all the same size) is slightly to the right of the text.
HTML:
<div id='nav'>
<ul>
<li>
<a href=''><img src='images/login.png' /></a>
</li>
<li>
<a href=''><img src='images/add.png' /></a>
</li>
<li>
<a href=''><img src='images/forum.png' /></a>
</li>
</ul>
</div>
Css:
#nav {
text-align: center;
}
#nav ul {
list-style: none;
margin: 20px auto;
}
#nav li {
display: inline-block;
margin: 0px 30px;
}
What can I do to completely center it?
Working Demo : http://jsfiddle.net/3d6TS/
The <ul> tag by default adds padding. You need to set padding:0 manually to <ul> tag.
#nav ul {
list-style: none;
margin: 20px auto;
padding:0;
}
#nav { text-align: center; }
#nav ul { list-style: none; }
#nav ul li { display: inline; }
the solution is the display:inline on the li
A good solution would be to maintain the margin-left and make sure the first child has a left margin of 0. This causes both the first and last children to have no margins on the edges it meets with the parent. This is good as :first-child doesn't catastrophically break styles in >=ie7 where as :last-child is unsupported in <=ie8 making the reverse of this infeasible for the time being.
#nav ul li {
display: inline-block;
margin-left:30px;
}
#nav ul li:first-child {
margin-left:0;
}
I have the following menu:
CSS:
ul.menu {
padding: 0;
margin: 0;
font-size: 16px;
}
ul.menu > li {
display: block;
width: 100%;
margin: 0;
}
ul.menu > li:hover {
color: red;
}
ul.menu > li a {
display: block;
background:transparent url("http://placehold.it/25x25") right center no-repeat;
background-size: 15px 15px;
}
ul.menu > li > a:hover {
background-color: #F7F7F7;
}
HTML:
<div style="width: 200px; background-color: lightgrey;">
<ul class="menu">
<li>
Line 1
</li>
<li>
Line 2
</li>
<li>
Line 3
</li>
<li>
Line 4
</li>
</ul>
</div>
JSFiddle: http://jsfiddle.net/8TzMc/
So far so good, but I want there to be padding on the left and right sides of the li's (about 10px) and I would also like the height of the li's to be a little greater (so that there's some space between the lines of text). I tried adding this line to the ul.menu > li CSS, but it messes up the menu in two ways:
There is now a non-clickable gap between the tops and bottoms of the menu items
The background image is messed up
JSFiddle: http://jsfiddle.net/HXrgq/
How can this be fixed?
Add the padding to the a element instead of the li element.
ul.menu > li a { padding:10px;}
for example
Updated Fiddle link
Add padding to ul.menu > li a instead, it gets rid of the gaps.
http://jsfiddle.net/HXrgq/1/
On the li element, do:
text-indent: 10px;
line-height: 1.5em;
seems this is what you searched: text indented (I suppose this is only one line?) and line-height.
In my website, I am trying to get the rollover effects working.
Currently, on no mouse hover, the ul li item is displayed as text but on mouse hover, it has a rollover effect to show the image.
Instead of having text in the normal mouse non-hover state, I want to have images.
That means, mouse hover and non-mouse hover are both different images, and there's no text
I wanted to ask how do I get such a rollover effect working, in contrast to what I have currently. (non-mouse hover is text which I want to to change to images as well)
Here is the jsfiddle of how I currently have rollovers: http://jsfiddle.net/PF35v/7/
You have all of the images hidden by default so when you put an image inside the a tag, it is also hidden.
ul#nav li a img { display: block; }
This will make the images in links always visible but the others hidden by default. I think that's what you're asking for.
Here's two different approaches, I'm sure there are others:
HTML-Centric
<ul id="nav">
<li>
<a href="#">
<span>My Text</span>
<img src="http://goo.gl/tYsDU"/>
<img class="hover" src="http://goo.gl/UohAz"/>
</a>
</li>
...
</ul>
#nav,
#nav li {
list-style-type: none;
margin: 0;
padding: 0;
}
#nav li a img {
display: inline;
}
#nav li a img.hover,
#nav li a span {
display: none;
}
#nav li a:hover img {
display: none;
}
#nav li a:hover img.hover {
display: inline;
}
http://jsfiddle.net/RdRcj/1
CSS-Centric
<ul id="nav">
<li>
</li>
...
</ul>
#nav,
#nav li {
list-style-type: none;
margin: 0;
padding: 0;
}
#nav li {
width: 128px;
height: 128px;
background-image: url(http://goo.gl/tYsDU);
}
#nav li a {
display: block;
width: 128px;
height: 128px;
padding: 0;
}
#nav li a:hover {
background-image: url(http://goo.gl/UohAz);
}
http://jsfiddle.net/RdRcj/
The first is probably the "best" from a flexibility standpoint; you don't have to hard-bake the dimensions in like you do the second. However, if they're unchanging, perhaps the second is preferable for your approach, it just takes targeting each li and a specifically, which can prove a little brittle.