How to horizontally stack elements using CSS?
Tags: html,css
Problem :
I want to create a custom audio player, with basically:
- a button for playing
- a flexible bar, i.e., that adapts itself to the player width
- a group of button at the right of the player, namely for the download button etc
For the two first parts I have no problem (see the fiddle), but it's for the second button group I have troubles.
I tried to put the group with float:right
, but in this case it is kicked out from the player. Then I tried to put the flexible
bar with a floating property, but in this case I have to specify its width and it becomes no more flexible.
Here is a sample image of what I want to achieve:
Here is what I have so far:
HTML:
<div class="player" style="width:500px">
<div class="group">
<a class="button" href="#"></a>
</div>
<div class="flexible">
<div class="bar"></div>
</div>
<div class="clear"></div>
</div>
CSS:
.player
{
height:24px;
background-color: #222222;
}
.player .group
{
float:left;
}
.player .group .button,
.player .group2 .button
{
display: inline-block;
width:24px;
height:24px;
background-color:#444444;
}
.player .group2
{
float:right;
}
.player .flexible
{
box-sizing:border-box;
overflow:hidden;
}
.player .flexible .bar
{
margin : 8px;
height : 8px;
background-color:#225599;
}
JSFiddle: https://jsfiddle.net/grh7sahq/3/
Do you have any advice ?
Thanks
Solution :
I understood you wanted the central part to be flexible. You can use display: flex. Really basic CSS to show it:
.player{
background: black;
height: 100px;
display: flex;
}
.button{
background: blue;
height: 100px;
width: 24px;
display: block;
}
.flexible{
flex: 1;
}
<div class="player" style="width:500px">
<div class="group">
<a class="button" href="#"></a>
</div>
<div class="flexible">
<div class="bar"></div>
</div>
<div class="group2">
<a class="button" href="#"></a>
</div>
</div>
<br/>
<div class="player" style="width:150px">
<div class="group">
<a class="button" href="#"></a>
</div>
<div class="flexible">
<div class="bar"></div>
</div>
<div class="group2">
<a class="button" href="#"></a>
</div>
</div>
CSS Howto..
This happens because of the 2px border. Can be solved by adding margin-right:-2px; to the triangle so as to move it right by 2px. .outer { padding: 20px; } .arrow_box...
Without using JavaScript and not having to support IE7 and below (IE8 fails on the second one) there are three options you can use: :first-child, :lastchild and the + selector:...
In addition to an HTML editor, if you just need something formatted quickly you can use this: http://www.freeformatter.com/html-formatter.html
Playing around in the fiddle, I found that : CSS needs to be applied before being positioned. The elements need to be rendered in the DOM when positioned (but not...
you can not do this directly; You should use an image for this, or svg might do the trick but that's a hell of a lot more complicated and browsers...
Your columns are actually lined up, the reason they "look" unaligned is because as standard Bootstrap columns come with a left & right padding of 15px. Which means when you...
Circles that scale based on size of content. This is something you will need to solve first, because you wont be able to place them anywhere without first knowing their...
The .dropdown-content is hidden by default: .dropdown-content { display: none; } The later rule overrides that and shows the content when the pointer hovers over the parent .dropdown: .dropdown:hover .dropdown-content...
@font-face is a CSS feature, and has no deal with Rails. It will loads the font the same way as loads image with url(path/to/image.jpg). font-family inside @font-face defines the name...
I have used qTip and the older version, Simpletip before and they work pretty well in all browsers (even IE6!). The documentation is really good and you can configure the...
First you will have to set the root element to height:100vh Then use :nth-child to set the height and the margin of each divs *{box-sizing: border-box} :root{width: 100vw; height: 100vh;...
The easiest way would be to restrict the container size. .container { width: 500px; /* look i'm now showing 5 images per line */ } .img { /* height: 100px;...
Can't understand what you problem is from the way you posted the question but here is a quick menu I put together that only uses CSS that functions like the...
You could use :after combined with absolute positioning. See: http://jsfiddle.net/thirtydot/ChJnr/4/ HTML: <div class="box"></div> CSS: .box { width: 250px; background: #ccc; position: relative; padding: 16px; } .box:after { content: ''; position:...
In the past I've done this by prepending to the content of each nested option. $spacer = ' '; while (list($id, $parent_id, $category) = mysqli_fetch_array($r, MYSQLI_NUM)) { $padding = str_repeat($spacer,...
In CSS, class selectors are always prefixed with .s. To apply the same set of rules on multiple selectors, separate the selectors with commas: .class1, .class2, .class3 { /*Making stuff...
var divElem = $("#yourdivid"); var ht = divElem.height(); var wdt = divElem.width(); $("#yourimageid").css({'height' : ht, 'width' : wdt}); ...
You cannot. alert() simply shows a native message box, so it'll look however the OS makes it look. In general, you shouldn't be using alert boxes because they are annoying...