Icon does not align well with text in Chrome - html

I'm trying to get the bottom of an icon to line up with some text (to the pixel - the lowest pixel of the first S should be at the same height as the lowest pixel of the foler icon) across browsers, but Chrome is always giving me different results.
Fiddle:
http://jsfiddle.net/LrhB7/1/
HTML:
<div class="study-box set-box">
<div class="set-box-title">
<i class="icon-folder-close-alt">
</i>
<div>SHOULD BE LINED UP WITH BOTTOM OF FOLDER</div>
</div>
</div>
CSS:
.study-box {
width: 200px;
height: 120px;
margin: 2px;
float: left;
color: white;
text-align: center;
font-size: 15px;
position: relative; }
.folder-box-title > div, .set-box-title > div {
-ms-text-overflow: ellipsis !important;
-o-text-overflow: ellipsis !important;
text-overflow: ellipsis !important;
white-space: nowrap;
overflow-x: hidden;
display: inline-block;
text-align: justify;
width: 162px !important;
padding-bottom: 0px;
margin-bottom: 0px;
line-height: 20px;
position: relative; }
.set-box-title {
position: absolute;
bottom: 0;
left: 0;
margin-left: 10px;
padding-bottom: 7px; }

This should be what you're looking for: http://jsfiddle.net/W3WW7/1/
<div class="study-box set-box">
<div class="set-box-title">
<i class="icon icon-folder-close-alt">
</i>
<div>SHOULD BE LINED UP WITH BOTTOM OF FOLDER</div>
</div>
</div>
Changed:
.folder-box-title > div, .set-box-title > div {
-ms-text-overflow: ellipsis !important;
-o-text-overflow: ellipsis !important;
text-overflow: ellipsis !important;
white-space:nowrap;
overflow-x:hidden;
display: inline-block;
text-align: justify;
width: 162px !important;
padding-bottom: 0px;
margin-bottom: 0px;
line-height: 20px;
position: relative;
top: 2px; // changed this line
}
Added:
.icon {
vertical-align: text-bottom;
}

Related

Active tab border bottom under the div instead in the div

I have made a tab wrapper with 2 tabs. Under the tabs I have a div with content.
This is my code:
.tab-wrapper {
width: auto;
padding-left: 17px;
background-color: aqua;
white-space: nowrap;
display: table-cell;
}
.content {
background-color: aqua;
}
.role-tab {
cursor: pointer;
display: inline-block;
height: 50px;
overflow: hidden;
text-align: center;
text-overflow: ellipsis;
vertical-align: middle;
margin-right: 19px;
}
.role-tab>p {
display: table-cell;
height: 50px;
overflow: visible;
vertical-align: middle;
width: 100%;
}
.role-tab-active {
border-bottom: 3px #108DE7 solid;
font-weight: bold;
}
<div class="tab-wrapper">
<div class="role-tab role-tab-active">
<p>Role tab 1</p>
</div>
<div class="role-tab">
<p>Role tab 2</p>
</div>
</div>
<div class="content">
<p>Content</p>
</div>
The styling and everything are working good. Now I want to add some padding-top so the border-bottom will go under the div. This is a screenshot what I want:
I want that the border-bottom goes under the div instead of in the div.
I have tried margin-top, padding-top and top, but it didn't work
How can I achieve when the tab is active that the border-bottom goes under the div instead inside it?
just set the margin-bttom: -3px; for the active class and its done :
.role-tab-active {
margin-bottom:-3px;
border-bottom: 3px #108DE7 solid;
font-weight: bold;
}
see below snippet :
.tab-wrapper {
width: auto;
padding-left: 17px;
background-color: aqua;
white-space: nowrap;
display: table-cell;
}
.content{
background-color: aqua;
}
.role-tab {
cursor: pointer;
display: inline-block;
height: 50px;
overflow: hidden;
text-align: center;
text-overflow: ellipsis;
vertical-align: middle;
margin-right: 19px;
margin-bottom:-3px;
}
.role-tab > p {
display: table-cell;
height: 50px;
overflow: visible;
vertical-align: middle;
width: 100%;
}
.role-tab-active {
margin-bottom:-3px;
border-bottom: 3px #108DE7 solid;
font-weight: bold;
}
<div class="tab-wrapper">
<div class="role-tab role-tab-active">
<p>Role tab 1</p>
</div>
<div class="role-tab">
<p>Role tab 2</p>
</div>
</div>
<div class="content">
<p>Content</p>
</div>
You can't move borders via padding and margin. It's not an element but part of the element.
Give the .tab-wrapper a static height instead of default auto. Whatever the size of your border, the containing div will adjust to it instead, so we give it a static height to allow overflow. And then make it display:flex.
.tab-wrapper {
width: auto;
padding-left: 17px;
background-color: aqua;
white-space: nowrap;
display: flex;
height: 50px;
}
You can see that both the parent and tab items are of 50px height, but that's not really the case when rendered. box-sizing: content-box being the default css property, your official active role tab height is 53px, thus, overflowing the div by 3px and giving the border an "under the div" effect
Fiddle: https://jsfiddle.net/c5u3wzv2/5/

CSS Property "overflow-y: auto" causing very unexpected results

The following code is part of a custom 404 page I am planning on using on a website of mine. However there is a major problem when I add the line of code overflow-y: auto;
The code below has the output which I expected it to. However when it the code inside the div reaches more than 75vh the overflow is not visible.
* {
margin: 0;
padding: 0;
}
.main {
min-height: 100vh;
font-size: 1em;
overflow-Y: hidden;
}
.center {
float: left;
position: relative;
left: 50%;
}
.wrap {
width: 100%;
float: left;
position: relative;
left: -50%;
}
.load_extra {
display: block;
position: fixed;
z-index: 11;
bottom: 15px;
}
.prep {
align: center;
background: #00eaff;
outline: none;
padding: 8px;
color: white;
border-color: white;
border-style: dotted;
border-width: 3px;
border-radius:50%;
font-size: 1.375em;
}
.extra {
display: block;
position: fixed;
bottom: 10px;
max-height: 75vh;
width: 80vw;
z-index: 10;
}
pre {
font-family: monospace, monospace;
font-size: 0.85em;
display: block;
overflow-y: auto;
word-break: break-all;
white-space:normal;
padding: 10px;
margin: 0 0 10px;
line-height: 1.42857143;
color: #333;
word-break: break-all;
word-wrap: break-word;
background-color: #f5f5f5;
border: 1px solid #ccc;
border-radius: 4px;
max-height: 50vh;
}
<body class="main">
<div class="center load_extra">
<div class="wrap">
<button id="extra" class="prep">Button</button>
</div>
</div>
<div id="infoCont" class="center extra">
<div class="wrap">
<h1>Extra Information</h1>
<pre>Some URL</pre>
<p>The requested URL shown above could not be found on the server</p>
<hr>
</div>
</div>
</body>
In order to fix this problem I added the line overflow-y: auto; in .extra class. This is what caused a problem. When you run the code below half of the output is "missing". I am unsure of why this is occuring.
* {
margin: 0;
padding: 0;
}
.main {
min-height: 100vh;
font-size: 1em;
overflow-Y: hidden;
}
.center {
float: left;
position: relative;
left: 50%;
}
.wrap {
width: 100%;
float: left;
position: relative;
left: -50%;
}
.load_extra {
display: block;
position: fixed;
z-index: 11;
bottom: 15px;
}
.prep {
align: center;
background: #00eaff;
outline: none;
padding: 8px;
color: white;
border-color: white;
border-style: dotted;
border-width: 3px;
border-radius:50%;
font-size: 1.375em;
}
.extra {
display: block;
position: fixed;
bottom: 10px;
max-height: 75vh;
width: 80vw;
z-index: 10;
overflow-y: auto;
}
pre {
font-family: monospace, monospace;
font-size: 0.85em;
display: block;
overflow-y: auto;
word-break: break-all;
white-space:normal;
padding: 10px;
margin: 0 0 10px;
line-height: 1.42857143;
color: #333;
word-break: break-all;
word-wrap: break-word;
background-color: #f5f5f5;
border: 1px solid #ccc;
border-radius: 4px;
max-height: 50vh;
}
<body class="main">
<div class="center load_extra">
<div class="wrap">
<button id="extra" class="prep">Button</button>
</div>
</div>
<div id="infoCont" class="center extra">
<div class="wrap">
<h1>Extra Information</h1>
<pre>Some URL</pre>
<p>The requested URL shown above could not be found on the server</p>
<hr>
</div>
</div>
</body>
I would appreciate any help in fixing this problem.
Half of the output goes "missing" due to the left positions defined in center and wrap classes.
center class will position your container starting from 50% and then, the inner container (wrap) gets repositioned again with -50%. Since the overflow is applied on the parent div, half of the content is no longer visible.
One solution might be to move overflow-y: auto; to wrap class.
Another is to choose another way to center infoCont div.
<div id="infoCont" class="extra">
<h1>Extra Information</h1>
<pre>Some URL</pre>
<p>The requested URL shown above could not be found on the server</p>
<hr>
</div>
.extra {
display: block;
position: fixed;
bottom: 10px;
max-height: 75vh;
width: 80vw;
z-index: 10;
overflow-y: auto;
margin: 0 auto; /* set margin to auto */
left: 0; /* set also left and right because position is fixed */
right: 0;
}
See working example.

Preserve Span when image is scaled

I have list of news items with image, title and date. I want to scale image which I'm able to but it hides the span which has title.
I fixed this issue for Firefox by using -moz-transform-style: preserve-3d; but in other browsers I'm not able to find CSS property which can work with other browsers like IE, Chrome, Safari etc.
.list-w li {
overflow:hidden;
display: block;
float: left;
margin-bottom: 20px;
margin-right: 15px;
width: 315px;
}
.list-w li img:hover {
border: 0 none;
float: left;
margin: 0;
width: 315px !important;
transform: scale(1.05);
z-index:10;
}
.title-span {
-moz-transform-style: preserve-3d;
z-index:100;
color: #000;
display: inline-block;
float: left;
font-size: 11px;
font-weight: bold;
height: 14px;
margin: -24px 0 0;
overflow: hidden;
padding: 5px;
text-align: left;
text-overflow: ellipsis;
white-space: nowrap;
width: 305px;
}
HTML
<div class="list-w">
<ul>
<li>
<a style="text-decoration:none; border:0; display:block;" href="/en/" id="hylTopFour2_0">
<img src=" http://placehold.it/350x150">
<span class="title-span">This is the title of the news</span>
</a>
</li>
</ul>
</div>
Just add position: relative to the .title-span class
Codepen demo
Note:
1) transform-style: preserve-3d; isn't necessary here and is not the issue
2) The real issue here is that the span element has a negative top margin and is being painted below the image.This is due to the rules of stacking regarding non-positioned elements (spec)
In this case it's because inline-level elements (the image here) are painted above non-inline-level elements (the span here)
(see my answer here for more details about that)
3) Setting position: relative on the span causes it to appear on top of the image, because positioned elements are painted above inline-level, non-positioned elements
.list-w li {
overflow: hidden;
display: block;
float: left;
margin-bottom: 20px;
margin-right: 15px;
width: 315px;
}
.list-w li img:hover {
border: 0 none;
float: left;
margin: 0;
width: 315px !important;
transform: scale(1.05);
z-index: 10;
}
.title-span {
-moz-transform-style: preserve-3d;
z-index: 100;
color: #000;
display: inline-block;
float: left;
font-size: 11px;
font-weight: bold;
height: 14px;
margin: -24px 0 0;
position: relative;
overflow: hidden;
padding: 5px;
text-align: left;
text-overflow: ellipsis;
white-space: nowrap;
width: 305px;
}
<div class="list-w">
<ul>
<li>
<a style="text-decoration:none; border:0; display:block;" href="/en/" id="hylTopFour2_0">
<img src=" http://placehold.it/350x150">
<span class="title-span">This is the title of the news</span>
</a>
</li>
</ul>
</div>

Resizing content in a div inside flex box pushes other content outside of box

As part of my HTML5/CSS3 app, I need to implement zoomable image popup. When the user clicks on a small image, a full-screen popup appears containing that image in the middle with a title above it and a button to close the popup below it. Clicking on the image then removes any scaling and puts it full-size inside a box in the middle to allow scrolling - with title and "close" button staying above and below.
I'm using flex (for several reasons, including vertical centering content). The overall popup works and looks fine. Clicking on the image does increase it in size, but it resizes the box so that the "done" button is pushed below the overall popup.
Here's the jsfiddle demonstrating the issue
I don't mind the fact that the box resizes - the more room to view/scroll the larger image - but I need to ensure that the button at the bottom stays put relative to the bottom edge of the popup.
My HTML looks like this (I used a random image for demonstration):
<div id="overlay" class="hidden">
<div id="alsg">
<div class="intro">Assist with ALS</div>
<div class="box scrollable">
<img src="http://upload.wikimedia.org/wikipedia/commons/8/8c/Male_monarch_butterfly.JPG" class="fit" />
</div>
<div class="popup-buttons">
<div id="button-alsg-done" class="button button-state-action button-green right">Done</div>
<div class="clear"></div>
</div>
</div> <!-- alsg -->
</div>
With the javascript being
$('img', '#alsg').on('click', function(e) {
$(this).toggleClass('fit');
});
There's a lot of CSS, unfortunately. You'll note that there's a pretty bad mix of flex and old-school positioning. This is because the app initially didn't use flex at all and I'm in a slow process of migrating/cleaning up now.
div#overlay {
position: absolute;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.7);
z-index: 104;
display: flex;
align-items: center;
justify-content: center;
}
div#overlay > div {
position: relative;
width: calc(100% - 40px);
margin: 10px auto;
background-color: #A9A9A9;
border-radius: 8px;
text-align: center;
padding: 10px;
display: flex;
flex-direction: column;
}
div#alsg {
max-height: calc(100% - 40px) !important;
}
div#overlay div.intro {
color: #FFF !important;
font-size: 12pt;
margin-bottom: 10px;
}
div#overlay div.box, div.template div.box {
padding: 3px 5px;
overflow: hidden;
font-weight: bold;
position: relative;
flex-grow: 1;
}
div#alsg div.box {
text-align: center;
position: relative;
overflow: auto !important;
margin: 10px 0px 0px !important;
}
div.box {
background-color: #FFF;
color: #27374A;
border-radius: 8px;
border: 3px solid #FBE96E;
position: relative;
margin: auto;
flex-shrink: 1;
}
.fit {
max-width: calc(100% - 4px) !important;
max-height: calc(100% - 4px) !important;
}
div.popup-buttons {
margin-top: 10px;
}
#overlay .button.right {
margin-left: 10px;
}
#button-alsg-done {
margin-top: 10px;
flex-basis: 25px;
}
div.button-green {
background-color: #2CC55D;
color: #FFF;
font-weight: bold;
}
div.button-state-action {
height: 25px;
padding: 0px 5px;
line-height: 25px;
text-align: center;
border-radius: 4px;
font-size: 10pt;
font-weight: normal !important;
width: 60px;
cursor: pointer;
margin-bottom: 5px;
}
div.button {
height: 22px;
padding: 0px 2px;
line-height: 22px;
text-align: center;
border-radius: 4px;
font-size: 9pt;
width: 42px;
cursor: pointer;
white-space: nowrap;
overflow: hidden;
}
.right {
float: right;
}
.clear {
clear: both;
}

CSS getting text in one line rather than two

I have a small issue with a title where I would like text to display on a single line rather than split onto two as im trying to arrange these blocks as a grid
jsFiddle
html
<div class="garage-row">
<a class="garage-row-title" href="/board/garage_vehicle.php?mode=view_vehicle&VID=4">
<div class="garage-title">1996 Land Rover Defender</div>
<div class="garage-image"><img src="http://enthst.com/board/garage/upload/garage_vehicle-4-1373916262.jpg"></div>
</a>
<div class="user-meta">
<b>
Hobbs92
</b>
</div>
</div>
css
#import url(http://fonts.googleapis.com/css?family=Open+Sans);
.garage-row {
border: 1px solid #FFFFFF;
float: left;
margin-right: 5px;
padding: 12px;
position: relative;
width: 204px;
}
.garage-row img{}
.garage-image {
background-position: center center;
display: block;
float: left;
max-height: 150px;
max-width: 204px;
overflow: hidden;
position: relative;
}
.user-meta {
background: none repeat scroll 0 0 #2C3539;
color: #FFFFFF;
float: left;
padding: 10px;
position: relative;
width: 184px;
}
img {
border-width: 0;
height: auto;
max-width: 100%;
vertical-align: middle;
}
.garage-title {
clear: both;
display: inline-block;
overflow: hidden;
}
.garage-row-title {
font-size: 22px;
font-weight: bold;
}
a:link {
color: #43A6DF;
}
font-family: 'Open Sans',sans-serif;
I would greatly appreciate if someone were able to help me get the title into one line rather than two or even fix it so if the title exceeds the width then it gets ellipses.
Add white-space: nowrap;:
.garage-title {
clear: both;
display: inline-block;
overflow: hidden;
white-space: nowrap;
}
jsFiddle
The best way to use is white-space: nowrap; This will align the text to one line.