Bootstrap 4 align right in cell - html

I'm currently writing an interface for a ticket system that uses Bootstrap 4's grid system to position components about the system. As you can see from the screenshot below, the UI has two container-fluid divs stacked. The top div aligns perfectly, the second one I am struggling with.
I want it to render like this (without the pink - the pink is showing the two cols):
however it is rendering like this:
The code that renders this is as follows:
HTML:
<div class="container-fluid container-navbar">
<div class="row navbar">
<div class="col">
logo goes here
</div>
<div class="col text-center help-desk">
help desk.
</div>
<div class="col text-right">
<i aria-hidden="true" class="fa fa-bars" id="settings-menu" ></i>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row ticket-summary-navbar">
<div class="col text-right">
<div class="global-ticket-summary">
<ul>
<li >
<p class="ticketCount" >5</p>
<p class="nameLabel" >User1</p>
</li>
<li >
<p class="ticketCount" >3</p>
<p class="nameLabel" >User2</p>
</li>
<li >
<p class="ticketCount" >8</p>
<p class="nameLabel" >User3</p>
</li>
<li >
<p class="ticketCount" >6</p>
<p class="nameLabel" >User4</p>
</li>
<li >
<p class="ticketCount" >2</p>
<p class="nameLabel" >User5</p>
</li>
</ul>
</div>
</div>
<div class="col">
</div>
</div>
</div>
CSS:
body{
background-color: #ababab;
}
.navbar{
color: white;
background-color: rgba(58, 191, 195, 1);
height: 75px;
padding-left: 10px;
padding-right: 10px;
}
.container-navbar{
padding-left: 0px;
padding-right: 0px;
min-width: 490px;
}
.help-desk{
font-size: 30px;
font-family: 'Roboto', sans-serif;
font-weight: 300;
}
#settings-menu{
font-size: 25px;
cursor: pointer;
}
.ticket-summary-navbar{
background-color: #f7f7f7;
height: 90px;
}
.global-ticket-summary {
font-family: 'Roboto', sans-serif;
color: #1b1b1b;
font-weight: 200;
}
.global-ticket-summary ul {
list-style-type: none;
}
.global-ticket-summary ul li {
text-align: center;
float: left;
width: 100px;
}
.global-ticket-summary ul li .ticketCount {
font-size: 22pt;
margin-bottom: -4px;
cursor: pointer !important;
}
.global-ticket-summary ul li .nameLabel {
font-size: 11pt;
/*margin-bottom: 0;*/
color: #656565;
cursor: pointer !important;
}
As you can see it renders the <ul> in the middle, even though I have the text-right directive.
I can certainly get it working by adding "float:right;" to the UL - which positions correctly horizontally, however it then no longer aligns vertically correctly (it snaps to the top of the div). I have searched in many places for a solution, however all point to using the navbar for Bootstrap, which isn't relevant in this case.
Is there a way I can have the UL align right to its parent div without resorting to padding/margin CSS hacks?
Plunkr link also: https://next.plnkr.co/plunk/y4EYmtpgwRvHkjuI

Put the text align on the global-ticket-summary div, and if that doesn't work put it in the UL. Text align only works for the direct child elements I believe

You can use flexbox to align content. Just put this .flex-container class into your code to right align child elements.
.flex-container {
display: flex;
justify-content: flex-end;
align-items: center;
}
If you are new to css i will recommend you to take a look into flexbox.

You want to put ul in right side of col. Correct me! if i misunderstood your question.
So, you need to do the following in your style.css file,
just replace with following css code.
.global-ticket-summary ul {
list-style-type: none;
text-align: right!important;
}
.global-ticket-summary ul li {
float: left;
width: 100px;
}

Use flex utilities for bootstrap 4. Add following classes to the first column (which is having text-right): d-flex, justify-content-end.
...
<div class="container-fluid">
<div class="row ticket-summary-navbar">
<div class="col d-flex justify-content-end">
...
It is aligning as you want to the right.
For reference here is link to flex utility for bootstrap 4 : https://getbootstrap.com/docs/4.0/utilities/flex/

Related

Icon alignment is bad when zoom chrome to 125 or other scale?

I have following code from one template:
My code is upload on:
JSFIDDLe
<div class="sidebar-body" dir="rtl">
<div class="side-logo d-flex justify-content-between">
<div><img src="images/logo.png" alt="">
</div>
</div>
<div class="side-contact">
<ul class="list-unstyled">
<li><i class="la la-map-marker"></i>22222</li>
<li><i class="la la-phone"></i>+3333</li>
<li><i class="la la-envelope"></i>asdasdasd</li>
</ul>
</div>
CSS:
.main-menu .sidebar-body .side-contact {
margin-bottom: 45px;
}
.main-menu .sidebar-body .side-contact ul li {
color: #666666;
margin-bottom: 10px;
}
.main-menu .sidebar-body .side-contact ul li i {
font-size: 18px;
color: #05ab90;
margin-top: 1px;
margin-right: 6px;
vertical-align: text-bottom;
float: left;
height: 30px;
}
in 100%, 200% and ... all things is okey but when Zoom in chrome to 125 (for example) one last icon alignment gets into trouble and not align with other icons.
attach a live link on jsfiddle
You need to clear: both on each line item element. The problem is the two float: left icons are bumping into each other. Adding the clear to each row will ensure that a new block is started since floated elements are pulled out of the flow of content.
.main-menu .sidebar-body .side-contact ul li {
color: #666666;
margin-bottom: 10px;
clear: both;
}

How can I line up my html elements in an element?

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>

CSS shrink width when text wrapped into multi-lines

I'm building a list widget where I have multiple <li> with two sibling elements wrapped inside.
A <span> for the title and a <div> for the bottom line. That line must vary depending the width of their adjacent span element.
.limit-area {
width: 250px;
height: 350px;
background-color: #96ceb4;
}
.limit-area ul {
font-size: 0;
list-style-type: none;
-webkit-padding-start: 0;
}
.limit-area ul li {
background-color: #ffeead;
display: table;
margin-bottom: 20px;
}
.limit-area ul li .wrapper span {
font-size: 24px;
color: #010101;
}
.limit-area ul li .wrapper .line {
height: 6px;
margin-top: 12px;
background-color: #ff6f69;
}
<div class="limit-area">
<ul>
<li>
<div class="wrapper">
<span>One line only</span>
<div class="line"></div>
</div>
</li>
<li>
<div class="wrapper">
<span>Bigger one line only </span>
<div class="line"></div>
</div>
</li>
<li>
<div class="wrapper">
<span>Long line and go crazyyyyyy</span>
<div class="line"></div>
</div>
</li>
</ul>
</div>
Full example on jsfiddle: https://jsfiddle.net/arnauth/55josw6e/
In the upper example, I can easily accomplish my goal on the first two list items.
The trick here is to have the same effect when I have a long line that break into two or more lines - that third line on the example.
The line element must have the same width of the text, so in the example must stop near the word 'go' - not in the end of the container as displayed.
The idea is try to approach the problem using only CSS rules avoiding javascript based code.
Thanks for your attention.
Try adding this inside of your span:
border-bottom: 6px solid #ff6f69;
so that it ends up looking like this:
span {
font-size: 24px;
color: #010101;
border-bottom: 6px solid #ff6f69;
}
it should come out like this
https://jsfiddle.net/55josw6e/3/
Hope this answers your question.

Need to put a border color when a menu link is :hover, but it has to be over an hr

I have designed a psd template for doing a website and I'm developing it with bootstrap, trying to make it responsive.
I want to obtain this effect:
http://pho.to/9RxrT (It's a link to a photo. StackOverflow doesn't allowed me to upload a photo.)
I managed to obtain it, but only for a few screen width, when I resize the screen it changes completally.
I have this CSS:
.menu {
width: auto;
font: 400 24px Calibri;
}
.vcenter {
padding: 5% 0 1%;
}
a:hover{
text-decoration:none;
color: #7d2828 !important;
border-bottom: 3px #7d2828 solid;
padding-bottom: 96px;
}
a,a:active,a.active,a:visited,a:link{
text-decoration:none;
color: #444443;
}
header hr {
height: 3px;
background-color: #a5a5a5;
}
And this block of my HTML document:
<header>
<div class="container">
<div class="row vcenter">
<div class="logo col-sm-2 col-md-3">
<img src="images/Logo.png" alt="Logotipo" class="img-responsive"/>
</div>
<div class="col-sm-offset-1 col-sm-9 col-md-offset-1 col-md-8 vcenter">
<ul class="menu text-uppercase list-inline pull-right">
<li class="pull-left">Inicio</li>
<li class="pull-left">Servicios</li>
<li class="pull-left">Sobre Nosotros</li>
<li class="pull-left">Blog</li>
<li class="pull-left">Contacto</li>
</ul>
</div>
</div>
<hr>
</div>
</header>
I found it out, that for a padding of 96px it fixs over the hr. But I dont know how to do it dinamically. I have tried to use #media queries, without success.
Thank you
The trick is that abuts the bottom of the list with <hr> element so for that you have to remove the border-bottom of the list and the border-top of hr and in your example you have to change the
.vcenter {
padding: 5% 0 1%;
}
by
.vcenter {
padding: 5% 0 0;
}
once adjoin the elements, you have to overlap the bottom of the list with the hr
doing this:
menu{
position: relative;
margin-bottom: -4px;
}
and now you have to make li and a elemtents get to the bottom of the list
li, a{
height: 100%
}
a{
display:inline-block; /*block works too, the catch is changes the `display:inline`
}
and here you have it, now you only have to put the desired size menu
like height: 96px
here you have a fiddle example with 2 menus at different size and both working
i remove some of your code to clarify
http://jsfiddle.net/Yandy_Viera/35ft5t4k/
Is this what you're looking for? You need to define a minimum width on the menu container to keep the menu items on the same line.
.menu {
width: auto;
font: 400 24px Calibri;
}
.vcenter {
padding: 5% 0 1%;
}
a:hover{
text-decoration:none;
color: #7d2828 !important;
border-bottom: 3px #7d2828 solid;
}
a,a:active,a.active,a:visited,a:link{
text-decoration:none;
color: #444443;
}
ul.menu {
min-width: 25em;
border-bottom: 3px #a5a5a5 solid;
}
ul.menu li {
display: inline-block;
margin-right: 1em;
}
<header>
<div class="container">
<div class="row vcenter">
<div class="logo col-sm-2 col-md-3">
<img src="images/Logo.png" alt="Logotipo" class="img-responsive"/>
</div>
<div class="col-sm-offset-1 col-sm-9 col-md-offset-1 col-md-8 vcenter">
<ul class="menu text-uppercase list-inline pull-right">
<li class="pull-left">Inicio</li>
<li class="pull-left">Servicios</li>
<li class="pull-left">Sobre Nosotros</li>
<li class="pull-left">Blog</li>
<li class="pull-left">Contacto</li>
</ul>
</div>
</div>
</div>
</header>

ListItem disc displaying at vertical bottom

I have a couple un-ordered lists on my page. Both lists use list-style: disc inside;. Each list's list-items have a couple div's inside them. The problem is that the list-item's content takes up multiple lines and the disc is appearing vertically, at the bottom of the multi-line list-item.
Here is a screenshot kind of showing the problem I am experiencing. Note that I stole the image from a similar question, it is not my HTML or CSS.
Here is a striped down version of my HTML:
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="billing_form">
<div id="purchase_items">
<h2>Your purchase</h2>
<h4>Items:</h4>
<div class="items">
<ul>
<li>
<div class="item">First Product - one year license</div>
<div class="price">$99.00 USD</div>
</li>
<li>
<div class="item">Second product & 3 year Product Plan</div>
<div class="price">$125.00 USD</div>
</li>
</ul>
</div>
<div class="subtotal">SUBTOTAL: $224.00 USD</div>
<h4>Discounts:</h4>
<div class="discount">
<ul>
<li>
<div class="item">A really long discount item name - with extra info on three lines!</div>
<div class="price">- $20.00 USD</div>
</li>
</ul>
</div>
<div class="total">TOTAL: $204.00 USD</div>
</div>
</div>
</body>
</html>
And here is the CSS, as small as I thought was relevant:
html
{
font-family: sans-serif;
}
#billing_form
{
width: 350px;
margin: 0 auto;
font-size: 14px;
background-color: #EEEEEE;
}
#billing_form .items
{
position:relative;
}
#billing_form .discount
{
position:relative;
color:#3665B0;
}
#billing_form ul
{
margin: 0;
padding: 0;
list-style: disc inside;
}
#billing_form .items .item,
#billing_form .discount .item
{
display: inline-block;
width: 190px;
}
#billing_form .price
{
float: right;
padding-left: 20px;
}
#billing_form .items,
#billing_form .discount,
#billing_form .subtotal,
#billing_form .total
{
width: 100%;
}
#billing_form .subtotal,
#billing_form .total
{
text-align: right;
margin-top: 5px;
border-top: 1px solid;
font-weight: bold;
}
#billing_form #purchase_items
{
margin: 10px 10px 10px;
}
I found a similar SO question. Unfortunately, the accepted (and only) answer to it states to try position: relative; and vertical-align: top; but it didn't work for me. I tried it with both #billing_form ul and #billing_form ul li and neither worked. They also mention a IE7 hack fix, but I don't think that is relevant to me because I am experiencing the problem in Firefox 3 & 4 and Google Chrome.
Does anyone know how I can make the list-item bullets (discs) appear at the top of each line item?
It looks like vertical-align: text-top; will do what you want (see spec). I believe the reason is that you are creating tall inline blocks that are aligning to the top of the box which is being pushed up by the tall inline box so aligning to top doesn't do what you want. However, I believe that using text-top will align it with the top of where the text is (and the bullet point).
http://jsfiddle.net/Yayuj/ is a fiddle that does what you want (I believe) and has primarily this updated section from your CSS:
#billing_form .discount .item
{
display: inline-block;
width: 190px;
vertical-align: text-top;
}
Any other differences to what you have pasted above should be cosmetic.