I am new to programming and have been stuck for days trying to get my buttons to align horizontally in the center of their div. I have tried display: inline and display: inline-block and all the different solutions i have found on this forum and none have worked for me. Here is the css for the buttons:
div.contact {
padding: 0px;
margin: 0px;
background: #d6d6c2 url(https://clcadvisors.files.wordpress.com/2015/10/img_0914-0.jpg) no-repeat center;
background-size: cover;
height: 300px;
overflow: hidden;
}
ul.soc {
list-style-type: none;
padding: 0px;
margin: 0px;
position: relative;
display: inline-block;
}
li.socbutton a {
background-color: gray;
border: 2px solid black;
border-radius: 10px;
color: white;
text-align: center;
text-decoration: none;
text-shadow: 2px 2px black;
font-size: 24px;
margin: 20px;
padding: 20px;
box-shadow: 10px 10px 5px black;
width: 250px;
}
HTML:
<div class="contact">
<h3>Contact</h3>
<div>
<ul class="soc">
<li class="socbutton">
<i class= "fa fa-linkedin-square fa-fw"></i>LINKEDIN
</li>
<li class="socbutton">
<i class= "fa fa-twitter fa-fw"></i>TWITTER
</li>
<li class="socbutton">
<i class= "fa fa-facebook-official fa-fw"></i>FACEBOOK
</li>
</ul>
</div>
</div>
and the link to the codepen that I am building it in http://codepen.io/SHENKU360/pen/VedRbP
Thanks in advance for any help!
Add this to your CSS:
ul.soc {
width: 100%;
text-align: center;
}
ul.soc li {
display: inline-block;
}
This will align all the stuff inside your "unsorted list"-element to center. This element will also need a 100% width.
All list-elements inside should be display: inline-block;.
You need to inline the lis, not the as:
li.socbutton {
display: inline-block;
}
And make the ul center them:
ul.soc {
display: block;
text-align: center;
}
Add the following code in your css
li{
overflow: hidden;
margin-left:auto;
margin-right:0px; }
this link is also helpfull https://css-tricks.com/centering-list-items-horizontally-slightly-trickier-than-you-might-think/
Related
I have an unordered linked list. I'm trying to shift one of the items in the navigation all the way to the right (Order) as if it had text-align: right;. I tried using float: right; and text-align: right;, but none of them seemed to work. If I set the margin-left to a really high number (such as 100px) it does shift to the right, but if I resize my window then I can't see it anymore or it's not on the right side of the page. Here is the HTML:
nav {
position: fixed;
}
.navigation-links-no-style a {
text-decoration: none;
position: relative;
margin: 15px;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
li {
float: left;
}
.navigation-links li {
padding-top: 1.3em;
}
.navbar {
overflow: hidden;
position: fixed;
top: 0;
width: 100%;
border-bottom: solid 1px black;
background: white;
padding-left: 5em;
}
.navbar a {
float: left;
display: block;
text-align: center;
padding: 14px 16px;
text-decoration: none;
margin-left: 20px;
color: black;
font-size: 14pt;
}
.order {
color: #FFFFFF !important;
background: #1419e2;
text-decoration: none;
padding: 8px;
border-radius: 5px;
margin-top: 15px;
}
<div class="navbar">
<a class="glacier-hills" href="glacier_hills.html">
<img src="Images/Glacier-Hills-Logo.svg" alt="" width="182" height="90">
</a>
<ul class="navigation-links">
<div class="navigation-links-no-style">
<li>
<a class="menu" href="menu.html">Menu</a>
</li>
<li>
<a class="location" href="location.html">Hours and Location</a>
</li>
</div>
<li>
<a class="order" href="order.html">Order</a>
</li>
</ul>
</div>
Any help would be greatly appreciated. Thanks!
Assuming you're looking to move your .order element, you'll want to apply the float: right rule to the parent (<li>) element. I've added a class to this, .order-container, to make this easier to achieve in the following example.
Note also that once you float to the right, it will be off the screen by default. You'll want to set a negative margin-right to circumvent this. I've gone with margin-right: -10em in the following, to match the offset from the image on the left.
Ultimately, you may wish to consider using a framework to achieve responsive design, ensuring that the offset is correct regardless of screen size.
nav {
position: fixed;
}
.navigation-links-no-style a {
text-decoration: none;
position: relative;
margin: 15px;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
li {
float: left;
}
.navigation-links li {
padding-top: 1.3em;
}
.navbar {
overflow: hidden;
position: fixed;
top: 0;
width: 100%;
border-bottom: solid 1px black;
background: white;
padding-left: 5em;
}
.navbar a {
float: left;
display: block;
text-align: center;
padding: 14px 16px;
text-decoration: none;
margin-left: 20px;
color: black;
font-size: 14pt;
}
.order {
color: #FFFFFF !important;
background: #1419e2;
text-decoration: none;
padding: 8px;
border-radius: 5px;
margin-top: 15px;
float: right;
}
.order-container {
float: right;
margin-right: 10em;
}
<div class="navbar">
<a class="glacier-hills" href="glacier_hills.html">
<img src="Images/Glacier-Hills-Logo.svg" alt="" width="182" height="90">
</a>
<ul class="navigation-links">
<div class="navigation-links-no-style">
<li>
<a class="menu" href="menu.html">Menu</a>
</li>
<li>
<a class="location" href="location.html">Hours and Location</a>
</li>
</div>
<li class="order-container">
<a class="order" href="order.html">Order</a>
</li>
</ul>
</div>
MDN still advises that <div> is not a valid child of <ul>. Furthermore float adds a whole heap of side effects by removing the items from the natural flow of the document. To modernize this we can make use of display:flex
/*Normalise body*/
body {
margin:0;
}
/*Set flex on the nabar top position logo and links*/
.navbar {
display: flex;
}
/*Ad a maring to the logo link*/
.navbar > a:first-of-type {
margin-left: 5em;
}
nav {
position: fixed;
}
.navigation-links-no-style a {
text-decoration: none;
}
.navbar ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
width: 100%;
/*Ad flex to the nav link element*/
display: flex;
/*Vertically center the links*/
align-items:center;
}
/*Push the last element right but give it a little margin to the right*/
.navbar ul>li:last-of-type {
margin-left: auto;
margin-right:1em;
}
.navigation-links li {
padding-top: 1.3em;
}
.navbar {
overflow: hidden;
position: fixed;
top: 0;
width: 100%;
border-bottom: solid 1px black;
background: white;
}
.navbar a {
display: block;
text-align: center;
padding: 14px 16px;
text-decoration: none;
margin-left: 20px;
color: black;
font-size: 14pt;
}
.order {
color: #FFFFFF !important;
background: #1419e2;
text-decoration: none;
padding: 8px;
border-radius: 5px;
margin-top: 15px;
}
<div class="navbar">
<a class="glacier-hills" href="glacier_hills.html">
<img src="Images/Glacier-Hills-Logo.svg" alt="" width="182" height="90">
</a>
<ul class="navigation-links">
<li>
<a class="menu" href="menu.html">Menu</a>
</li>
<li>
<a class="location" href="location.html">Hours and Location</a>
</li>
<li>
<a class="order" href="order.html">Order</a>
</li>
</ul>
</div>
You should use media queries for making navbar responsive.
a {
text-decoration: none;
color: black;
}
.navbar {
width: 100%;
overflow: hidden;
position: fixed;
top: 0;
display: flex;
justify-content: space-between;
border-bottom: solid 1px black;
}
.div-links {
display: flex;
align-items: center;
width: 70%;
}
.nav-links {
width: 100%;
display: flex;
justify-content: end;
align-items: center;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
.nav-links li {
padding: 2rem;
}
.nav-items {
width: 30%;
display: flex;
justify-content: space-around;
}
.order {
overflow: hidden;
color: #ffffff !important;
background: #1419e2;
text-decoration: none;
padding: 0.8rem;
border-radius: 5px;
}
<div class="navbar">
<a href="glacier_hills.html">
<img
src="Images/Glacier-Hills-Logo.svg"
alt=""
width="182"
height="90"
/>
</a>
<div class="div-links">
<ul class="nav-links">
<div class="nav-items">
<li>
<a class="menu" href="menu.html">Menu</a>
</li>
<li>
<a class="location" href="location.html">Hours and Location</a>
</li>
</div>
<li class="btn">
<a class="order" href="order.html">Order</a>
</li>
</ul>
</div>
</div>
I have a problem.
I have a list with link in all item of the list.
And when I want to add a span inside anchor tag, i have a space and can't remove it..
<li class="elementMyAccount spaceTopBetweenElementMyAccount">
<a href=""
class="elementMyAccountText">
Text4
<div class="adressDescription" >(text4)</div>
</a>
</li>
I send you jsFiddle to show you css and html:
https://jsfiddle.net/5fwvsqnb/10
I had remove this space line with change on my css, but it worked only on google chrome ... but not Safari and IE ( don't try others )
I changed css by :
#my-account .elementMyAccountText{
font-size: 15px;
position: absolute;
margin-left : 5px;
line-height:60px;
width:240px;
display: flex;
align-items: center;
}
#my-account .adressDescription{
display:block;
position:absolute;
font-size: 11px;
text-decoration: none;
margin-left: 40px;
line-height:15px;
display: block;
}
But maybe it's not the solution because on IE I have a space between my span and my text above.
Thanks all if you will try to help me !
The issue is in your code, elementMyAccountText class have position: absolute;.
If you want to display TEXT in left align with the center of the box then You can use display: flex to the ul and li and align-items: center; to the li.
If you want full box clickable then
Remove height from elementMyAccount class and add below code
ul li a{
width: 100%;
display: block;
padding: 20px 0;
}
.listElementMyAccount {
margin-top: 50px;
}
.listElementMyAccount ul {
margin-left: -8px;
display: flex;
}
.elementMyAccount {
border-radius: 7px;
border: 1px solid black;
height: 60px;
width: 240px;
margin-left: 8px;
margin-top: 8px;
display: flex;
align-items: center;
}
/*.elementMyAccountText{
font-size: 15px;
position: absolute;
margin-left : 5px;
line-height:60px;
width:240px;
height:60px;
}*/
.elementMyAccountImg {
margin-left: 5px;
opacity: 0.75;
margin-right: 10px;
vertical-align: middle;
}
.adressDescription {
display: block;
position: absolute;
font-size: 11px;
text-decoration: none;
line-height: 15px;
display: block;
}
<div class="listElementMyAccount">
<ul>
<li class="elementMyAccount">
<a href="" class="elementMyAccountText">
TEXT1
</a>
</li>
<li class="elementMyAccount">
<a href="" class="elementMyAccountText">
TEXT2
</a>
</li>
<li class="elementMyAccount">
<a href="" class="elementMyAccountText">
TEXT3
</a>
</li>
<li class="elementMyAccount">
<a href="" class="elementMyAccountText">
TEXT4
<span class="adressDescription" >(text4)</span>
</a>
</li>
</ul>
</div>
I'm not specialist, but I guess, this is because render engine (i don't know to name that) cannot recognize your style e.g. -webkit-column-count. IE is not supporter, if is it, it will no longer soon. Forget about IE.
I have tried many solutions on SO and none of them seem to work. I have tried many different methods of getting navbar-right to work but to no avail.
"Login" should be on the right.
Here is my nav:
<div class="navbar-header">
<a href="#" class="logo">
<img alt="Brand" src="img/logo.png">
</a>
</div>
<ul class="nav navbar-nav main-nav">
<li>Coin Flip</li>
<li>Deposit</li>
<li>Support</li>
<li>FAQ</li>
<li><i class="fa fa-twitter" aria-hidden="true"></i></li>
<li><i class="fa fa-steam" aria-hidden="true"></i></li>
</ul>
<div class="right">
<ul class="nav navbar-nav navbar-right">
<li>Login</li>
</ul>
</div>
And the relevant css:
.navbar {
background-color: #0C1322;
box-shadow: none;
z-index: 1000;
border: 0;
height: 70px;
border-bottom: inset 1px #2F394E;
display: flex;
align-items: center;
padding-left: 25px;
}
.navbar a {
text-transform: uppercase;
font-weight: bold;
color: #BDC0C5 !important;
word-wrap: none;
font-style: italic;
font-size: 15px;
padding: 0 !important;
transition: 0.5s all;
align-self: center;
padding-right: 30px !important;
}
.navbar a .fa {
font-size: 20px;
}
.navbar a:hover {
color: #4c7ba3 !important;
text-decoration: none;
}
.right {
float: right;
}
.main-nav {
padding-left: 30px;
display: flex;
align-content: center;
justify-content: center;
}
I have tried multiple positions, displays, etc. I think the issue might be in the flex box? When I added a container around the uls, it pulled right but also broke my flex box centering.
Thanks!
JSFiddle: https://jsfiddle.net/ga3rcg0w/ (Make sure to expand the web view)
Try this : Using Inspect Element on your browser.
<ul class="nav navbar-nav navbar-right" style="float:right">
<li>Login</li>
</ul>
Lets try to make the .navbar position to relative, and some change and add code for right class.
And the code looks :
.navbar {
background-color: #0C1322;
box-shadow: none;
z-index: 1000;
border: 0;
height: 70px;
border-bottom: inset 1px #2F394E;
display: flex;
align-items: center;
padding-left: 25px;
position:relative; /* <-- Add This */
}
/* New Style */
.right {
position:absolute;
top:0;
right:0;
}
.right ul {
margin-right:10px;
}
It should work like what you expected :)
I was able to get it to work with this.
.right {
margin-left: auto;
margin-right: 25px;
}
Float does not work due to the flex box.
I am trying to create the navigation as per the picture below, where the text is centered aswell as the icon, but the text is left aligned to the icon. The link needs to be the width of its container, this also needs to be responsive:
How do you go about this?
CODEPEN DEMO HERE
HTML
<ul class="mobile-home-section">
<li>PROPERTY</li>
<li>FUTURE PLANNING</li>
<li>COMMERICAL</li>
</ul>
CSS
.mobile-home-section {
margin: 0;
padding: 0;
list-style-type: none;
width: 100%;
background: #163158
}
.mobile-home-section li {
background-image: url('http://s18.postimg.org/m26o71ohx/icon_future_hover.png');
background-repeat: no-repeat;
background-position: 0 10px;
padding-left: 50px;
}
.mobile-home-section li a {
color: white;
text-decoration: none;
padding: 20px 0;
display: block;
border-bottom: 1px solid white;
}
EDIT Changed the code to make it responsive
If i was you, I would not place the icon for the link as a background image. I would place the icon as an image inside of the link tag.
HTML
<div class="container">
<ul class="mobile-home-section">
<li>
<a href="#">
<span><img src="img2.jpg">PROPERTY</span>
</a>
</li>
<li>
<a href="#">
<span><img src="img2.jpg">FUTURE PLANNING</span>
</a>
</li>
<li>
<a href="#">
<span><img src="img3.jpg">COMMERICAL</span>
</a>
</li>
</ul>
</div>
CSS
.container {
background: #273F87;
}
ul.mobile-home-section {
display: block;
list-style-type: none;
padding: 0px;
}
ul.mobile-home-section li:nth-child(2) {
border-top: 2px solid #fff;
border-bottom: 2px solid #fff;
}
ul.mobile-home-section li a {
display: block;
color: #fff;
padding: 0px;
font-family: serif;
margin: 0px auto;
text-decoration: none;
}
ul.mobile-home-section li a span img {
width: 50px;
height: 50px;
padding-right:20px;
display: inline-block;
vertical-align: middle;
}
ul.mobile-home-section li a span {
padding: 10px 0px;
width: 230px;
display:block;
margin: auto;
}
Updated JSfiddle
As others have said, it's going to be easier using an image. The most important thing to know is that not all display: values support vertical alignment - my go-to is display: inline-block, but if you're using flexbox it might be more convenient to use display: flex
Depending on context, I typically use one of these three solutions:
Adjacent inline blocks
CSS tables
A pseudoelement with a background image
Here are examples of each of those.
Notes:
For the table solution, the <li> loses its bullet and gets an auto width (it's as wide as its contents) - depending on your context, you might want to add on a width: 100% to #or-another li
For the background image solution, if the image isn't necessarily the same size as the container you'll want to use background: no-repeat center center; -webkit-background-size: cover; background-size: cover; background-image:url(...);
In all three cases, we're accounting for the possibility that either of the elements could be the taller one. If you know the image is always going to be taller than the text, you could target #or-another span instead of #or-another li > *, and you could drop #one-more li span {...} entirely
#one-way li > * {
display: inline-block;
vertical-align: middle;
}
#or-another li {
display: table;
}
#or-another li > * {
display: table-cell;
vertical-align: middle;
}
#one-more li span {
display: inline-block;
vertical-align: middle;
}
#one-more li:before {
content:'';
width: 200px;
height: 200px;
display: inline-block;
vertical-align: middle;
background:url('https://placehold.it/200x200');
}
<ul id="one-way">
<li>
<img src="https://placehold.it/200x200" alt="" />
<span>1</span><!-- or div or p or what have you -->
</li>
</ul>
<ul id="or-another">
<li>
<img src="https://placehold.it/200x200" alt="" />
<span>2</span>
</li>
</ul>
<ul id="one-more">
<li>
<span>3</span>
</li>
</ul>
Add a text-align: center; in the .mobile-home-section class to make them align to the center and remove the padding-left: 50px; under .mobile-home-section li class. And these two CSS will become:
.mobile-home-section {
margin: 0;
padding: 0;
list-style-type: none;
width: 100%;
background: #163158;
text-align: center;
}
.mobile-home-section li {
background-image: url('http://s18.postimg.org/m26o71ohx/icon_future_hover.png');
background-repeat: no-repeat;
background-position: 0 10px;
}
You can see the demo here.
Try just editing the paddings and background-position.
.container {
width: 600px;
}
.mobile-home-section {
margin: 0;
padding: 0;
list-style-type: none;
width: 100%;
background: #163158
}
.mobile-home-section li {
background-image: url('http://s18.postimg.org/m26o71ohx/icon_future_hover.png');
background-repeat: no-repeat;
background-position:50% 15px;
padding-left: 50px;
}
.mobile-home-section li a {
color: white;
text-decoration: none;
padding: 20px 50%;
display: block;
border-bottom: 1px solid white;
text-align:left;
}
UPDATE try this
.mobile-home-section li a {
color: white;
text-decoration: none;
padding: 20px 0 20px 50%;
display: block;
border-bottom: 1px solid white;
text-align: left;
}
Update the padding of .mobile-home-section li a
The selectors could use some love, but here is my codepen:
<div class="container">
<ul class="mobile-home-section">
<li><span><img src="http://s18.postimg.org/m26o71ohx/icon_future_hover.png" /><span>PROPERTY</span></span>
</li>
<li><span><img src="http://s18.postimg.org/m26o71ohx/icon_future_hover.png" /><span>FUTURE PLANNING</span></span>
</li>
<li><span><img src="http://s18.postimg.org/m26o71ohx/icon_future_hover.png" /><span>COMMERICAL</span></span>
</li>
</ul>
.container {
width: 600px;
}
.mobile-home-section {
margin: 0;
padding: 0;
list-style-type: none;
width: 100%;
background: #163158
}
.mobile-home-section li {
margin: 0;
padding: 0;
}
.mobile-home-section li a {
display: block;
height: 3em;
}
.mobile-home-section li a > span {
display: block;
width: 55%;
padding: 0;
margin: 0 auto;
text-align: left;
}
.mobile-home-section li a > span > span {
line-height: 2em;
font-size: 1.4em;
position: relative;
top: -0.4em;
}
.mobile-home-section li span img {
margin-right: 0.75em;
height: 2.6em;
position: relative;
top: 0.2em;
}
.mobile-home-section li a {
border-bottom: 1px solid white;
color: white;
display: block;
font-family: 'Times New Roman';
font-size: 1.2em;
padding: 0;
text-align: center;
text-decoration: none;
}
http://codepen.io/anon/pen/PZwvZz
I got a template from themeforest. There are some boxes near the bottom of the website (the ones with delivery worldwide etc)
When I make it smaller they dissapear, does anybody know how I can make them stack under each other?
This is the template: http://pixelgeeklab.com/demo/wordpress/flatize/?page_id=579
It's about this part:
<div class="wpb_text_column wpb_content_element ">
<div class="wpb_wrapper">
<ul class="wp-ads">
<li><i class="fa fa-plane"></i><strong>Delivery worldwide</strong>See all conditions</li>
<li><i class="fa fa-refresh"></i><strong>30 days returns</strong>For a smooth shopping</li>
<li><i class="fa fa-phone"></i><strong>0123 456 789</strong>Contact Customer</li>
<li><i class="fa fa-lock"></i><strong>30 days returns</strong>For a smooth shopping</li>
<li><i class="fa fa-question-circle"></i><strong>Shopping Guide</strong>Contact Customer</li>
</ul>
</div>
</div>
The reason it dissapears is because it is inside <section class="section-element hidden-xs"> so it's display is none when your width < 767px.
You should remove the class hidden-xs.
And add this css code.
#media (max-width: 767px){
.wp-ads li {
background: #1abc9c;
color: white;
display: block;
float: none;
overflow: hidden;
padding: 20px 0 20px 25px;
width: 20%;
}
}
You may want to increase the width when your view is smaller.
For example:
#media (max-width: 767px){
.wp-ads li {
background: #1abc9c;
color: white;
display: block;
float: none;
overflow: hidden;
padding: 20px 0 20px 5%;
width: 90%;
}
}
Check out the css, if I understand you right, you simply want to disable the floating of the li elements and make them appear as a stack, right?
Have a look at template.css about line 1497:
.wp-ads li {
background: #1abc9c;
color: white;
display: inline-block;
float: left;
overflow: hidden;
padding: 20px 0 20px 25px;
width: 20%;
}
change it to
.wp-ads li {
background: #1abc9c;
color: white;
/* display: inline-block; */
/* float: left; */
overflow: hidden;
padding: 20px 0 20px 25px;
width: 20%;
}