I want to have all of these on the same line, not multiple lines. However, when I try to do this, I end up with multiple lines. You can check out my fiddle here
I tried this for my css:
.left-img {
height: 34px;
width: 34px;
margin-right: 12px;
vertical-align: middle;
}
.right-img {
height: 34px;
width: 34px;
margin-right: 12px;
vertical-align: middle;
}
.container {
max-width: 300px;
}
.text {
text-overflow: ellipsis;
font-size: 18px;
}
<div class="container">
<img src="https://c1.staticflickr.com/7/6217/6357645479_b6d8c2d367_z.jpg" class="left-img" />
<span class="text">my Text that should wrap in elipses before the icon right?</span>
<img src="http://rlv.zcache.co.nz/zoom_up_of_cat_face_large_square_tile-r9ff2bcd4ac1d49e9b01fc97b9d0993c6_agtbm_8byvr_50.jpg" class="right-img">
</i>
</div>
but its not working.
I want to have the container at a fixed width. How can I accomplish all of this?
Using flexbox is great for this (produces better result than #dippas's answer):
Demo page
.left-img {
height: 34px;
width: 34px;
}
.right-img {
height: 34px;
width: 34px;
}
.container {
max-width: 300px;
display:flex; /* <--- add this */
align-items: center;
outline:1px dashed #CCC; /* can delete this */
}
.text {
font-size: 18px;
padding: 0 12px;
/* <--- add this */
text-overflow: ellipsis; /* <--- add this */
white-space: nowrap; /* <--- add this */
overflow: hidden; /* <--- add this */
}
<div class="container">
<img src="https://c1.staticflickr.com/7/6217/6357645479_b6d8c2d367_z.jpg" class="left-img" />
<span class="text">my Text that should wrap in elipses before the icon right?</span>
<img src="http://rlv.zcache.co.nz/zoom_up_of_cat_face_large_square_tile-r9ff2bcd4ac1d49e9b01fc97b9d0993c6_agtbm_8byvr_50.jpg" class="right-img" />
</div>
By the way, you could also give the clipped text element a title with the same text, when the mouse hovers it, the user could read the whole text.
you are missing a few properties to make ellipsis work, you need to add to .text:
white-space: nowrap
width: (some value)
display: (inline-)block , because this is span(inline element)
overflow: hidden
remove duplicated classes with same properties, merging them.
img {
height: 34px;
width: 34px;
margin-right: 12px;
vertical-align: middle;
}
.container {
max-width: 300px;
}
.text {
white-space: nowrap;
width: 100px;
display: inline-block;
vertical-align: middle;
overflow: hidden;
text-overflow: ellipsis;
font-size: 18px;
}
<div class="container">
<img src="https://c1.staticflickr.com/7/6217/6357645479_b6d8c2d367_z.jpg" class="left-img" />
<span class="text">my Text that should wrap in elipses before the icon right?</span>
<img src="http://rlv.zcache.co.nz/zoom_up_of_cat_face_large_square_tile-r9ff2bcd4ac1d49e9b01fc97b9d0993c6_agtbm_8byvr_50.jpg" class="right-img" />
</div>
If you don't want a fixed width in your span .text then you can use flexbox (as #vsync already answered)
img {
height: 34px;
width: 34px;
vertical-align: middle;
}
.container {
max-width: 300px;
display: flex;
border: red dotted
}
.text {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
margin: 0 12px;
font-size: 18px;
align-self: center
}
<div class="container">
<img src="https://c1.staticflickr.com/7/6217/6357645479_b6d8c2d367_z.jpg" class="left-img" />
<span class="text">my Text that should wrap in elipses before the icon right?</span>
<img src="http://rlv.zcache.co.nz/zoom_up_of_cat_face_large_square_tile-r9ff2bcd4ac1d49e9b01fc97b9d0993c6_agtbm_8byvr_50.jpg" class="right-img" />
</div>
Related
I've been messing with a bunch of code that refuses to center within my divs that are floated left and right. For my left one, a span and an image are stuck in the bottom left, while on the right, normal text is stuck on the top-right.
Here's what it currently looks like.
As for my code, here it is. If I can get help on what I could maybe do to fix it, I'd appreicate it.
HTML:
<div class="header">
<div class="allSelector">
<!-- <span (click)="showAll()"><img src={{imgSource}} /> {{expandContractStatement}}</span> -->
<img src={{imgSource}} (click)="showAll()"/><span (click)="showAll()" class="selectorInsides">{{expandContractStatement}}</span>
</div>
<div class="legend">
Incidents
Tasks
CRs
Problems
</div>
</div>
CSS:
.header {
background-color: gray;
color:black;
font-size: 24pt;
line-height: 24pt;
height: 6%;
max-height: 6%;
overflow: hidden;
vertical-align: middle;
}
.allSelector {
width: 50%;
max-height: 100%;
height: 100%;
float: left;}
.selectorInsides { /*Threw this in because of some issues before*/
overflow: hidden;
}
.allSelector > img {
height: 80%;
object-fit: contain;
}
.legend {
line-height: 24pt;
max-height: 100%;
height: 100%;
width: 50%;
float: right;
margin: 0;
text-align: right;
vertical-align: middle;
}
It's hard to tell if this answer is sufficient since a minimal, reproducible example wasn't provided, but you use Flexbox to vertically align elements.
/* Vertically align elements */
.header,
.allSelector,
.legend {
display: flex;
align-items: center;
}
.selectorInsides {
/* Adjust the spacing between image and text as needed */
margin-left: 8pt;
}
/* Vertically align elements */
.header,
.allSelector,
.legend {
display: flex;
align-items: center;
}
.header {
background-color: gray;
color: black;
font-size: 24pt;
line-height: 24pt;
height: 6%;
max-height: 6%;
overflow: hidden;
vertical-align: middle;
}
.allSelector {
width: 50%;
max-height: 100%;
height: 100%;
float: left;
}
.selectorInsides {
/*Threw this in because of some issues before*/
overflow: hidden;
/* Adjust the spacing between image and text as needed */
margin-left: 8pt;
}
.allSelector>img {
height: 80%;
object-fit: contain;
}
.legend {
line-height: 24pt;
max-height: 100%;
height: 100%;
width: 50%;
float: right;
margin: 0;
text-align: right;
vertical-align: middle;
}
<div class="header">
<div class="allSelector">
<!-- <span (click)="showAll()"><img src={{imgSource}} /> {{expandContractStatement}}</span> -->
<img src="https://via.placeholder.com/32" (click)="showAll()" /><span (click)="showAll()" class="selectorInsides">Expand All</span>
</div>
<div class="legend">
Incidents Tasks CRs Problems
</div>
</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/
I'm trying to display information for a plant right next to it and I want to force the information to stay right of the image of the plant as long as the screen has a specific min width.
Problem is: if the information contains a line that's longer than the normal width of 100% of leftover width-space in the parent div, the information div is shown below the image.
Example with good line length (no div wrap): https://jsfiddle.net/o3sjug9q/
Example with too much line length (div wrapped around): https://jsfiddle.net/seL72mt9/
How do I force the details div to wrap his text rather than wrapping itself to the next line?
<div class="outer">
<div class="slidecontainer row" id="biodivslider" data-id="1">
<div class="sliderbtn nowrap" onclick="bwdpic()"><</div>
<div class="wrap">
<div class="detailimg"><img src="http://www.nachhaltiger-weinbau.net/wp-content/plugins/biodivslider/img/Milchsterne/Dolden-Milchstern_Ornithogalum_umbellatum-Tci_2004.jpg" class="detailimg"></div>
<div class="details">
<p><span class="detailslabel">Name:</span><br>Milchsterne</p>
<p><span class="detailslabel">Lateinischer Name:</span><br>(Ornithogalum spec.), O. umbellatum, O. nutans</p>
<p><span class="detailslabel">Standort:</span><br>mäßig trocken, sandig, Wärmezeiger, mäßig stickstoffreich</p>
</div>
</div>
<div class="sliderbtn nowrap" onclick="fwdpic()">></div>
</div>
</div>
CSS:
div.outer {
width: 833px;
height: 491px;
background: lightblue;
}
div.slidecontainer {
max-height: 300px;
}
div.row {
display: table;
width: 100%;
table-layout: fixed;
border-spacing: 10px;
max-height: 300px;
}
div.row > div {
float: none;
display: table-cell;
height: 100%;
width: 100%;
}
div.row > div.wrap > div {
float: left;
}
#
div.detailimg {
height: 300px;
width: 300px;
}
img.detailimg {
display: block;
max-height: 300px;
max-width: 300px;
}
div.details {
max-width: 100%;
vertical-align: middle;
word-wrap: break-word;
overflow: visible;
}
span.detailslabel {
font-size: smaller;
font-weight: bold;
}
div.details > p {
line-height: 90%;
word-wrap: break-word;
overflow: visible;
}
div.sliderbtn {
font-size: 50px;
font-weight: 900;
min-height: 300px;
height: 100%;
width: 60px !important;
line-height: 300px;
text-decoration: none;
vertical-align: middle;
text-align: center;
cursor: pointer;
}
https://jsfiddle.net/tjepuh1L/
1.) erase overflow: visible; from div.details and from div.details > p
2.) Define the max-width of div.details as calc(100% - 300px)
change
div.details {
max-width: 100%;
vertical-align: middle;
word-wrap: break-word;
overflow: visible;
}
to
div.details {
max-width: 50%;
vertical-align: middle;
word-wrap: break-word;
overflow: visible;
}
if you use different sizes for your images change max-width in the CSS class of your images aswell to 50%
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;
}
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.