I would like to have a one-line "row" that contains 2 "columns". The first "column" should be fluid and cut off overflowing text.
The example below is perfectly working in webkit browsers (Chromium, Safari), but not in Firefox or Opera.
Does anyone know a solution that works in all browsers?
http://jsfiddle.net/fluidblue/YV3s9/
HTML:
<div class="header">
<div class="clickable">
<div class="description">
Some very very very very very very very very very very long description
</div>
</div>
<div class="buttons">
Link1
Link2
</div>
</div>
<div class="content">
Text below
</div>
CSS:
*
{
margin:0;
padding:0;
}
.header
{
background-color: gray;
display: table;
width: 100%;
}
.clickable
{
background-color: green;
display: table-cell;
width: 100%;
position: relative;
cursor: pointer;
}
.description
{
width: 100%;
position: absolute;
top:0;
left:0;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.buttons
{
background-color: red;
display: table-cell;
white-space: nowrap;
}
Edit: Added top, left as suggested by web2008
Try removing position: absolute given for description or else if you wnat it then set the left and top values.
Tried another approach: flex-box. This is working in Firefox, Chromium, Safari, but not in Opera (overflow: hidden is ignored..)
http://jsfiddle.net/JH5fQ/
HTML:
<div class="flex-container flex-container-style">
<div class="flex-item">
Text Text Text Text Text Text Text Text Text Text Text Text Text
</div>
<div class="flex-item">
Button Button
</div>
</div>
CSS:
.flex-container {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-direction: normal;
-moz-box-direction: normal;
-webkit-box-orient: horizontal;
-moz-box-orient: horizontal;
-webkit-flex-direction: row;
-ms-flex-direction: row;
flex-direction: row;
-webkit-flex-wrap: nowrap;
-ms-flex-wrap: nowrap;
flex-wrap: nowrap;
-webkit-box-pack: start;
-moz-box-pack: start;
-webkit-justify-content: flex-start;
-ms-flex-pack: start;
justify-content: flex-start;
-webkit-align-content: stretch;
-ms-flex-line-pack: stretch;
align-content: stretch;
-webkit-box-align: start;
-moz-box-align: start;
-webkit-align-items: flex-start;
-ms-flex-align: start;
align-items: flex-start;
}
.flex-item
{
white-space: nowrap;
}
.flex-item:nth-child(1)
{
overflow: hidden;
text-overflow: ellipsis;
background-color: red;
-webkit-box-ordinal-group: 1;
-moz-box-ordinal-group: 1;
-webkit-order: 0;
-ms-flex-order: 0;
order: 0;
-webkit-box-flex: 1;
-moz-box-flex: 1;
-webkit-flex: 1 1 auto;
-ms-flex: 1 1 auto;
flex: 1 1 auto;
-webkit-align-self: auto;
-ms-flex-item-align: auto;
align-self: auto;
}
.flex-item:nth-child(2)
{
background-color: green;
-webkit-box-ordinal-group: 1;
-moz-box-ordinal-group: 1;
-webkit-order: 0;
-ms-flex-order: 0;
order: 0;
-webkit-box-flex: 0;
-moz-box-flex: 0;
-webkit-flex: 0 0 auto;
-ms-flex: 0 0 auto;
flex: 0 0 auto;
-webkit-align-self: auto;
-ms-flex-item-align: auto;
align-self: auto;
}
/* Legacy Firefox implementation treats all flex containers as inline-block elements. */
#-moz-document url-prefix()
{
.flex-container
{
width: 100%;
-moz-box-sizing: border-box;
}
}
Found a solution working in Firefox, Chromium, Safari and Opera (IE untested):
http://jsfiddle.net/zKtU3/
HTML:
<div class="header">
<div class="clickable">
<div class="posrel">
<div class="description">
Some very very very very very very very very very very long description
</div>
</div>
</div>
<div class="buttons">
<div>Button1</div><div>Button2</div>
</div>
</div>
<div>
Text below
</div>
CSS:
.header
{
display: table;
width: 100%;
height: 50px;
}
.clickable
{
display: table-cell;
width: 100%;
}
.posrel
{
position: relative;
/* Vertically centering the text */
line-height: 50px;
}
.description
{
width: 100%;
position: absolute;
top: 0;
left: 0;
/* Cut text */
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.buttons
{
display: table-cell;
vertical-align: middle;
/* Prevent wrapping of multiple buttons */
white-space: nowrap;
}
.buttons div
{
display: inline-block;
}
The additional div with the class posrel is needed, because firefox has got a bug when setting position: relative on table-cells: Does Firefox support position: relative on table elements?
Related
I have the following CSS and HTML as the minimal to reproduce the issue. On Chrome all good. IE11 not. Is there a way to fix the CSS and HTML so it works on both Chrome and IE11?
<html>
<style>
.max-box {
background-color: #00e;
width: 100px;
max-height: 80%;
padding: 5px;
display: flex;
flex: 1 1 auto;
}
.fixed-box {
background-color: #00e;
width: 100px;
height: 100px;
padding: 5px;
display: flex;
flex: 1 1 auto;
}
.wrapper {
display: flex;
flex: 1 1 auto;
flex-direction: column;
}
.content {
background-color: #0e0;
display: flex;
flex: 1 1 auto;
flex-direction: column;
overflow: auto;
}
.footer {
background-color: #e00;
display: flex;
flex: 0 0 auto;
}
</style>
<body>
<div class="max-box" style="float: left">
<div class="wrapper">
<div class="content">
<span>a1</span><span>a2</span>
</div>
<div class="footer">
<span>b1</span><span>b2</span>
</div>
</div>
</div>
<div class="max-box" style="float: left">
<div class="wrapper">
<div class="content">
<span>a1</span><span>a2</span><span>a3</span><span>a4</span><span>a5</span><span>a6</span><span>a7</span><span>a8</span><span>a9</span>
</div>
<div class="footer">
<span>b1</span><span>b2</span>
</div>
</div>
</div>
<div class="fixed-box">
<div class="wrapper">
<div class="content">
<span>a1</span><span>a2</span><span>a3</span><span>a4</span><span>a5</span><span>a6</span><span>a7</span><span>a8</span><span>a9</span>
</div>
<div class="footer">
<span>b1</span><span>b2</span>
</div>
</div>
</div>
</body>
</html>
So the requirements are what Chrome is behaving:
Box 1 will not take up the space below if the content is little.
Box 2 will take up at most 80% height of the browser and the content is scrollable. Responsive if the browser height changes.
Box 3 is fixed height and the content is scrollable and spaced the same as box 2.
What IE11 failed are:
Box 1 and Box 2 does not make content scrollable when browser height changed to smaller than the content.
Box 3 content is scrollable but the values all cramped.
as this seems to be unanswered I will try to give you my two cents. IE and other browsers usually need autoprefixer for flexbox to work properly. Try the following, which is exactly your code run trough autoprefixer
.max-box {
background-color: #00e;
width: 100px;
max-height: 80%;
padding: 5px;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-flex: 1;
-ms-flex: 1 1 auto;
flex: 1 1 auto;
}
.fixed-box {
background-color: #00e;
width: 100px;
height: 100px;
padding: 5px;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-flex: 1;
-ms-flex: 1 1 auto;
flex: 1 1 auto;
}
.wrapper {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-flex: 1;
-ms-flex: 1 1 auto;
flex: 1 1 auto;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
}
.content {
background-color: #0e0;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-flex: 1;
-ms-flex: 1 1 auto;
flex: 1 1 auto;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
overflow: auto;
}
.footer {
background-color: #e00;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-flex: 0;
-ms-flex: 0 0 auto;
flex: 0 0 auto;
}
I will extract the style later. I want to learn how to do this with straight up HTML.
Notice that as long as my checkbox is the default size, all contents inside of my wrap1 div vertical-align in the middle.
If I change the size of the checkbox then the vertical-align appears to stop working. Here is my JSFiddle.
<div id="wrapper" style="width: 80%; height: 100%; overflow:hidden; margin: 0 auto; float: left">
<div class="row" style="width: 100%; height: 80%; margin: 0 0 0 0; float: left; background-color: aqua;">
<div id="heading" class="row">
<p style="text-align: center;">This is a title</p>
</div>
<div class="wrap1" style="vertical-align: middle;">
<div style="width: 15%; line-height: 53px; text-align: center; background-color: yellow; display: inline-block;">
<input type="checkbox" style="height: 30px; width: 30px;">
</div><div style="width: 70%; line-height: 53px; background-color: orange; display: inline-block;"><label>Description</label>
</div><div style="width: 15%; line-height: 53px; text-align: center; background-color:green; display: inline-block;">
<label>100</label>
</div>
</div>
</div>
</div>
Best approach is to use CSS flexbox to be honest as it will auto justify and align center and vertical:
<style type="text/css">
.main__container {
position: relative;
width: 500px;
height: auto;
}
.main__container .content__list {
position: relative;
list-style: none;
width: 100%;
height: auto;
}
.main__container .content__list .content__col {
position: relative;
height: 60px;
}
.flex-grid {
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: -moz-box;
flex-wrap: wrap;
}
.flex-row {
-webkit-box-direction: normal;
-moz-box-direction: normal;
-webkit-box-orient: horizontal;
-moz-box-orient: horizontal;
-webkit-flex-direction: row;
-ms-flex-direction: row;
flex-direction: row;
}
.flex-column {
flex-flow: column;
}
.flex-wrap {
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}
.flex-nowrap {
-webkit-flex-wrap: nowrap;
-ms-flex-wrap: nowrap;
flex-wrap: nowrap;
}
.flex-cell {
flex: 1;
}
.flex-20 {
-webkit-box-flex: 1;
-moz-box-flex: 1;
-webkit-flex: 1 1 20%;
-ms-flex: 1 1 20%;
flex: 1 1 20%;
}
.flex-60 {
-webkit-box-flex: 1;
-moz-box-flex: 1;
-webkit-flex: 1 1 60%;
-ms-flex: 1 1 60%;
flex: 1 1 60%;
}
.flex-100 {
-webkit-box-flex: 1;
-moz-box-flex: 1;
-webkit-flex: 1 1 100%;
-ms-flex: 1 1 100%;
flex: 1 1 100%;
}
.grid-center {
justify-content: center;
align-items: center;
}
</style>
<main class="main__container flex-grid flex-row flex-wrap grid-center ">
<header class="title__container flex-cell flex-100">
{{--Nav HTML here --}}
</header>
<ul class="content__list flex-grid flex-nowrap flex-column grid-center">
<li class="content__col flex-20 one">
<input type="checkbox" style="height: 30px; width: 30px;">
</li>
<li class="content__col flex-60 two"></li>
<li class="content__col flex-20 there"></li>
</ul>
</main>
You can try a couple of things here: if you want to align your checkbox vertically, you could try styling your checkbox like this:
vertical-align: inherit;
This will give your checkbox the same vertical alignment property of the parent element, and should fix your issue. However, if that option doesn't work, try playing around with the vertical-align: length property. This allows you to adjust alignment via px values, and can take a positive or negative number. This may not be your needed value, but for example:
vertical-align: -10px;
I am using flex for making a searchbar/input element stay centered and change width as the screen size changes.
This is my html:
<div class="flex-container">
<div class="flex-row">
<h1 class="brandname">Hello</h1>
</div>
<div class="flex-row">
<form>
<!-- <div class="search centered"> -->
<div class="search">
<div class="input-container">
<input type="text" name="query" class="searchbar" />
<button type="submit" class="search-button">Search</button>
</div>
</div>
</form>
</div>
</div>
and this is my css:
#import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');
.flex-container{
display: flex;
display: -webkit-flex;
align-items: center;
-webkit-align-items: center;
justify-content: center;
-webkit-justify-content: center;
-webkit-flex-direction: row;
flex-direction: row;
flex-wrap: wrap;
-webkit-flex-wrap: wrap;
}
.flex-row {
display: flex;
display: -webkit-flex;
justify-content: center;
-webkit-justify-content: center;
flex: 1;
-webkit-flex: 1;
}
form{
display: flex;
display: -webkit-flex;
justify-content: center;
-webkit-justify-content: center;
flex: 1;
-webkit-flex: 1;
}
.search{
display: flex;
display: -webkit-flex;
flex: 0 1 455px;
-webkit-flex: 0 1 455px;
}
.input-container{
display: flex;
display: -webkit-flex;
flex: 1;
-webkit-flex: 1;
min-width: 0;
}
.searchbar{
flex: 1;
-webkit-flex: 1;
min-width: 0;
}
.flex-container > .flex-row:first-child{
flex: 0 1 100%;
-webkit-flex: 0 1 100%;
}
.brandname {
position: relative;
font-size: 500%;
font-family: 'Lato', sans-serif;
color: #1f0e3e;
text-align: center;
margin-bottom: 30px;
margin-top: 5%;
}
body {
margin: 10px;
}
.input-container{
/*float: left;*/
/*display: block;*/
flex: 1;
-webkit-flex: 1;
outline-style: solid;
outline-color: #e3e3e3;
outline-width: 1px;
}
.searchbar{
margin-left: 5px;
}
.search button {
background-color: rgba(152,111,165,0.38);
background-repeat:no-repeat;
border: none;
cursor:pointer;
border-radius: 0px;
/*overflow: hidden;*/
outline-width: 1px;
outline-style: solid;
outline-color: #e3e3e3;
color: white;
}
.search input{
outline-width: 0px;
outline-style: none;
border-width: 0px;
}
and it works in chrome, ie edge and in this fiddle, but not in safari.
In Safari the searchbar goes above the .brandname element and to the right of it and takes a width of 150px.
any ideas on how to make this work in safari?
One thing that is not working is the the first flex row width of 100% is not working. In safari it is making the two felx-row elements be right next to each other and both of them together are taking 100% of the width.
I changed .flex-row css rules to:
.flex-row {
display: flex;
display: -webkit-flex;
justify-content: center;
-webkit-justify-content: center;
flex: 1;
-webkit-flex: 0 1 100%;
}
and changed the flex-row first child css rules to:
.flex-container > .flex-row:first-child{
flex: 0 1 100%;
-webkit-flex: 0 1 auto;
}
and then it works.
I thought about doing this after reading that flex-wrap is buggy in safari from this SO question which suggests that setting flex-wrap in safari is buggy
Always use the non-prefixed setting last in your CSS rules. In your first rule that would be:
.flex-container{
display: -webkit-flex;
display: flex;
-webkit-align-items: center;
align-items: center;
-webkit-justify-content: center;
justify-content: center;
-webkit-flex-direction: row;
flex-direction: row;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
}
similar for all other rules.
I got a situation where flex box is not working the way I want it to within Chrome but it works in other browsers (apart from iOS mobile devices).
I am struggling to vertically align any content within Chrome but works in everything else. Any ideas?
Also, does anyone know a way I can dynamically stretch a div to a certain % of the div class content which will also work within chrome?
Thanks in advance. See the bottom for demo and screenshots.
HTML
<div class="container">
<div class="content">
<h2>Ticket System <span style="color:#339933; font-weight:bold;">Open</span> Customer Ticket List</h2>
<a class="BlueButton" href="ticket_view_cust_ticket.php">Open Customer Tickets</a>
<a class="BlueButton" href="ticket_view_cust_ticket_rejected.php">Rejected Customer Tickets</a>
<div class="centerContent">
There are currently no open customer tickets
</div>
</div>
</div>
CSS
html,body
{
height: 100vh;
}
body
{
display: table;
margin: 0 auto;
font-family: Tahoma,Arial,Sans-Serif;
}
.container
{
height: 98vh;
vertical-align: middle;
width: 70vw;
min-width:1024px;
margin-left:auto;
margin-right:auto;
margin-top: 1vh;
display: flex;
flex-direction: column;
}
.content
{
background-color: #ff0000;
flex: auto;
webkit-flex-direction: column;
-moz-flex-direction: column;
-ms-flex-direction: column;
-o-flex-direction: column;
flex-direction: column;
webkit-flex-shrink: 0;
-moz-flex-shrink: 0;
-ms-flex-shrink: 0;
-o-flex-shrink: 0;
flex-shrink: 0;
text-align: center;
font-size: 12px;
padding-top:20px;
min-height:600px;
}
.centerContent
{
height: 95%;
padding: 0;
margin: 0;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
align-items: center;
justify-content: center;
}
Demo - https://jsfiddle.net/qr2tpgo6/1/
Container Screenshot - http://prntscr.com/azp8bk
Firefox - http://prntscr.com/azp4oj
Chrome - http://prntscr.com/azp4hy
Your container is missing display: flex, so flex properties aren't working.
Add this:
.content
{
background-color: #ff0000;
flex: auto;
flex-direction: column;
flex-shrink: 0;
text-align: center;
font-size: 12px;
padding-top:20px;
min-height:600px;
display: flex; /* new; establish flex container */
justify-content: center; /* new; center children vertically */
}
Revised Fiddle
I have a problem in chrome which does not happen in Firefox.
<div class="container">
<div class="flex-1"></div>
<div class="flex-2">
<div class="flex-2-child"></div>
<div class="flex-3-child"></div>
</div>
</div>
.container {
height: 200px;
width: 500px;
display: -moz-box;
display: -webkit-flexbox;
display: -ms-flexbox;
display: -webkit-flex;
display: -moz-flex;
display: flex;
-webkit-flex-direction: row;
-moz-flex-direction: row;
-ms-flex-direction: row;
flex-direction: row;
}
.flex-1 {
width: 100px;
background-color: blue;
}
.flex-2 {
position: relative;
-moz-box-flex: 1;
-webkit-flex: 1;
-moz-flex: 1;
-ms-flex: 1;
flex: 1;
background-color: red;
}
.flex-2-child {
height: 100%;
width: 100%;
background-color: green;
}
.flex-3-child {
height: 100%;
width: 100%;
background-color: steelblue;
}
http://jsfiddle.net/michaelch/TfB9c/2/
If you check this fiddle in firefox and in chrome, you will see there is a big difference.
flex-2-child and flex-3-child have no height in chrome, but have the behavior which i think is right which both have a 100% height relative to their parent.
Do you know how to have the correct behavior in chrome?
Thanks in advance.
Michael
You will get the same result in Chrome as you do in Firefox if you add height: 100%; to your .flex-2 class.
.flex-2 {
position: relative;
-moz-box-flex: 1;
-webkit-flex: 1;
-moz-flex: 1;
-ms-flex: 1;
flex: 1;
background-color: red;
height: 100%; // Add this!
}
If a child's height is defined by a percentage of their parent's height, then the parent's height should be defined.