H1 on the left, "buttons" on the right, vertically aligned - css-float

I'm trying to display on one line:
a H1 element aligned to the left of the containing box
several "buttons" (A elements here) aligned to the right of the containing box
all being on the same baseline
Is it possible to do this with minimal markup (i.e. no wrapping elements) and without having to set precise heights, line-heights, margin-tops, etc.
<div id="block1">
<h1>What a great title</h1>
This link can kill you
Click if you dare
</div>
The fiddle here shows what I feel are two incompatible directions (inline-blocks and you can't align to the right vs. float right and you can't align vertically):
http://jsfiddle.net/GlauberRocha/bUsvX/
Any idea?

I did this to my site a quite ago: a h2 on the left, and a button on the right. Screen shot:
Code:
<div id="side_bar" class="clearfix">
<h2 style="float: left;">Charity Map</h2>
<button class="btn btn-primary" style="float: right; position: relative; top: 10px; right: 10px;">Submit</button>
</div>

You have a potential problem with that layout - what if your H1 is too long and so are the buttons? They will run in to each other. Because of this, no simple CSS will do - CSS doesn't do magic like that - it would have to imply some sort of solution to the above problem.
However, what you want can simply be accomplished using absolute positioning:
<div style="position: relative;">
<h1 style="position: absolute; left: 0; top: 0">What a great title</h1>
<div style="position: absolute; right: 0; top: 0; text-align: right">
This link can kill you
Click if you dare
</div>
</div>
If you are really afraid that the header and the anchor container might run in to each other depending on generated content, you can use CSS max-width and overflow properties to restrict their containing boxes to some sensible values. The overflowing content will be hidden but at least the layout will not break visually. I assume the following modification of the above code (pardon the duplicate) would serve the purpose:
<div style="position: relative;">
<h1 style="position: absolute; left: 0; top: 0; max-width: 50%; overflow: hidden">What a great title</h1>
<div style="position: absolute; right: 0; top: 0; text-align: right; max-width: 50%; overflow: hidden">
This link can kill you
Click if you dare
</div>
</div>
To round off, you cannot achieve this using a straightforward CSS property combination, because with CSS (and HTML), content flows from left to right and top to bottom, or it becomes absolutely- or fixed- positioned which interrupts the flow. Anyhow, it does not want to remain on the same line, and you as the layout designer are left with resolving ambiguities such layout would introduce, such as what to do when the two trains running from each direction front-collide with each other :-)

It's hard to achieve without any wrapping elements or fixed values...
Adding a fixed line-height to both the Heading and the Links would solve your problem rather quick.
Align your Links with 'display:block; float:right' to the right.
Now Set "line-height: 40px;" to both the heading and the links
Should work, but only when the size of the heading doesn't change....

One potential approach to this, depending on your exact needs, is to use a table layout:
#block3 {
display: table;
width: 100%;
box-sizing: border-box;
}
#block3 > * {
display: table-cell;
}
#block3 > *:last-child {
text-align: right;
}
JSFiddle: http://jsfiddle.net/bUsvX/39/
If you want the buttons strictly aligned right, I think this solution requires another element to wrap them:
JSFiddle: http://jsfiddle.net/bUsvX/40/

I had the same issue.. Add display:inline to the h1, then for buttons: float:right; display:inline;
example (with use of Twitter Bootstrap):
<h2 style="display:inline">Users</h2>
<i class="icon-download-alt"></i>XLS
<form style="display:inline; float:right;">
<input type="text" class="input-medium search-query" name="search">
<button class="btn" type="submit">Search</button>
</form>

Related

CSS for full-width button for Modal Pop-up

I want to make the green button at the bottom of the nav area on this page full width (across the whole page, with the text centered).
I've tried adding width:100% to 3 of the divs which I though were relevant, but no joy. I've also tried quite a few other tricks. I can only use css as the whole modal poop-up is handled by a WordPress plugin which I don't want to tamper with.
Any help much appreciated.
Try to move your element <div class="banner-button"> out of the current hierarchy and place after element <div class="col-md-8 desktop-only" in side element <div class="row">
since it is inside nav nothing works with width
if you want to work with same hierarchy please use css : position properties
Do you want something like that
If yes then you have to made some changes into your html like
<nav >
<ul>
<div class="banner-button">
<div class="md-trigger md-setperspective btn-bg-2160 btn btn-lg text-center">
Css must be
.md-trigger.md-setperspective.btn-bg-2160.btn.btn-lg.text-center {
width: 100%;
}
.banner-button {
display: block;
position: fixed;
left: 0px;
width: 100%;
z-index: 91;
text-align: center;
top: 72px;
}
Best way to do this take out your button from <div class="col-md-8 desktop-only"> then add <div class="col-md-12"> and wrap your button inside this.

Center a form for all devices: bootstrap/css

I centered my form for laptop, with this .css code:
form{
position: absolute;
top: 40%;
left: 20%;
}
And here is the result:
this
But now, when I whatch it on my smartphone, I get this:
this
Which is not centered.
How would you center a form for every devices in Bootstrap/CSS ?
Add this class next to the row class: "justify-content-center". And delete "left: 20%" Like this:
<div class="container">
<form>
<div class="row justify-content-center">
<input type="text">
<input type="text">
<input type="text">
</div>
</form>
</div>
However, it won't success with absolute position. You may change that with relative position. Or check these: How to center absolutely positioned element in div? or How to center a "position: absolute" element
Add (left and right) margin: auto.
form{
margin: auto;
}
If you need top/bottom margin, set it like margin: 5px auto
This will center the form using your current setup:
form {
position: absolute;
top: 40%;
left: 0;
right: 0;
margin: auto;
}
But I would personally go with Atreidex's solution using existing Bootstrap classes (well, I personally wouldn't use Bootstrap, but if I already were using it, I would make use of its available classes rather than re-inventing the wheel - isn't that why you're using Bootstrap?).

Responsive site html/css

I have started to try to build a really easy website and trying to make it responsive. Something in the style of http://www.squarespace.com/ (Split up in different sections with different backgrounds etc that you just scroll throu) But i have a problem that I really cant figure out right now, I don't know how to make the foundation for this kind of site. I got the "menu" part quite nice, but as soon as I try to but some content on the first "part" or try to start the second part I run into trouble.
To try to explain I have two < p > that I tried to put on-top of the first part, and below to make the second part. I guess the explanation is not perfect, but hopefully the code can clear up my issue abit :)
Edit: Just took some random pictures to be able to show...
#logo img{
z-index: 10;
left: 4%;
top:20px;
max-width: 50%;
height: auto !important;
position: absolute;
}
#signup img{
z-index: 10;
right: 4%;
top:20px;
max-width: 50%;
height: auto !important;
position: absolute;
}
#main-container img {
width: 100%;
height: 100%;
max-height:308px !important;
position: absolute;
top: 0;
left: 0;
margin:0;
}
#second-container {
}
<div class="container">
<div id="menu">
<div id="logo">
<a href="example.com">
<img src="https://tcrf.net/images/d/de/FBEAR-nosave.png" alt="" />
</a>
</div>
<div id="signup">
<a href="example.com">
<img src="https://tcrf.net/images/d/de/FBEAR-nosave.png" alt="" />
</a>
</div>
</div>
<div id="content">
<div id="main-container">
<img src="http://www.reallifeglobal.com/wp-content/uploads/2015/03/background-radi-700x300.png" alt="" />
</div>
<p>Ontop of background</p>
<div id="second-container">
<p>Under background</p>
</div>
</div>
</div>
https://jsfiddle.net/gt2d6aa7/
Since the image in main-container is not set as a background image and it comes before the paragraphs in the source code, it is appearing on top of the paragraphs.
2 things you could do to get the paragraphs to show:
1) Set a position property on the paragraph style to make it appear on top of the image:
div.container p{position:relative;}
2) I would suggest setting that image as the background of your container and giving it a minimum height (in case your content does not increase the container size enough to fully see your image). Like so:
<div id="main-container" style="background-image:url('http://www.reallifeglobal.com/wp-content/uploads/2015/03/background-radi-700x300.png');background-size:100%;min-height:300px;background-repeat:no-repeat;">
Then, make sure to close your main-container before opening the second-container, that way it creates a clean section for different content. The way you have it, second-container is inside the main-container and any content that you wanted to appear below the main background and top content would actually just appear on top of the main-container background.
The Squarespace site you linked to is a good example visually, but if you inspect their code it gets a little confusing for a beginner, since they are nesting the bottom sections (below that video presentation) in a section within in a div.
Twitter Bootstrap has some good examples of one-page layouts with cleaner markup to follow. This is a good example: http://blackrockdigital.github.io/startbootstrap-landing-page/
Here are their other examples: http://startbootstrap.com/template-categories/one-page/
I am not an advocate of Bootstrap, since it adds a lot of unnecessary bloat in most cases, but these give a good indication of how to structure your page.
Good luck!

How can I position my icons top right inside table cell?

I'm trying to position some icons inside a table cell <td>, but the result is that they are position top right of the screen (outside of the table cell).
Short version of my code is like this:
<td class="td_name">
<div class="actions">
<div class="floatLeft iconset_16px update_sprite_bw_16px" title="Update"></div>
<div class="floatLeft iconset_16px settings_sprite_bw_16px" title="Settings"></div>
<div class="floatLeft iconset_16px delete_sprite_bw_16px" title="delete"></div>
</div>
<div class="gal_name">
Some name
</div>
</td>
Where td_name position is set to relative and action is set to absolute. This should work, but not this time.
What am I missing here? Se full code example on jsFidle.
NOTE
I'm trying to position the action DIV inside the <td class="td_name">.
If your jsFiddle stills shows the iconset_16px divs in the top right corner of the HTML window in jsFiddle, then your example is not working either.
#sim_gallery .defaultList tr td.name { position: relative; width: 200px; height: 100px; }
#sim_gallery .defaultList tr td .actions { position: absolute; top: 0px; right: 0px; margin: 5px;}
NOTE 2
This is for everyone that is not familiar with the usage of tables.
In the early 90's it was very popular and very simple to use tables for page layout. But designers soon understood that changing layout was a pain in the a**. The use of tables also have several more disadvantages.
So yes, you can design anything without ever using tables.
So when do yo use tables? Tables are normally used for displaying tabular data. It's kind of Excel sheet for the web. My experience is that it's much easier to structure table data, than list elements and div's. So in some cases I use tables knowing that this will not have any negative effects on the website what so ever.
So please, do not start a debate about how bad is is to use tables. Use your energy to help me solve my problem :)
After some more testing, it looks like it's not possible to position a table cell. Which kind of makes sense. But I wasn't trying to position the table cell itself, but the content inside the cell.
After some more research on the web (and some useless debate here), I found this article. This basically gives me the short answer: No, it's not possible.
In their example, they use jQuery. But since I still want to do this using CSS, I came up with an alternative solution.
I simply wrap my content inside a DIV in the table cell, and make sure this DIV is as large as the table cell. Voila, all is good :)
.wrapper { width: 200px; height: 100px; line-height: 100px; position: relative; border: solid 1px #666; }
.actions { position: absolute; top: 0px; right: 0px; }
.iconset_16px { height: 16px; width: 16px; background-color: #87ceeb; margin: 3px;}
.floatLeft { float:left!important; }
<table>
<tr>
<td>
<div class="wrapper">
<div class="actions">
<div title="Update" class="floatLeft iconset_16px"></div>
<div title="Settings" class="floatLeft iconset_16px"></div>
<div title="delete" class="floatLeft iconset_16px"></div>
</div>
<div class="gal_name">
<a title=" Adventure" href="#"> Adventure</a>
</div>
<div>
</td>
</tr>
</table>
Don't know entirely what you're trying to do,
but have you tried setting position: relative on your <td> and then
adjusting the position of your icons as needed?
http://jsfiddle.net/Z3kpr/1/
Your div elements under actions are floating left with your !important flag (bad idea for this very reason) so they are ignoring the positioning of their parent.
Remove the float and they will be positioned properly.
Here's your updated fiddle with one of them fixed so you can see the difference.
http://jsfiddle.net/u9p4u/1/

CSS float causes blank space

I have to show a list of divs in a seamless order, thought their heights may vary.
Here's an example:
As you can see, when an element is floated to the left and is positioned next to another float it generates a white space until the next float. This doesn't happen the other way around. I can't seem to find a way around this and as I use javascript to filter out certain elements (divs) I can not create two different columns.
Here's the html/css:
<div style="width: 200px;">
<div style="float: left; width: 50%; background-color: green;">
<p>Float1</p>
</div>
<div style="float: left; width: 50%; background-color: blue;">
<p>Float2</p>
<p>expanded</p>
</div>
<div style="float: left; width: 50%; background-color: yellow;">
<p>Float3</p>
<p>expanded</p>
</div>
<div style="float: left; width: 50%; background-color: gray;">
<p>Float4</p>
</div>
<div style="float: left; width: 50%; background-color: red;">
<p>Float5</p>
</div>
</div>
Any ideas how to get it to look so that Float1 and Float3 don't have empty room between them?
In your example it might be possible using float:left for the uneven blocks and float:right for the even ones but in general this is not possible using just css. You will need javascript or 2 separate columns (or a combination...).
As you are using javascript already, it would be pretty easy to load all visible blocks in an array and divide them over two columns.
It seems that toggling float:left; and float:right; does what you want: http://jsfiddle.net/cELff/1/
Try using display: inline-block instead of float: left.
appreciate this q is old, for others that find this in a search ( like I was searching ).
the reason for the space is the heights. try setting a height on the floated items.

Resources