Css distribute text over 2 lines and vertically align - html

I am trying to achieve a layout like the image in the link below. It's basically a set of list items that contain some text and then a large number to the right. I am wondering if it would be possible to distribute the text where it's outputted over 2 lines even though there is no fixed width on the list item elements
Additionally, i am looking for a cross browser solution to vertically align the text and the numbers inside the LI. It needs to work in IE7+ without any javascript

Try this
<ul>
<li>
<div class="top">To</div>
<div>For Submit<span class="number">50</span></div>
</li>
<li>
<div class="top">To</div>
<div>For Submit<span class="number">50</span></div>
</li>
<li>
<div class="top">To</div>
<div>For Submit<span class="number">50</span></div>
</li>
<ul>
CSS
ul {
list-style:none;
font-size:14px;
margin:0;
padding:0;
}
ul li {
background-color:gray;
display:inline-block;
padding:5px 10px;
}
.number {
margin-left:10px;
font-size:20px;
}
JS Fiddle Demo

First solution: navigation bar
I think that you need basically a navbar.
Twitter Bootstrap navbar is the best thing you can chose I say.
See the documentation.
<div class="navbar">
<div class="navbar-inner">
<a class="brand" href="#">Title</a>
<ul class="nav">
<li class="active">Home</li>
<li>Link</li>
<li>Link</li>
</ul>
</div>
</div>
See live example: JSFIDDLE.
Second solution
Also, you can use rows and spans.
Documentation is here.
Example:
<div class="row">
<div class="span1">Text 1</div>
<div class="span1">Text 2</div>
<div class="span1">Text 3</div>
<div class="span1">Text 4</div>
<div class="span1">Text 5</div>
<div class="span1">Text 6</div>
</div>
JSFIDDLE

Related

I can't add a logo to my website. It takes up the entire page. Please help me

HTML
<body>
<!-- Header -->
<section id="header">
<div class="header container">
<div class="nav-bar">
<div class="brand">
<a href="#home">
</a>
</div>
<div class="nav-list">
<div class="hamburger">
<div class="bar"></div>
</div>
<ul>
<li>Home</li>
<li>Services</li>
<li>About</li>
<li>Contact</li>
</ul>
I'm trying to add a logo to my website. The logo fills the screen. I can't adjust its size.HTML codes like this.
It is difficult to answer without seeing the stylings and I see you haven't provided a proper code.
Just give the img tag a width and a height and position the div wrapping it correctly.
Something like this,
div {
position:relative;
text-align:center;/* Add This*/
}
<div>
<img src="https://www.w3schools.com/tags/img_girl.jpg" width='300px' height='400px'/>
</div>
I suggest you to refer the following,
Positioning a div
Inserting an img
Good luck mate!

Bootstrap navbar hide content on #link

I have a problem with the navbar-fixed-top item. It hides content form the container.
This is a common problem solved by adding the following css code :
body { padding-top: 70px; }
Now, when I load my page, the container is not hidden by the navbar anymore. The problem is when I want to go to a specific item in the page with a href=#item. In this case, the item is always hidden by the navbar.
I have created a simple code on Codeply which shows this problem. In this example, when I click on "Got to test3", the item <h2 class="font-weight-light">TEST3</h2> is hidden by the navbar.
Here is the code below :
<nav class="navbar navbar-expand-sm bg-dark navbar-dark fixed-top">
HELLO NAVBAR
</nav>
<div class="container py-2">
<div class="row">
<div class="col">
<div class="sidebar-sticky" id="menu">
<ul class="nav flex-column">
<li class="nav-item">
Go to test1
</li>
<li class="nav-item">
Go to test2
</li>
<li class="nav-item">
Go to test3
</li>
<li class="nav-item">
Go to test4
</li>
</ul>
</div>
</div>
<div class="col">
<div id="test">
<h2 class="font-weight-light">TEST1</h2>
<p>
This is a Bootstrap starter example snippet.
</p>
<br/><br/><br/><br/><br/>
</div>
<div id="test2">
<h2 class="font-weight-light">TEST2</h2>
<p>
This is a Bootstrap starter example snippet.
</p>
<br/><br/><br/><br/><br/>
</div>
<div id="test3">
<h2 class="font-weight-light">TEST3</h2>
<p>
This is a Bootstrap starter example snippet.
</p>
<br/><br/><br/><br/><br/>
</div>
<div id="test4">
<h2 class="font-weight-light">TEST4</h2>
<p>
This is a Bootstrap starter example snippet.
</p>
<br/><br/><br/><br/><br/>
</div>
</div>
</div>
</div>
Here's the solution
body {
padding-top: 70px;
}
#test{
padding-top:90px;
}
#test2{
padding-top:90px;
}
#test3{
padding-top:90px;
}
#test4{
padding-top:90px;
}
For the current case, you could add the padding to the div elements which have a h2 following them (such as "Test3"). Adding div h2 { padding-top: 70px; } does that for your current structure. However, in order to not depend on the h2 following a div as you further develop your project, you could also create an own class to which the padding-top-rule applies, and add it to those elements for which it is needed.
Hope that helps.
From the question Fixed page header overlaps in-page anchors, the solution is not the accepted answer but is in the answers. So I'll repeat it here.
I have add this class in the css file :
.hreflink::before {
content: "";
display: block;
height: 70px; /* fixed header height*/
margin: -70px 0 0; /* negative fixed header height */
}
and then I have define every element I want to go to with this class, for example :
<div id="test3" class="hreflink">

My footer won't align vertically

I'm trying to make my li elements stay on the same line but they won't (they are aligning horizontally but that's about it)
Code is as follows:
<footer>
<div class="container">
<div id="coisas"
class="col-6">
<div class="row">
<ul class="col-6">
<li class="col-1"><img src="icon-behance.png"></li>
<li class="col-1"><img src="icon-behance.png"></li>
<li class="col-1"><img src="icon-behance.png"></li>
</ul>
</div>
<div id="nothing"
class="col-6">
</div>
</div>
</footer>
And here is the CSS:
#coisas {
float: right;
bottom: 0;
position: absolute;
size: 50%;
left: 0;
padding-left: 5%;
padding-right: 5%;
}
#nothing {
size: 50%;
right: 0;
}
To achieve expected result, use below option
#coisas ul li{
display:inline;
}
Codepen- https://codepen.io/nagasai/pen/vmdYNg
I'm not sure what you're trying to do, but Bootstrap col's should always be inside row..
<footer>
<div class="container">
<div class="row">
<div id="coisas" class="col-6">
<ul class="row list-unstyled">
<li class="col-1"><img src="//placehold.it/40"></li>
<li class="col-1"><img src="//placehold.it/40"></li>
<li class="col-1"><img src="//placehold.it/40"></li>
</ul>
<div id="nothing" class="col-6">
</div>
</div>
</div>
</div>
</footer>
http://codeply.com/go/ArVyBK4VU5
Tried your problem, resolved it now you can check it here!
#coisas ul li{
display:inline;
}
Demo
The float property specifies whether or not a box (an element) should float.
If you float the li elements to the left, they will lineup in same line.So to put them on one line you can use this:
#coisas ul li{
list-style-type:none;
float:left;
}
The list-style-type:none; property is only for removing the bullet points of the list items.
You can learn more about the css float property here: https://www.w3schools.com/cssref/pr_class_float.asp

Correct way of sticking to the bottom of a div

I'm trying to have a ul and a span elements to stick to the bottom of their containing div. The only way I managed to so is through setting them with position:relative and playing with bottom: x for each element separately (according to its size).
Is there a more standard way to do it?
Here is the code: jsfiddle
<div id="header">
<div id="top_menu">
<span id="logo">TechSystems</span>
<span id="sub_logo">think smarter</span>
<div id="menu_content">
<ul>
<li>home</li>
<li>about</li>
<li>contact us</li>
</ul>
</div>
</div>
</div>
<div id="slideshow">
</div>
Try adding to #menu_content:
#menu_content
{
position:fixed;
bottom: 0px;
}
See: https://jsfiddle.net/x7p35mrz/

How to center two pieces of text using CSS and Bootstrap?

I'm very new to programming and I've been trying to figure this out for a while now but I'm still having trouble. I'm trying too center two different pieces of text so that they are equal distances from the left and right side and from the top and bottom of the page.
Here's my code:
<div class="entrance">
<div class="container">
<div class="row">
<div class="col-md-6">
<li> Example1 </li>
</div>
<div class="col-md-6">
<li><a href="#" style="text-decoration:none" > Example2 </a></li>
</div>
</div>
</div>
</div>
I just can't seem to figure out what I'm missing and I'm sure it's probably something very simple that I'm just not getting. Any help is appreciated, thanks!
You can use css text-align to achieve what you want. text-aligh: right on the left hand <div> and text-align: left on the right hand <div>.
As #Manish mentioned, I also removed the <li> wrapper. I also added col-xs-6 to the <div>'s so it works on smaller views too.
Example: http://jsfiddle.net/11cLvc2c/3/
In case you just want to center the text, try this:
Add "text-center" next to each "col-md-6" classes:
<div class="entrance">
<div class="container">
<div class="row">
<div class="col-md-6 text-center">
<li> Example1 </li>
</div>
<div class="col-md-6 text-center">
<li><a href="#" style="text-decoration:none" > Example2 </a></li>
</div>
</div>
</div>
</div>
In case you'd like to make full centering, I'd recommend to step a little outside from bootstrap and use flexboxes. Flexboxes are new to CSS3 and solve most of our problems. See here for more info:
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Here's your modified code:
<style type="text/css">
.entrance{
display: flex;
justify-content:center;
align-items: center;
width: 800px; /*Put your desired width*/
height: 400px; /*Put your desired height */
}
.container div
{
width: 50%;
text-align: center;
}
</style>
<div class="entrance">
<div class="item-1">
Item 1
</div>
<div class="item-2">
Item 2
</div>