I am trying to align the text vertically, but the star is not aligning, How do I align them vertically center?
.operators {
margin: 0;
padding: 0;
list-style: none;
}
.operators > li {
display: inline-block;
}
.operators > li span{
font-size: 18px;
display: flex;
padding: 4px 8px;
justify-content: center;
align-items: center;
color: #ffffff;
background-color: #cdcdcd;
border: 1px solid #333333;
}
<ul class="operators">
<li>
<span>+</span>
</li>
<li>
<span>-</span>
</li>
<li>
<span>*</span>
</li>
<li>
<span>=</span>
</li>
<li>
<span>2</span>
</li>
</ul>
You could try another asterisk that is centered. Unicode Asterisk Operator with HTML entity ∗
However note that some browsers might not show this correctly
.operators {
margin: 0;
padding: 0;
list-style: none;
}
.operators > li {
display: inline-block;
}
.operators > li span{
font-size: 18px;
display: flex;
padding: 4px 8px;
justify-content: center;
align-items: center;
color: #ffffff;
background-color: #cdcdcd;
border: 1px solid #333333;
}
<ul class="operators">
<li>
<span>+</span>
</li>
<li>
<span>-</span>
</li>
<li>
<span>∗</span>
</li>
<li>
<span>=</span>
</li>
<li>
<span>2</span>
</li>
</ul>
Neither the hyphen nor the asterisk are correctly aligned. This is because they are defined as to be used for different purposes, not for minus and multiply though that is how many programming languages use them as they are present on most keyboards.
The correct (i.e. consistent with the Unicode definitions) signs for minus and multiplication in HTML are
Minus: HTML − which gives you − see Wikipedia
Multiply: HTML × which gives you × see Wikipedia
For a calculator type application then these signs are probably the ones to use.
However, if you are trying to use them in some way to discuss programming then you probably need to stick to using the hyphen and asterisk. The fact that they aren't aligned with the other symbols would at least then be consistent with what the user sees when writing code in an editor.
Related
I'm trying to keep my logo "Reservia" and my LI "S'inscrire" on the same line and wrap my 2 other LI "Hebergement" and "Activités" on a line under this first one but it doesn't work.
Here is my Header
<header>
<div id="containerHeader">
<img src="images/logo/Reservia.svg" class="test" alt="Logo reservia">
<nav class="Navmenu">
<ul class="liMenu">
<li class="liMenu--list liMenu--list_nocolor">
Hebergement
</li>
<li class="liMenu--list liMenu--list_nocolor">
Activités
</li>
<li class="liMenu--list liMenu--list_blue">
S'inscrire
</li>
</ul>
</nav>
</div>
</header>
And here is my CSS
#containerHeader{
flex-wrap: wrap;
}
.navMenu,
.liMenu {
justify-content: center;
padding-right: 80px;
}
.liMenu--list {
list-style: none;
}
.test{
order: -1;
}
.link--navbar {
border-bottom: 4px solid lightgrey;
border-top: none;
padding-bottom: 15px;
}
.link--navbar:hover {
border-top: none;
}
And I put my 2 screenshots ( what it looks like and what I want ) :)
Thanks a lot
img, li {
width: 50%
}
Try adding 50% width to the img and li elements. This will ensure that a single element takes up half the width, which will result in two elements per row.
You may need to use media queries if you want a different look for different devices.
I have this list at the bottom of the page, and when I hover over each number, a sentence shows up, however, I want the paragraph with the sentence to show centered in the middle of the page, so pretty much all in the same position, how can i do that?
Images attached to help 1-2
.dotMenu {
margin-left: auto;
text-align: center;
margin-right: auto;
margin-bottom: -50px;
position: relative;
margin-left: 5%;
margin-right: 5%;
}
.dotMenu ul li {
height: 30px;
width: 30px;
background-color: #222954;
border-radius: 50%;
text-align: center;
font-family: Lovelo Pro;
line-height: 30px;
display: inline-block;
margin-left: 3px;
margin-right: 3px;
margin-top: 5px;
margin-bottom: 5px;
}
.dotMenu ul li a {
text-decoration: none;
color: #FDBA3B;
}
.dotMenu ul li:hover {
background-color: white;
}
.dotMenu ul li p {
display: none;
}
.dotMenu ul li:hover p {
display: inline-block;
position: absolute;
}
<div class="dotMenu">
<ul>
<li>1
<p>Cascading Web Design with Feature Queries</p>
</li>
<li>2
<p>Lint the Web Forward With Sonarwhal</p>
</li>
<li>3
<p>Web Content Accessibility Guidelines—for People Who Haven't Read Them</p>
</li>
<li>4
<p>Jobs-to-Be-Done in Your UX Toolbox</p>
</li>
<li>5
<p>Levelling Up for Junior Developers</p>
</li>
<li>6
<p>Designing a Remote Project</p>
</li>
<li>7
<p>Automating Your Accessibility Tests</p>
</li>
<li>8
<p>Stop Leaving Animation to the Last Minute</p>
</li>
<li>9
<p>Styling Components - Typed CSS With Stylable</p>
</li>
<li>10
<p>Christmas Gifts for Your Future Self: Testing the Web Platform</p>
</li>
<li>11
<p>Teach the CLI to Talk Back</p>
</li>
<li>12
<p>Design Systems and CSS Grid</p>
</li>
<li>13
<p>Getting Hardboiled with CSS Custom Properties</p>
</li>
<li>14
<p>Why Design Systems Fail</p>
</li>
<li>15
<p>Accessibility Through Semantic HTML</p>
</li>
<li>16
<p>Care and Feeding of Burnout</p>
</li>
<li>17
<p>Feeding the Audio Graph</p>
</li>
<li>18
<p>Designing for Mobile Performance</p>
</li>
<li>19
<p>Want to Break Out of Comparison Syndrome? Do a Media Detox</p>
</li>
<li>20
<p>Is Your Website Accidentally Sexist?</p>
</li>
<li>21
<p>Knowing the Future - Tips for a Happy Launch Day</p>
</li>
<li>22
<p>Design Systems and Hybrids</p>
</li>
<li>23
<p>Refactoring Your Way to a Design System</p>
</li>
<li>24
<p>All That Glisters</p>
</li>
</ul>
</div>
Give your p tags a position of absolute, aligned to the left, with a 100% width and a text-align of center.
Note: you may have to give a parent div a position:relative if you want the p tags to be centered relative to the container, not the page.
li p{
display: none;
position:absolute;
left: 0;
width: 100%;
text-align: center;
}
.flex{
display:flex;
list-style:none;
padding: 0;
}
li{
background: dodgerblue;
margin-right: 5px;
border-radius: 50%;
}
li p{
display: none;
position:absolute;
left: 0;
width: 100%;
text-align: center;
}
li a{
text-decoration:none;
color: #fff;
display:block;
width: 30px;
height: 30px;
display:flex;
align-items: center;
justify-content:center;
}
li a:hover ~ p{
display: block;
}
<ul class="flex">
<li>1<p>Cascading Web Design with Feature Queries</p></li>
<li>2<p>Lint the Web Forward With Sonarwhal</p></li>
<li>3<p>Web Content Accessibility Guidelines—for People Who Haven't Read Them</p></li>
<li>4<p>Jobs-to-Be-Done in Your UX Toolbox</p></li>
<li>5<p>Levelling Up for Junior Developers</p></li>
<li>6<p>Designing a Remote Project</p></li>
<li>7<p>Automating Your Accessibility Tests</p></li>
<li>8<p>Stop Leaving Animation to the Last Minute</p></li>
<li>9<p>Styling Components - Typed CSS With Stylable</p></li>
<li>10<p>Christmas Gifts for Your Future Self: Testing the Web Platform</p></li>
<li>11<p>Teach the CLI to Talk Back</p></li>
<li>12<p>Design Systems and CSS Grid</p></li>
<li>13<p>Getting Hardboiled with CSS Custom Properties</p></li>
<li>14<p>Why Design Systems Fail</p></li>
<li>15<p>Accessibility Through Semantic HTML</p></li>
<li>16<p>Care and Feeding of Burnout</p></li>
<li>17<p>Feeding the Audio Graph</p></li>
<li>18<p>Designing for Mobile Performance</p></li>
<li>19<p>Want to Break Out of Comparison Syndrome? Do a Media Detox</p></li>
<li>20<p>Is Your Website Accidentally Sexist?</p></li>
<li>21<p>Knowing the Future - Tips for a Happy Launch Day</p></li>
<li>22<p>Design Systems and Hybrids</p></li>
<li>23<p>Refactoring Your Way to a Design System</p></li>
<li>24<p>All That Glisters</p></li>
</ul>
I have a navigation bar with hyperlinks to other pages. I decided to use different divisions for each hyperlink because I couldn't get them to spread out. When I execute this on my browser, two of the hyperlinks(both the right ones) are slightly below the other ones. I don't know if that is because of my mac or if it's an error in the code. Could someone please tell me how I can make sure all hyperlinks are evenly lied up in 2 lines?
.navbar {
padding: 15px;
font-size: 28pt;
background-color: #F64C72;
position: relative;
top: 20px;
text-align: center;
margin: auto;
font-size: 17pt;
}
.connectp1 {
text-align: left;
}
.connectp2 {
text-align: center;
}
.connectp3 {
text-align: right;
}
.connectp4 {
text-align: left;
}
.connectp5 {
text-align: center;
}
.connectp6 {
text-align: right;
}
<div class="navbar">
<div>
<div class="connectp1">
First Peoples
</div>
<div class="connectp2">
Natives And Newcomers
</div>
<div class="connectp3">
Provincial Centre
</div>
</div>
<div>
<div class="connectp4">
Industrializing City
</div>
<div class="connectp5">
Wars And Crises
</div>
<div class="connectp6">
The Modern Metropolis
</div>
</div>
</div>
You don't need extra layers to spread out. Inline elements like <a> are better for this kind of menus, so just keep it simple. The code bellow will split in two lines only if required.
.navbar {
padding: 15px;
background-color: #F64C72;
text-align: center;
font-size: 17px;
}
.menu {
display: inline-block;
margin: 10px auto;
white-space: nowrap;
}
nav a {
display: inline-block;
padding: 5px;
white-space: normal;
vertical-align: top;
}
<nav class="navbar">
<div class="menu">
First Peoples
Natives And Newcomers
Provincial Centre
</div>
<div class="menu">
Industrializing City
Wars And Crises
The Modern Metropolis
</div>
</nav>
However I recommend you considering some improvements in your design to help the menu look more tidy.
This looks like a perfect opportunity to use flexbox setting justify-content. We can just work with a div to hold all the nav and then a div for each row then the links directly.
flexbox handles the distribution of the a elements in our instance, while setting justify-content: space-between determines how the a elements are spaced.
.navbar {
padding: 15px;
font-size: 28pt;
background-color: #F64C72;
position: relative;
top: 20px;
text-align: center;
margin: auto;
font-size: 17pt;
}
.navbar > div {
display:flex;
justify-content: space-between;
}
<div class="navbar">
<div>
First Peoples
Natives And Newcomers
Provincial Centre
</div>
<div>
Industrializing City
Wars And Crises
The Modern Metropolis
</div>
</div>
With IE 10 you will need to prefix with -ms- and it won't work at all with older versions of IE if you need to support IE 9 and earlier. See: https://css-tricks.com/almanac/properties/j/justify-content/
You would be much better off using unordered lists (ul) with list items (<li>), and then displaying the lists as table rows/table cells as in the snippet below, and vertically aligning to top. Btw, your current css includes duplication, there is no need to created 2 different classes to text-align to the right (e.g)
Feel free to adjust the snippet ( I reduced the huge font size! - so that the adjustments could be seen in the snippet)
* {
margin: 0px;
padding: 0px;
}
nav {
margin: auto;
top: 20px;
padding: 20px;
font-size: 13pt;
background-color: #F64C72;
text-align: center;
}
nav ul {
margin: 0px;
list-style-type: none;
vertical-align: top;
display: table-row;
}
ul li {
display:table-cell;
}
ul li a {
text-decoration: none;
}
<nav>
<ul>
<li>First Peoples </li>
<li>Natives And Newcomers</li>
<li>
Provincial Centre
</li>
</ul>
<ul>
<li class="">Industrializing City
</li>
<li class="">
Wars And Crises
</li>
<li class="">
The Modern Metropolis
</li>
</ul>
</nav>
Use HTML5 semantic elements when possible. In your case, the nav element is the proper tool for the job. MDN shows:
nav {
border-bottom: 1px solid black;
}
.crumbs ol {
list-style-type: none;
padding-left: 0;
}
.crumb {
display: inline-block;
}
<nav class="crumbs">
<ol>
<li class="crumb">Acme</li>
<li class="crumb">Foo</li>
<li class="crumb">Bar</li>
</ol>
</nav>
<h1>Jump Bike 3000</h1>
<p>This BMX bike is a solid step into the pro world. It looks as legit as it rides and is built to polish your skills.</p>
<div> elements are block-level elements, so take up 100% of the width of a 'row' by default. While you can correct this by simply changing their display to inline-block, I would recommend replacing them with <span> tags instead (which are inline-block by default):
.navbar {
padding: 15px;
font-size: 28pt;
background-color: #F64C72;
position: relative;
top: 20px;
text-align: center;
margin: auto;
font-size: 17pt;
}
.connectp1 {
text-align: left;
}
.connectp2 {
text-align: center;
}
.connectp3 {
text-align: right;
}
.connectp4 {
text-align: left;
}
.connectp5 {
text-align: center;
}
.connectp6 {
text-align: right;
}
<div class="navbar">
<div>
<span class="connectp1">
First Peoples
</span>
<span class="connectp2">
Natives And Newcomers
</span>
<span class="connectp3">
Provincial Centre
</span>
</div>
<div>
<span class="connectp4">
Industrializing City
</span>
<span class="connectp5">
Wars And Crises
</span>
<span class="connectp6">
The Modern Metropolis
</span>
</div>
</div>
Note that you're also likely looking for float: left and float: right
rather than text-align: left and text-align: right, in order to separate out your elements. There's no float: center, though this isn't needed. You can also combine your selectors in this regard to save space, as can be seen in the following:
.navbar {
padding: 15px;
font-size: 28pt;
background-color: #F64C72;
position: relative;
top: 20px;
text-align: center;
margin: auto;
font-size: 17pt;
}
.connectp1, .connectp4 {
float: left;
}
.connectp3, .connectp6 {
float: right;
}
<div class="navbar">
<div>
<span class="connectp1">
First Peoples
</span>
<span class="connectp2">
Natives And Newcomers
</span>
<span class="connectp3">
Provincial Centre
</span>
</div>
<div>
<span class="connectp4">
Industrializing City
</span>
<span class="connectp5">
Wars And Crises
</span>
<span class="connectp6">
The Modern Metropolis
</span>
</div>
</div>
How do I get them to stay?
I have the following list - the moment I add to my list li display: inline-block; the custom list decorators I designated disappear.
Is there a CSS way of keeping my list decorators when the list is horizontal, or are list decorators only ever supposed to appear with vertical lists? Of course I could just have an image next to every list entry, but for simplicity's sake I'd rather deal with this in the CSS.
.first-page-menu-list {
list-style-image: url('../graphics/list-style-image.png');
list-style-position: inside;
text-transform: uppercase;
}
An alternate method consists of floating the li elements.
<ul>
<li>the item</li>
<li>the item</li>
<li>the item</li>
</ul>
ul {
overflow: auto; /* similar to clearing the floats... */
border: 1px solid gray;
}
ul li {
float: left;
border: 1px solid blue;
padding: 10px;
margin: 0 20px;
}
Demo fiddle: http://jsfiddle.net/audetwebdesign/kBNVz/
It seems that you're right but there's an easy fix for this, just use the background as long as you're not using it otherwise try this:
CSS:
.first-page-menu-list li {
background: url('../graphics/list-style-image.png') no-repeat 0px 4px;
display: inline;
text-transform: uppercase;
padding-left: 15px;
margin-left: 10px;
}
HTML:
<ul class="first-page-menu-list">
<li>asd</li>
<li>asdf </li>
<li> asdf</li>
</ul>
Play with the px values and you'll easy see what does which magic
Flexbox works well for this without the need to clear your floats.
ul.inline-list-style {
list-style: upper-roman;
display: flex;
}
ul.inline-list-style li {
flex: 1;
}
So, I have attempted to create a horizontal list for use on a new website I am designing. I have attempted a number of the suggestions found online already such as setting 'float' to left and such - yet none of these have worked when it comes to fixing the problem.
ul#menuItems {
background: none;
height: 50px;
width: 100px;
margin: 0;
padding: 0;
}
ul#menuItems li {
display: inline;
list-style: none;
margin-left: auto;
margin-right: auto;
top: 0px;
height: 50px;
}
ul#menuItems li a {
font-family: Arial, Helvetica, sans-serif;
text-decoration: none;
font-weight: bolder;
color: #000;
height: 50px;
width: auto;
display: block;
text-align: center;
line-height: 50px;
}
<ul id="menuItems">
<li>
Home
</li>
<li>
DJ Profiles
</li>
</ul>
Currently I am unsure of what is causing this issue, how would I go about and resolve it?
Updated Answer
I've noticed a lot of people are using this answer so I decided to update it a little bit. No longer including support for now-unsupported browsers.
ul > li {
display: inline-block;
/* You can also add some margins here to make it look prettier */
}
<ul>
<li> some item
</li>
<li> another item
</li>
</ul>
This fiddle shows how
http://jsfiddle.net/9th7X/
ul, li {
display:inline
}
Great references on lists and css here:
http://alistapart.com/article/taminglists/
I guess the simple solution i found is below
ul{
display:flex;
}
A much better way is to use inline-block, because you don't need to use clear:both at the end of your list anymore.
Try this:
<ul>
<li>
some item
</li>
<li>
another item
</li>
</ul>
CSS:
ul > li{
display:inline-block;
}
Have a look at it here : http://jsfiddle.net/shahverdy/4N6Ap/
You could also use inline blocks to avoid floating elements
<ul>
<li>
some item
</li>
<li>
another item
</li>
</ul>
and then style as:
li{
/* with fix for IE */
display:inline;
display:inline-block;
zoom:1;
/*
additional styles to make it look nice
*/
}
that way you wont need to float anything, eliminating the need for clearfixes
Here you can find a working example, with some more suggestions about dynamic resizing of the list.
I've used display:inline-block and a percentage padding so that the parent list can dynamically change size:
display:inline-block;
padding:10px 1%;
width: 30%
plus two more rules to remove padding for the first and last items.
ul#menuItems li:first-child{padding-left:0;}
ul#menuItems li:last-child{padding-right:0;}
strong tex
ul {
list-style: none;
display: flex;
justify-content: space-around;
}
<ul>
<li>bla</li>
<li>blabla</li>
<li>blablabla</li>
</ul>