I have written a piece of code:
<p>
Example:
</p>
<ol>
<li>Text 1</li>
<li>Text 2</li>
</ol>
This need to set my text vertical under each other
But it gives me the output that my text is written over each other so not vertical under each other but just on one line.
I need it like this:
<p>
Example:
</p>
<ol>
<li>Text 1</li>
<li>Text 2</li>
</ol>
And now it is like this:
This could have been a comment. But I thought I could guide you and explain more.
The question contains only the HTML Markup, where the issue doesn't occur. It is perfectly fine. The issue lies with the CSS, which is the presentational style. So, it is something to do with the CSS.
What I feel from your screenshot is, there might be a CSS with a rule:
* {line-height: 0;}
This might have been given as a mistake, or because of something, it is getting over-ridden. You need to reset these values by either:
Using a CSS Reset - Eric Meyer, Simple Reset, or YUI Reset.
If it is a Simple Reset, you can just give this rule:
* {margin: 0; padding: 0; line-height: 1.2em;}
The line-height is for your particular case.
And make sure, you put your custom CSS at the end, so that it is effective and over-rides all the other styles.
Hope you get it done.
try using:
li {
float: none;
dispaly: block;
clear: both;
}
Related
I have simple unordered list in Bootstrap 4:
<ul>
<li>line 1</li>
<li>line 2</li>
<li>line 3</li>
<li>line 4</li>
<li>line 5</li>
</ul>
with this custom CSS:
ul, ol {
padding-left: 1rem;
}
li {
margin-bottom: 1rem;
}
But they renders differently on Firefox and Safari
Firefox
Safari
I've noticed that Bootstrap uses ::marker pseudo element instead of ::before, can I change it so that is more compatible with Safari?
This may not be a Bootstrap problem. I found a few solutions that may work:
This could happen if the charset is not set right. Try to add #charset "UTF-8"; in the first line of your CSS code.
Developers often use reset CSS to reset default paddings and margins to reduce browser inconsistencies. You can find simple reset CSS here.
You could add custom bullet points with CSS by adding a list-style: none; to your ul element and then add a bullet with ::before on li element.
This may have something to do with a browser bug in Safari. I found one at https://getbootstrap.com/docs/3.4/browser-bugs/ that relates to rem units (WebKit bug #156684).
I'm trying to create a navigation list where all the list items stack on top of one another, as per display:block, but where their width is influenced by the width of the text within them, as per display:inline.
It seems like I can only choose one or the other - I've tried setting the li and li a to various combinations of block/inline/inline-block and it's not working. Either my list items are all the same width, or they're sitting next to each other instead of on top of one another.
Here's what I'm trying to achieve and can't:
http://i39.tinypic.com/280t5s0.png
Is this possible to do? I feel like it really should be but am completely stumped and searching hasn't turned up much.
Any help would be much appreciated!
Thanks and best wishes,
Emma
HTML
<ul>
<li>Item 1</li>
<li>Long Item 2</li>
<li>Longer Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
</ul>
CSS
li {
border: 1px solid black;
display: inline-block;
float: right;
clear: right;
}
See it live
So I have a menu, 4 menu points and I want to put them in a square 2x2. Is there a way to do that WITHOUT having a class for the first two and one for the other ones?
Thanks for any help :)
UPDATE:
I did mess around a little more and I'm using the flex box structure, I'm sorry for not posting this information:
ul {
-webkit-box-orient: horizontal;
}
ul li {
-webkit-box-flex: 1;
height: 44%;
margin: 3%;
}
Sure. For one, you can use floating and set the widths accordingly. See the example below, or http://jsfiddle.net/BUPX7/ for a live example.
HTML
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
CSS
ul {
width: 200px;
}
ul li {
width: 100px;
margin: 0;
padding: 0;
float: left;
}
There is a line break between div elements by default. You are apparently using some CSS to override that. You need to modify the CSS code accordingly, or select a different approach.
The simplest way, assuming ”menu points” are links, is to use
<div><a ...>link1</a> <a ...>link2</a></div>
<div><a ...>link3</a> <a ...>link4</a></div>
But if you are using some elaborated markup and wish to create the break in CSS alone, then you may need some elaborated selectors like :nth-child(3).
I have an ASP.NET application with contains a list of hyperlinks. After each hyperlink, there is a br tag that puts each hyperlink on their own line. I want to increase the spacing between each line. I don't want to add another br trag since that does not provide the control I am looking for. I have tried different CSS styling without any change. What CSS styling do I use to accomplish this?
For the hyperlinks you could use display:block; and margin-bottom:[some value] style/CSS properties, you wouldn't need to have your BR elements, and you would gain much more control.
You could add margin or padding to top of your BR tags eg.
br { margin:10px 0; }
If that isn't feasible, then make your hyperlinks block level and add margin or padding to top of them eg.
a { display:block; margin:10px 0; }
Using the latter method you don't require the BR tags anymore.
Remove the <br /> elements and instead give those anchor elements a display:block property.
Then use padding-top or padding-bottom or margin-top or margin-bottom to increase the space between.
i think what you are looking for is line-height:
http://www.w3.org/TR/WCAG20-TECHS/C21.html
even though this might be the better/'nicer' solution:
<ul id="mylinklist">
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
<li>Link 4</li>
<li>Link 5</li>
</ul>
and this style:
ul#mylinklist{
list-style-type: none;
margin: 0;
padding: 0;
}
ul#mylinklist li{
margin-bottom: 10px;
}
use margin-top or margin-bottom
a{
margin-bottom: 1em;
}
I thought this would be an easy thing, but I haven't found a good solution (maybe I'm also using the wrong search terms).
I would like to style an ordered list so the items appear so:
1
Item one
2
Item two
3
Item three
Is there any way to do this simply with CSS?
Many thanks in advance!
You can try along the line of:
<style>
ol {
list-style-position: inside;
padding-left: 0;
}
</style>
<ol>
<li> <div>foobar</div></li>
<li> <div>wah la</div></li>
</ol>
It works on FF and Chrome, but I don't have IE on my current machine to try.
You can use the content property with the :before pseudo-element and the \a newline escape:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>OL Test</title>
<style type="text/css">
li:before {
content: "\a";
white-space: pre;
}
</style>
</head>
<body>
<ol>
<li>Item one</li>
<li>Item two</li>
<li>Item three</li>
</ol>
</body>
</html>
That should work fine on browsers that support CSS 2.1.
AFAIK, CSS does not allow you to have a lot of control regarding the position of the list-item relative to the "bullet" (or number or whatever)... So it might be a better idea to generate the numbers directly in the HTML, on server-side, or on client-side via Javascript...
Nevertheless, the following works (at least in Firefox), but is rather ugly (with that br in the middle :-/ )
<html>
<head>
<style type="text/css">
li > p{
margin-left:-30px;
margin-top:-10px;
}
</style>
</head>
<body>
<ol>
<li><br/><p>item 1</p></li>
<li><br/><p>item 2</p></li>
</ol>
</body>
</html>
The idea is to force the content of the list-item to be on another line with a br, and then, on the content, apply some negative margins to move it where you want to... This is certainly not a nice solution ... in addition, I think that each browser may generate the "list-index" in its way, so there would be no nice way to have it work on all browsers ...
I know this question is really old, but I ended up finding it when searching for the same answer, and these answers provided didn't quite do what I needed it to do. I had also just learned this really cool technique using the "counter" in CSS.
ol {
/* Remove default numbers */
list-style: none;
counter-reset: item;
}
ol li {
/* Increment the counter for this element */
counter-increment: item;
/* Style the vertical spacing as needed */
display: block;
margin: 1em 0;
}
ol li:before {
/* Add the numbers as content in the before pseudo */
content: counter(item);
/* Continue styling as needed, changing, fonts, position, etc. */
display: block;
margin-bottom: 1em;
}
<ol>
<li>Item One</li>
<li>Item Two</li>
<li>Item Three</li>
</ol>
Does it absolutely have to be an ordered list?
If you are dynamicaly generating the content, then you could always output the numbers yourself, and then format the markup however you like - rather than trying to coerce the browser by doing something 'clever', simplify the situation by doing someting 'smart'