CSS: Using 100% of remaining width - css

I'm making a list consisting of an image, title, buttons, source code and am having a problem with using 100% of the remaining width.
My main problem is that I'm not being able to make a <textarea> use all the remaining width and height.
Here's what I'm getting:
And what I intend to have:
Below the source code, CSS:
.listing {width:100%;background:#f1f1f1;display:table;}
.leftimage {clear:none;display:table-cell;padding:20px;}
.listing .information {padding: 20px;width:100%;display:table-cell;}
.listing .information .title {font-size:20px;color:#016b98;}
.listing .information .title a {color:#016b98;text-decoration:underline;}
.listing .information .outsideButton {float:left;padding-top:5px;padding-right:5px;clear:none;}
.listing .information .outsideButton {clear:right;}
.listing .information .outsideButton .button {border: 1px solid #626262;background:#d8d8d8;}
.listing .information .outsideButton .button .label {padding:5px;}
.listing .information .outsideButton .button .label a {color:#626262;}
HTML:
<div class="listing">
<div class="leftimage">
<div style="height:150px;"><!-- Allows to change image position on click without changing .listing size -->
<a><img class="preview" height="150px" src="img.png"></a>
</div>
</div>
<div class="information">
<div class="title">
<a>TITLE</a>
</div>
<div class="outsideButton">
<div class="button">
<div class="label">
<a>BUTTON 2</a>
</div>
</div>
</div>
<div class="outsideButton">
<div class="button">
<div class="label">
<a>BUTTON 3</a>
</div>
</div>
</div>
<div class="outsideButton">
<div class="button">
<div class="label">
<a>BUTTON 4</a>
</div>
</div>
</div>
<div class="outsideButton">
<div class="button">
<div class="label">
<a>BUTTON 5</a>
</div>
</div>
</div>
<!-- END OF BUTTONS -->
<!-- HERE I WANT TO DISPLAY THE TEXTAREA WITH HTML CODE -->
<div style="float:left;padding-top:10px;clear:left;width:100%;">
<textarea style="padding:0;margin:0;width:100%;"><?php echo htmlspecialchars("<div><span>Whatever...</span></div><div><span>Whatever...</span></div><div><span>Whatever...</span></div><div><span>Whatever...</span></div><div><span>Whatever...</span></div><div><span>Whatever...</span></div>"); ?></textarea>
</div>
<!-- END OF TEXTAREA WITH HTML CODE -->
</div><!-- END OF .information -->
</div>
Thanks.
SOLUTION:
Set vertical-align:top; for every table-cell

As also referred in my comments maybe this helps you to achieve the same result but without the usage of floats at all:
CSS for HTML dynamic layout with not fixed columns?
Build the layout with display: table; and display: table-cell; properties and then use width: 100% on your <textarea>
EDIT:
You still use floats for your buttons - clear them correctly - e.g. wrap them in a <div class="clearfix"> and use this css for it:
.clearfix {
*zoom: 1;
}
.clearfix:before,
.clearfix:after {
display: table;
line-height: 0;
content: "";
}
.clearfix:after {
clear: both;
}
EDIT:
For anyone refering to this question: as pointed out by 2013Asker, don't forget to set the vertical-align: when using display: table-cell

First you have to tell the container div to get the remainder space and then tell textarea to get all that space of its parent. Add 'width: 100px' to each one.
<div style="float:left;padding-top:10px;clear:left; width:100%">
<textarea style="padding:0;margin:0; width: 100%"><?php echo htmlspecialchars("<div> <span>Whatever...</span></div><div><span>Whatever...</span></div><div><span>Whatever...</span></div><div><span>Whatever...</span></div><div><span>Whatever...</span></div><div><span>Whatever...</span></div>"); ?>
</textarea>
</div>

Related

stop `inline-block` and then start again

On a page of mine I have two elements (let's name them X and Z) styled with inline-block, so they are positioned one next to the other.
Right below them I want to place three elements (let's name them A,B,C), one next to the other again.
When I insert element A with inline-block, it goes next to Z.
If I apply clear:both to A, then it goes under (so that's good) but if I also apply inline-block to A, then A, B and C go right next to X and Z! How can I override this?
.header h1 {
text-align: center;
}
.map img{
width: 100%;
height: 100%;
}
.logo {
display: inline-block;
float: left;
}
.logo img {
display: block;
margin: auto;
}
.info {
padding: 5px ;
display: inline-block;
float: left;
background-color: #c0dfd9
}
.column1 {
width: 45%;
}
<div class="container" id="contact"> <!-- /CONTACT -->
<div class="map">
<img src="img/map.jpg" alt="map">
</div>
<div class="header">
<h1 id="contactheader">Contact me</h1>
<div>
<div class="logo column1">
<img src="img/logo.png" alt="logo">
</div>
<div class="info column1">
<p><span class="glyphicon glyphicon-user"></span><strong>Email:</strong>John#john.com</p>
<p><span class="glyphicon glyphicon-home"></span><strong>Address:</strong>Plateia Karitsi 25</p>
<p><span class="glyphicon glyphicon-asterisk"></span><strong>Telephone:</strong>+30 1654984</p>
</div>
</div> <!-- /END CONTACT -->
<br>
<footer>
<div id="copyright">©John 2016</div>
<div id="twitterbutton">Follow #aptbs</div>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
<div class="fb-like" data-href="https://www.facebook.com/QOTSA/?fref=ts" data-layout="button" data-action="like" data-show-faces="true" data-share="false"></div>
</footer>
Line break: https://developer.mozilla.org/en/docs/Web/HTML/Element/br
div {display: inline-block; padding: 8px 12px; background: #ccc; margin: 4px}
<div>x</div>
<div>z</div>
<br>
<div>a</div>
<div>b</div>
<div>c</div>
No need to complicate simple things.
Here's your code modified by what I wrote in the comment:
You need to remove float rules from X and Z. And then you won't even need the <br> because they're in separate blocks. Also, make sure A, B and C are inline-blocks as well (they are blocks now).
.header h1 {text-align: center;}
.map img{width: 100%; height: 100%;}
.logo, #twitterbutton, #copyright, .fb-like {display: inline-block;}
.logo img {display: block; margin: auto;}
.info {padding: 5px; display: inline-block; background-color: #c0dfd9}
.column1 {width: 45%;}
<div class="container" id="contact"> <!-- /CONTACT -->
<div class="map">
<img src="img/map.jpg" alt="map">
</div>
<div class="header">
<h1 id="contactheader">Contact me</h1>
<div>
<div class="logo column1">
<img src="img/logo.png" alt="logo">
</div>
<div class="info column1">
<p><span class="glyphicon glyphicon-user"></span><strong>Email:</strong>John#john.com</p>
<p><span class="glyphicon glyphicon-home"></span><strong>Address:</strong>Plateia Karitsi 25</p>
<p><span class="glyphicon glyphicon-asterisk"></span><strong>Telephone:</strong>+30 1654984</p>
</div>
</div> <!-- /END CONTACT -->
<footer>
<div id="copyright">©John 2016</div>
<div id="twitterbutton">Follow #aptbs</div>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
<div class="fb-like" data-href="https://www.facebook.com/QOTSA/?fref=ts" data-layout="button" data-action="like" data-show-faces="true" data-share="false"></div>
</footer>

background url not beneath text

I am working on a project where we are using blocks which contains text. The blocks have a header image. The result should be something like the picture below.
The problem I am facing is that the image is set using the CSS background-url propertly, which makes the image go beneath the text instead of being displayed as a header image. I am using the code below, for the purpose of this question in the style of the picture above:
.block {
background-color: #fff;
border-radius: 5px;
padding: 20px 40px 20px 40px;
margin: 10px 10px 10px 10px;
}
.header {
background: url('https://www.facebook.com/rsrc.php/v2/yq/r/ZAmUp1oGGPN.png');
background-size: contain;
height: 300px;
}
This creates the <div> that I need, however as you can see on the picture below, it does not give me the result I want.
I have tried setting the .header to display: block, but this did not change anything. I have also tried using margin to force the text to be displayed under the image, which did not work either. Can someone help me to get the result I want?
The relevant HTML is down below.
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="block header">
<h1>A Bootstrap Starter Template</h1>
<p class="lead">Complete with pre-defined file paths that you won't have to change!</p>
<ul class="list-unstyled">
<li>Bootstrap v3.3.6</li>
<li>jQuery v1.11.1</li>
</ul>
</div>
</div>
</div>
</div>
Change your html to below:
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="header">
</div>
<div class="block">
<h1>A Bootstrap Starter Template</h1>
<p class="lead">Complete with pre-defined file paths that you won't have to change!</p>
<ul class="list-unstyled">
<li>Bootstrap v3.3.6</li>
<li>jQuery v1.11.1</li>
</ul>
</div>
</div>
</div>
</div>
You have put block and header in the same div, so your background-color in .block class is overriden by background of .header class.
Here is fiddle.
If you really want to use a background image, consider using % padding. That also helps the layout stay responsive. Also, cover forces the background image to cover the entire div, so you don't want that at all.
.block {
background-color: #fff;
border-radius: 5px;
padding: 20px 40px 20px 40px;
margin: 10px 10px 10px 10px;
}
.header {
background: url('https://www.facebook.com/rsrc.php/v2/yq/r/ZAmUp1oGGPN.png');
background-size: 100% auto;
background-repeat: no-repeat;
padding-top: 32%;
}
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="block header">
<h1>A Bootstrap Starter Template</h1>
<p class="lead">Complete with pre-defined file paths that you won't have to change!</p>
<ul class="list-unstyled">
<li>Bootstrap v3.3.6</li>
<li>jQuery v1.11.1</li>
</ul>
</div>
</div>
</div>
</div>
I keep my original suggestion of using an <img> instead of a background image. It is both easier to implement and more correct semantically.
I've tried to simulate the result in your image below:
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="row content">
<img class="header_img" src="https://www.facebook.com/rsrc.php/v2/yq/r/ZAmUp1oGGPN.png" />
<div class="col-md-12">
<div class="block header">
<h1>A Bootstrap Starter Template</h1>
<p class="lead">Complete with pre-defined file paths that you won't have to change!</p>
<ul class="list-unstyled">
<li>Bootstrap v3.3.6</li>
<li>jQuery v1.11.1</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
CSS:
.header_img{
width: 100%;
height: auto;
}
.content{
background-color: white;
border-radius: 5px;
margin-top: 20px;
overflow: hidden;
}
Demo: http://jsfiddle.net/bh7Lh42k/1/

Input field should take the remaining width

I am trying to build a form to add new users to some kind of entity. The idea is to have user avatars in a line and on the end of the line there is a input-field with a typeahead to insert new users.
I tried this some years ago and ended up using javascript as I was not able to do this in plain css (2).
The big question: is this somehow possible in css3?
Basic idea of code:
<div class="availableWidth">
<div class="list">
<ul>
<li><div class="avatar">...</div></li>
...
</ul>
</div>
<div class="form">
<div class="typeaheadField">
<input ...>
</div>
<button>+</button>
</div>
</div>
CSS:
.list ul li {
list-style-type:none;
display:inline-block;
}
button {
width:50px;
}
Basic Idea is that the box .availableWidth has some width (100%) the box .list grows in width (when new li items are added) as the box .form should shrink in width. Right to the input is a some pixels wide button. The input should take the remaining space.
Is that possible in css3 or will I need Javascript?
You can use flexbox, or you can use display table attributes in CSS. Take a look:
.container {
display: table;
width: 100%;
position:relative;
}
.avatar {
width: 50px;
height: 50px;
display: table-cell;
}
.input {
height: 50px;
display:table-cell;
vertical-align: middle;
}
.input input {
width: 100%;
box-sizing: border-box;
padding: 5px;
}
<div class="container">
<div class="avatar">
<img src="http://dummyimage.com/50x50/000/fff&text=Avatar"/>
</div>
<div class="avatar">
<img src="http://dummyimage.com/50x50/000/fff&text=Avatar"/>
</div>
<div class="avatar">
<img src="http://dummyimage.com/50x50/000/fff&text=Avatar"/>
</div>
<div class="input">
<input type="text"/>
</div>
</div>
<div class="container">
<div class="avatar">
<img src="http://dummyimage.com/50x50/000/fff&text=Avatar"/>
</div>
<div class="avatar">
<img src="http://dummyimage.com/50x50/000/fff&text=Avatar"/>
</div>
<div class="avatar">
<img src="http://dummyimage.com/50x50/000/fff&text=Avatar"/>
</div>
<div class="avatar">
<img src="http://dummyimage.com/50x50/000/fff&text=Avatar"/>
</div>
<div class="avatar">
<img src="http://dummyimage.com/50x50/000/fff&text=Avatar"/>
</div>
<div class="input">
<input type="text"/>
</div>
</div>
You can add all the avatars that you want at left side and the input rearrange automatically.
You want to make input 100% width relative to some container from avatars to button. You can get it by using table, flexboxes or formatting contexts and floats.
Here is last one http://jsfiddle.net/53f0yzeL/
Notice overflow:hidden rule for .avatars-wrapper, it make container to fit exactly between floated elements and .avatars side so you can make input 100% wide.

How do I float these fieldsets?

I am working with an existing system, and am trying to modify the CSS in order to arrange the three columns correctly.
What css changes do I need to make in order to display the third column correctly?
View in this JSFiddle
CSS
.test .repeater {
border: none;
margin: 0;
}
.test .indent1 .wizard-parentcontrol .controlkl {
width: 33%;
float: left;
display: block;
}
.test .wizard-controls .indent1 .control:first-child {
margin-top: 17px;
}
.test .indent1 .wizard-parentcontrol .popupbrowser {
width: 30%;
float: left;
border: 1px solid red;
display: block;
}
HTML
<div class="test wizard-parentcontrol">
<div>
<div>
<fieldset></fieldset>
</div>
<div>
<div>
<fieldset>
<div>
<div class="repeater indent1">
<div class="wizard-parentcontrol">
<div>
<div>
<div class="controlkl">Column 1</div>
</div>
</div>
<div>
<div>
<fieldset>
<div id="p0t2c4dpopupbrowserControl" class="popupbrowser">Column 2</div>
</fieldset>
</div>
<div>
<div class="">
<p class="ctrlinvalidmessage"></p>
<fieldset>
<div id="p0t2c5dpopupbrowserControl" class="popupbrowser">Column 3</div>
</fieldset>
</div>
</div>
</div>
</div>
</div>
</div>
</fieldset>
</div>
</div>
</div>
</div>
Check If you can do the following changes.
I just added class
.wizard-parentcontrol div
{
float:left;
}
and removed the hardcoded width's of 33% and 30% from your code.
Check the demo

Align div to top of container

You can see in this JSFiddle that the search div is centre aligned, how can I make it align to the top?
HTML:
<div id="wrapper">
<div id="banner">
<a href="#"><h1>Title</h2><br />
<h2>Subtitle</h2></a>
<div id="search">
<label>Search</label>
<input type="textbox"/>
<input type="submit" />
<img src="images/logo.png" alt="logo"/>
</div>
</div>
CSS:
#wrapper{
width:85%;
margin:35px auto;
}
#banner{
height:150px;
padding:30px;
padding-bottom:5px;
}
#search{
float:right;
display:inline;
width:38%;
}
#banner h1, #banner h2{
margin:0;padding:0;color:#A2A2A2;display:inline;
}
#banner h1{
font-size:50px;
}
#banner h2{
font-size:35px;
}
You have at least two options. If you want to float the search div to right, move it up in the html code. Now the search div floats right to the elements that are after it in the code. (Note that you had an unclosed div in the original code.)
See the Fiddle
<div id="wrapper">
<div id="banner">
<div id="search">
<label>Search</label>
<input type="textbox"/>
<input type="submit" />
<img src="images/logo.png" alt="logo"/>
</div>
<a class="" href="#"><h1>Title</h2><br />
<h2 class="">Subtitle</h2></a>
</div>
</div>
Other option is to make the preceding elements (a and h2) float to the left side of the search div but that doesn't look so good as the search div is not at the right edge of the browser window.

Resources