How to space words in a div with spans - javascript

I've got trouble spacing words in a div with spans. Here is the html :
<div class="footer-links">
<span>Suggestions</span>
<span>Help</span>
<span>Contact us</span>
</div>
and the css :
.footer-links{
float: right;
margin-top: 11px;
margin-bottom: 11px;
}
JS fiddle her ==> https://jsfiddle.net/kxdnwL4k/3/
How to space words so its gets easier for users to read ?
Many thanks

I'm assuming you mean the words are too close to read.
.footer-links{
float: right;
margin-top: 11px;
margin-bottom: 11px;
word-spacing: 5px;
letter-spacing: 2px;
}
<div class="footer-links">
<span>Suggestions</span>
<span>Help</span>
<span>Contact us</span>
</div>
I used letter-spacing to space out the letters a bit, and word-spacing to put some space between words a bit more.

Just add a horizontal margin to the spans. You can exclude the first one using :not(:first-child) or span + span
.footer-links {
margin: 11px 0;
float: right;
}
.footer-links span:not(:first-child) {
margin-left: 1em;
}
<div class="footer-links">
<span>Suggestions</span>
<span>Help</span>
<span>Contact us</span>
</div>

Why not just to use margin css property to make them look more clearer?
.footer-links a {
margin: 0 5px 0 5px;
}
.footer-links {
float: right;
margin-top: 11px;
margin-bottom: 11px;
}
.footer-links a {
margin: 0 5px 0 5px;
}
<div class="footer-links">
Suggestions
Help
Contact us
</div>

I would suggest a ul for the list of links - its always best to use the right tool for the job.
Note that I have put this ul into a <footer> element - use a div if you are not using the HTML5 doctype. then its just a case of applying a margin to the ul lis and you have a horizontal list with spaced out li's.
You could also get fancy and apply an "active" class to the li that reflects the current page. Then you would have a list of footer links that are spaced and in context with your page.
.footer-links {
list-style:none
}
.footer-links li {
display:inline;
margin-right:30px
}
<footer>
<ul class="footer-links">
<li>Suggestions</li>
<li>Help</li>
<li>Contact us</li>
</ul>
</footer>

Related

Bootstrap 3 Unordered list displaying incorrectly

I am creating a unordered list in Bootstrap 3 for my class. I am using a glyphicon as the bullet point. I am having trouble with the last item wrapping in desktop view and as I view it in different breakpoints the items sometimes display inline.
Here is my html
<div class="bg">
<div class="container-fluid text-center" style="height:100%;">
<div class="row content">
<div class="col-sm-2">
</div>
<div class="col-lg-8 text-left">
<h2>EDUCATION</h2>
<hr class="style1">
<h3 class="job">Bachelor of Science, Marketing - San Jose State University</h3>
<h2>CERTIFICATIONS</h2>
<hr class="style1">
<h3 class="job">HubSpot Inbound Certification</h3>
<h4>2016</h4>
<p>The course details the stages of the inbound methodology. Lectures explained various inbound marketing topcis such as how to optimize websites and best practices for a sucessful landing page.</p>
<h3 class="job">Coursera Web Design for Everybody</h3>
<h4>2017</h4>
<ul class="custom-bullet col-lg-4">
<li>Introduction to HTML5</li>
<li>Introduction to CSS3</li>
<li>Interactivity with JavaScript</li>
<li>Advanced Styling with Responsive Design</li>
</ul>
</div>
</div>
</div>
</div>
<div class="col-sm-2">
</div>
Here is my css:
.bg {
background-color:#ffffff;
background-size:100%;
width:100%;
height: auto;
padding-top:8%;
margin-bottom:0;
margin-top:3%;
}
.job {
color: #800080;
}
.custom-bullet li {
display: block;
}
.custom-bullet li:before
{
/*Using a Bootstrap glyphicon as the bullet point*/
content: "\e080";
font-family: 'Glyphicons Halflings';
font-size: 9px;
float: left;
margin-top: 4px;
margin-left: -17px;
color: #000000;
}
You are setting float: left; to the ul li, that causes the 'inline' looking behavior.
On larger screen use have container with col-lg-4, so the container is smaller and some items do not fit there and appears on new line.
You can reset this, or adjust the selector, depends on what you want.
.custom-bullet li
display: block;
float: none;
}
The problem is with this class
.custom-bullet li:before
{
/*Using a Bootstrap glyphicon as the bullet point*/
content: "\e080";
font-family: 'Glyphicons Halflings';
font-size: 9px;
float: left; // change to none
margin-top: 4px;
margin-left: -17px;
color: #000000;
}
By the way why did you add this as with CSS pseudo-elements rather than writing in html.

How to align two span elements separately but in same line

I am working on aligning two span elements should be present in same line but have separated as shown in below. The code i am using is below.
If I do not use float:right the both texts are coming in single line with attaching one each other.
If I use float:right; they are not aligning in same line, having some misalignment between them.
with float:right; the result will be this
without float:right; the result will be this
Please give me suggestions for this
.clearSpan {
color: $alt-dark-blue;
float: right;
cursor: pointer;
clear: both;
font-size: 10px;
}
.saveSpan {
color: $alt-dark-blue;
clear : both;
cursor: pointer;
font-size: 10px;
}
<div>
<span class="saveSpan" >Save as Default Filters</span>
<span class="clearSpan" >Clear All Filters</span>
</div>
you can use flexbox for that
div {
display: flex;
justify-content: space-between;
border-bottom: 1px solid grey
}
span {
color: blue;
cursor: pointer;
font-size: 10px;
}
<div>
<span class="saveSpan">Save as Default Filters</span>
<span class="clearSpan">Clear All Filters</span>
</div>
Maybe you can do:
.clearSpan {
margin-left: 15px;
}
or
.saveSpan {
margin-right: 15px;
}
That should separate it.
You need to define a style for your span tags as,
span {
display: inline-block;
}

How to display divs side by side inside a list (inline-block doesn't work) while vertically align the right div (vertical-align doesn't work)

I have a list of items where an item is some text and a button. I want text to be aside the button. I used inline-block but it doesn't work.
Note that I want text to wrap too.
<ul>
<li>
<div class="inline-block">
Side by side
</div>
<div class="inline-block">
Side by side
</div>
</li>
<li>Profile</li>
<li>Logout</li>
</ul>
styles:
.inline-block {
display: inline-block;
}
ul {
position: absolute;
padding: 4px 0;
top: 28px;
right: 0;
width: 80px;
background-color: white;
border: 1px solid hsl(0, 0%, 80%);
border-radius: 4px;
box-shadow: 0 3px rgba(0, 0, 0, 0.05);
list-style-type: none;
}
Codepen: http://codepen.io/TimGThomas/pen/oXzpXL
Edit
I achieved the expected result. There is a lot of wrapped text and a button aside. I want button to vertically align in the middle, I tried vertical-align:middle but it doesn't work.
<ul style="width: 300%">
<li>
<div>
<div class="inline-block text-mid">
A lot of wrapped text
A lot of wrapped text
A lot of wrapped text
</div>
<div class="inline-block" style="vertical-align:middle;">
In the middle
</div>
</div>
</li>
</ul>
style:
.text-mid {
width: 100px;
}
New Codepen: http://codepen.io/anon/pen/wajWBV
Give bigger UL width:
ul {
width: 280px;
}
CodePen: http://codepen.io/anon/pen/wajWBV
i think you better use <span> instead of a <div>, <span> display property by default set to inline

Multiple classes animating on hover

I'm styling a menu that has a toggleClass in there, so far no problem, but when i have the hover function and i do hover then mouse on the menu elements the function executes on all the menu's elements, how do i manage to only affect one at the time?
The menu:
<div id="menu_segundo">
<ul>
<li class="curso av">AV</li>
<li class="curso dc">DC</li>
<li class="curso dp">DP</li>
<li class="curso pa">PA</li>
</ul>
</div>
The Css
#menu_segundo {
margin-top: 20px;
float: right;
background: #58ACFA;
}
.curso {
color: white;
font-family: DIN;
width: 25px;
height: 10px;
border-left: 2px solid white;
padding-left: 10px;
padding-right: 0px;
}
.expand_menu{
color: white;
font-family: DIN;
width: 150px;
height: 10px;
border-left: 2px solid white;
padding-left: 10px;
padding-right: 0px;
}
The JS
var segundo = $('#menu_segundo').find('ul').children();
segundo.hover(function(){
$(this).toggleClass('expand_menu');
})
Here is a DEMO of the menu
This does not need JS to function.
Simply change .expand_menu to .curso:hover in your CSS.
Alternatively, to fix your JS use:
$("#menu_segundo").on("hover", ".curso", function(){
$(this).toggleClass('expand_menu');
});
The problem with your JS is that you are toggling the class on all li elements. segundo is set to equal all li elements, not the one being hovered.
UPDATE
There is a problem beyond the initial applying of classes, the CSS/HTML structure is not rendering correctly. The problem is that extending one of the li elements increases the size of the entire ul moving all li elements in the process.
Updating the HTML to this:
<div id="menu_segundo">
<div class="curso av">AV</div>
<div class="curso dc">DC</div>
<div class="curso dp">DP</div>
<div class="curso pa">PA</div>
</div>
And updating the CSS to:
#menu_segundo {
margin-top: 20px;
float: right;
}
.curso {
color: white;
font-family: DIN;
width: 25px;
border-left: 2px solid white;
padding-left: 10px;
padding-right: 0px;
background: #58ACFA;
float: right;
clear:both;
}
.curso:hover{
width: 150px;
}
Gets the desired behavior. See this Fiddle for an example.
Note
The CSS can also be set to
.expand_menu{
width: 150px;
}
To continue with the JS solution.
Try like
var segundo = $('#menu_segundo li')
segundo.hover(function(){
$(this).toggleClass('expand_menu');
})

jquery show() breaks css position properties while acting

my problem is in my website,when I load the page and click Home,if article is visible on screen, the js I've written hides it smoothly and great with no problem.but when I click the About Us Link,it shows the article but with broken css position while its act is finished.
here is the code:
HTML:
<nav>
<ul class="sf-menu sf-vertical">
<li><a href=# onclick=home()>Home</a></li>
<li><a href=#about onclick=about()>About Us</a></li>
<li><a href=#>Cuisines</a>
<ul>
<li><a href=#starters>Starters</a></li>
<li><a href=#>Main Dishes</a></li>
<li><a href=#>Desserts</a></li>
<li><a href=#>Mezes</a></li>
</ul>
</li>
<li><a href=#>Wine List</a></li>
<li><a href=#gallery>Gallery</a></li>
<li><a href=#contacts>Contacts</a></li>
</ul>
</nav>
<article class=vanished id=about>
<h1>About Us</h1>
<div class="main-wrapper scroll">
<div class="wrapper clearfix">
<img src=img/bazar-place.png alt=bazar-place width=222 height=150 class=about-img>
<h4>Our Restaurant</h4>
<p>Bazar is a restaurant located between the districts Haga and Vasastaden in Gothenburg with a focus on Turkish and Persian food of the best quality that creates opportunities for an exciting mix all the way, from appetizer to dessert.</p>
</div>
<div class="wrapper clearfix">
<img src=img/belly.jpg alt=belly-dancing width=222 height=167 class=about-img id=belly>
<h4>Events</h4>
<p>Every Saturday from 21, we have Belly dancing at Bazar.</p>
</div>
<div class="wrapper clearfix">
<img src=img/food.jpg alt=food-services width=222 height=167 class=about-img id=food>
<h4>Food Services</h4>
<p>Taste our famous pasta dish to the human price of 69 :- We offer 10% discount for take-away at our entire menu.</p>
<p>At lunchtime you can choose from three Turkish pasta dishes or among two or three different main dishes. Ask about vegetarian options! Drinking, salad and coffee / tea included. Lunch can also be picked up.</p>
</div>
<div class="wrapper last clearfix">
<img src=img/extra.jpg alt=extra-services width=222 height=167 class=about-img id=extra>
<h4>Extra Services</h4>
<p>We can help with everything from after work, kick-off to the birthday called with food and drink that lasts all night. Do you want more entertainment we can arrange live music and belly dancing.</p>
</div>
</div>
</article>
JAVASCRIPT:
function home(){
if ($(".active") == [])
{
return ;
}
else
{
var active = $(".active");
active.css("display","inline-block");
active.hide("slide",{direction:"left"},700);
active.attr("class","vanished");
}
}
function about(){
if ($(".active") == [])
{
var hidden = $("#about");
hidden.css("display","inline-block");
hidden.show("slide",{direction : "right"},700);
hidden.attr("class","active");
}
else
{
if ($("#about").attr("class") == "active")
{
return ;
}
else
{
var active = $(".active");
active.css("display","inline-block");
active.hide("slide",{direction:"left"},700);
active.attr("class","vanished");
var hidden = $("#about");
hidden.css("display","inline-block");
hidden.show("slide",{direction : "right"},700);
hidden.attr("class","active");
}
}
}
CSS:
article{
position: absolute;
width: 550px;
height: 100%;
background-image: url("../img/blockBG.png");
z-index: 1;
left: 235px;
border-left: 1px solid #4A4A4A;
border-right-color: #7b7b7b;
border-right-style: solid;
border-right-width: thick;
padding-right: 40px;
padding-left: 40px;
text-align: center;
}
.vanished{
display:none;
}
.main-wrapper{
position:relative;
z-index:1;
width: 100%;
height: 590px;
display:block;
}
.wrapper{
border-bottom:1px solid #4A4A4A;
margin-bottom: 15px;
}
.last{
border: none;
}
h4{
color: #efefef;
text-decoration: none;
text-align: left;
font-family:'Yeseva One',cursive;
font-size: 17px;
font-weight: normal;
margin-bottom: 10px;
margin-top: 0;
line-height: 19px;
}
h1{
position: relative;
font-family:'Yeseva One',cursive;
font-size:60px;
z-index: 2;
color: white;
margin-top: 90px;
padding-bottom: 41px;
margin-bottom: 20px;
font-weight: normal;
border-bottom:1px solid #4A4A4A;
}
p{
color: #efefef;
text-decoration: none;
text-align: left;
font-family:Arial, sans-serif;
font-size: 12px;
}
.clearfix:before,
.clearfix:after {
content: " "; /* 1 */
display: table; /* 2 */
}
.clearfix:after {
clear: both;
}
/*
* For IE 6/7 only
* Include this rule to trigger hasLayout and contain floats.
*/
.clearfix {
*zoom: 1;
}
The problem is with the <h1> margin-top only being correctly applied at the end of the animation.
Try turning the distance top into a padding instead of margin, it should fix it:
h1{
position: relative;
font-family:'Yeseva One',cursive;
font-size:60px;
z-index: 2;
color: white;
margin-top: 0;
padding-top: 90px;
padding-bottom: 41px;
margin-bottom: 20px;
font-weight: normal;
border-bottom:1px solid #4A4A4A;
}
Alternatively, you could give the parent <article> a padding or border top. This will prevent the <h1> margin from collapsing outside it's container while the animation runs.

Categories

Resources