Here is my code:
.block {
width: 25%;
float: left;
}
<paper-material elevation="1">
<p>List of blocks:</p>
<div class="block">
<p>Block 1</p>
</div>
<div class="block">
<p>Block 2</p>
</div>
<div class="block">
<p>Block 3</p>
</div>
<div class="block">
<p>Block 4</p>
</div>
</paper-material>
Paper-material element contains only "List of blocks" label, all four divs are outside. How can I fix it so that the divs are inside the paper-material element?
Thank you.
Import iron-flex-layout and add #apply --layout-horiztonal; to your CSS, which currently amounts to
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-ms-flex-direction: row;
-webkit-flex-direction: row;
flex-direction: row;
You have to add div at the end of all .block divs and set style clear: both
inside style:
.block {
width: 25%;
float: left;
}
.clear {
clear: both;
}
and paper-material:
<paper-material elevation="1">
<p>List of blocks:</p>
<div class="block">
<p>Block 1</p>
</div>
<div class="block">
<p>Block 2</p>
</div>
<div class="block">
<p>Block 3</p>
</div>
<div class="block">
<p>Block 4</p>
</div>
<div class="clear"></div>
</paper-material>
but this is still not the best solution. Since your paper-material should have fixed width. At this moment it is better to use display: flex . Be aware that older IE doesn't support flex. So if you really want to support that 1% of people then you can continue using float:left.. but i still think using display: inline-block would be much more better.
Related
I'm learning web dev basics with HTML and CSS. I met an issue today : I want to make a horizontal scroll on my page with paragraphs (represented here by Lorem) inside but they appear in line while i want them in block.
Here's my code :
.scroll {
display: flex;
justify-content: flex-start;
flex-direction: row;
overflow-x: scroll;
overflow-y: hidden;
white-space: nowrap;
}
.part {
display: inline-block;
align-content: flex-start;
overflow-x: visible;
overflow-y: visible;
flex-wrap: wrap;
height: 200px;
width: auto;
}
<div class="scroll">
<div class="part">
<p>
Lorem...
</p>
</div>
<div class="part">
<p>
Lorem...
</p>
</div>
<div class="part">
<p>
Lorem...
</p>
</div>
</div>
I have been trying tons of things but unsuccessful... (I think the first part is good)
Thanks in advance
.scroll {
flex-direction: column;
}
add this style..this will change the content flow to column wise
Flexbox provided a property called flex-direction. Which means that what direction the flexbox children are laid out in and by default this is set to row. flex-direction
.parent {
display: flex;
}
<div class="parent">
<div class="child1">
<p>Hello I'm Child 1</p>
</div>
<div class="child2">
<p>Hello I'm Child 2</p>
</div>
<div class="child3">
<p>Hello I'm Child 3</p>
</div>
</div>
As you see that in above example div is a block level element but they appear as inline becuase flex-direction is set to row by default. Now change the direction from row to column that will put flexbox children in a column layout.
.parent {
display: flex;
flex-direction: column;
}
<div class="parent">
<div class="child1">
<p>Hello I'm Child 1</p>
</div>
<div class="child2">
<p>Hello I'm Child 2</p>
</div>
<div class="child3">
<p>Hello I'm Child 3</p>
</div>
</div>
Hope that you understand the concept of flex-direction.
I am new to flexbox and I have been trying to make a description list aligned in pairs stacked on top of each other like in a table.
I have tried some flexbox techniques but nothing is working
This is the markup
<div class="ad-overview">
<h3>Overview</h3>
<dl>
<dt>Mileage(KM)</dt>
<dd>4300</dd>
<dt>Condition</dt>
<dd>Locally used</dd>
<dt>Body Type</dt>
<dd>4 wheel drives & Suvs</dd>
<dt>Colour</dt>
<dd>Black</dd>
<dt>Fuel</dt>
<dd>Diesel</dd>
<dt>Transmission</dt>
<dd>Automatic</dd>
<dt>Duty Type</dt>
<dd>Paid</dd>
<dt>Interior</dt>
<dd>Leather</dd>
<dt>Engine size</dt>
<dd>2993</dd>
<dt>Year</dt>
<dd>2012</dd>
</dl>
</div>
This is my css
.ad-overview,
dl {
display: flex;
}
dl {
flex-wrap: wrap;
}
dt {
font-weight: bold;
}
dt+dd {
display: flex;
}
This is the layout style I am trying to achieve. Some help would be appreciated
There's many solutions to your problem, the simpliest one is by putting each pair of td and dd inside a block, and set that block as a flexbox with a flex-direction:column, and you will also have to add a wrap to make it look stacked, this is the main idea, then you will have to make some modifications on the code for the margin for example, the width of your blocks and so on, these are up to you, the following code will show you the solution:
.ad-overview,
dl {
display: flex;
flex-direction:row;
justify-content: space-between;
flex-wrap: wrap;
}
.col{
display:flex;
flex-direction:column;
text-align:left;
width: 30%;
margin-bottom: 3%;
}
dt {
font-weight: bold;
}
dd{
margin-left:0px;
width: 100%;
}
<div class="ad-overview">
<h3>Overview</h3>
<dl>
<div class="col">
<dt>Mileage(KM)</dt>
<dd>4300</dd>
</div>
<div class="col">
<dt>Condition</dt>
<dd>Locally used</dd>
</div>
<div class="col">
<dt>Body Type</dt>
<dd>4 wheel drives & Suvs</dd>
</div>
<div class="col">
<dt>Colour</dt>
<dd>Black</dd>
</div>
<div class="col">
<dt>Fuel</dt>
<dd>Diesel</dd>
</div>
<div class="col">
<dt>Transmission</dt>
<dd>Automatic</dd>
</div>
<div class="col">
<dt>Duty Type</dt>
<dd>Paid</dd>
</div>
<div class="col">
<dt>Interior</dt>
<dd>Leather</dd>
</div>
<div class="col">
<dt>Engine size</dt>
<dd>2993</dd>
</div>
<div class="col">
<dt>Year</dt>
<dd>2012</dd>
</div>
</dl>
</div>
I need elements inside a div to be outside of their div for different screen sizes.
I currently have the html repeated and am hiding it in certain viewports, this obviously isn't ideal but I'm not sure if there's another way to do it.
Here's the html desktop and tablet
<div class="container">
<div class="one">
<p>Content 1</p>
</div>
<p>Content 2</p>
</div>
Here's the html needed for mobile
<div class="container">
<p>Content 1</p>
<p>Content 2</p>
</div>
This is so I can use flexbox order on all the items within the container div
This is the perfect use case of display:contents; (https://caniuse.com/#feat=css-display-contents)
display: contents causes an element's children to appear as if they were direct children of the element's parent, ignoring the element itself. This can be useful when a wrapper element should be ignored when using CSS grid or similar layout techniques.
.container {
display:flex;
}
.one {
display:contents;
}
.one p:first-child {
order:2;
}
<div class="container">
<div class="one">
<p>Content 1</p>
<p>Content 3</p>
</div>
<p>Content 2</p>
</div>
You can try this(if you want):
<div class="container">
<div class="one d-none d-md-block">
<p>Content 1</p>
</div>
<p class="d-block d-md-none">Content 1</p>
<p>Content 2</p>
</div>
For CSS part:
.d-none {
display: none;
}
.d-md-none {
display: none;
}
.d-md-block {
display: block;
}
// Extra small devices (portrait phones, less than 576px)
#media (max-width: 575.98px) {
.d-none {
display: none;
}
.d-block {
display: block;
}
}
This method is actually came from Bootstrap. But if you don't want to use it you may try to add the code into your HTML and CSS.
I have the following
<div class="row">
<div class="col-md-6">
<div class = "box-cell">
<p>
Slightly short text
</p>
</div>
</div>
<div class="col-md-6">
<div class = "box-cell">
<p>
Text that<br>literally<br>spans<br>4 lines
</p>
</div>
</div>
</div>
and css
.box-cell
{
position: relative;
margin: 3px;
border-style: groove ridge ridge groove;
border-width: 3px;
background-size: cover;
}
So the problem that I am facing is that one of the cells is usually taller than the other.IS there any way for me to equalize how much height each cell takes up?
Searching didn't yield me which property I can manipulate to get same height :(
Here is jsfiddle
However in this fiddle I can not get them to be side by side to prove my point
EDIT: I guess I didn't specify it properly. I would like to have the borders be as tall as the tallest cell. So all the examples provided here actually take out the borders and instead color the background. If I do that then yes it gives illusion of every cell being the same, but I would like there to be a border of same height.
I tried replicating what it sounds like you are looking for.
I would recommend you mess around with flexbox since it seems to do exactly what you are looking for.
<div class="myc">
<div class="col">
<p>Text of some sorts</p>
<p>Text of some sorts</p>
<p>Text of some sorts</p>
<p>Text of some sorts</p>
</div>
<div class="col">
<p>Text of some sorts</p>
<p>Text of some sorts</p>
<p>Text of some sorts</p>
</div>
</div>
And for the CSS
.myc {
display: flex;
}
.col {
background-color: yellow;
margin-right: 20px;
}
.row {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
.row > [class*='col-'] {
display: flex;
flex-direction: column;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="row">
<div class="col-xs-12 col-sm-4" style="background-color: green">
some content
</div>
<div class="col-xs-6 col-sm-4" style="background-color: orange">
some content
<img src="http://placehold.it/100x120">
</div>
<div class="col-xs-6 col-sm-4" style="background-color: magenta">
some of content
</div>
</div>
Some options to solve it:
Different Tricks on How to Make Bootstrap Columns All the Same Height
<style type="text/css">
.box-cell{
position: relative;
margin: 3px;
border-style: groove ridge ridge groove;
border-width: 3px;
background-size: cover;
}
</style>
<div class="row">
<div class="col-md-6">
<div class = "box-cell">
<p>
Slightly short text
</p>
</div>
</div>
<div class="col-md-6">
<div class = "box-cell">
<p>
<span>Text that</span>
<span>literally</span>
<span>s4 lines</span>
<span>ygthfg</span>
</p>
</div>
</div>
</div>
1- you need to add text in span tag.
2- Or take text in one line .
In Safari 8.0.8 on Macbook.
I'm using flexbox to distribute elements in a grid-like container.
My .eventContainer is parent to multiple .event boxes which should be distributed across the rows by flexbox. It works fine in Firefox and Chrome but Safari displays the events on their own line, rather than next to each other!
<div class="eventContainer">
<div class="event">
<div class="thumb">
<img src="http://imgur.com/JDxjEknb.jpg">
</div>
<p class="thumbDate">Fri 18 Sept</p>
<p class="thumbArtist">Event 1</p>
<p class="thumbTitle">Subtitle 1</p>
<p class="thumbLocation">Location</p>
</div>
<div class="event">
<div class="thumb">
<img src="http://imgur.com/AwA5ga7b.jpg">
</div>
<p class="thumbDate">Sat 19 Sept</p>
<p class="thumbArtist">Event 2</p>
<p class="thumbTitle">Title 2</p>
<p class="thumbLocation">Subtitle 2</p>
</div>
<div class="event">
<div class="thumb">
<img src="http://imgur.com/9z5NkBxb.jpg">
</div>
<p class="thumbDate">Sat 19 Sept</p>
<p class="thumbArtist">Event 3</p>
<p class="thumbTitle">Title 3</p>
<p class="thumbLocation">Subtitle 3</p>
</div>
<!-- Fix for FlexBox -->
<div class="event"></div>
<div class="event"></div>
<div class="event"></div>
<div class="event"></div>
<div class="event"></div>
</div>
CSS:
.eventContainer {
display: -webkit-flex;
display: flex;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-justify-content: space-between;
justify-content: space-between;
}
.event {
display: inline-block;
margin-bottom: 35px;
width: 100%;
max-width: 200px;
margin-right: 15px;
cursor: pointer;
}
What have I missed here?
JSFiddle Example: http://jsfiddle.net/foepzgf8/1/
Can try it in both Chrome and Safari and see what I mean.
It's actually not justify-content in this situation. When you run into issues with flexbox, it's always good to go back and define flex-grow, flex-shrink, and flex-basis on the children of the flexbox container.
If you add this to .event your issue will be resolved:
-webkit-flex: 1 0 200px;
flex: 1 0 200px;
Updated fiddle: http://jsfiddle.net/foepzgf8/5/