CSS, two columns - left with dynamic width (input), right with fixed (button) - html

can somebody please point me to a solution for this?
HTML
<div class="container">
<input type="text" class="left" />
<button class="right">Some button</button>
</div>
CSS
.container {
display: table;
width: 100%;
background-color: red;
}
.left, .right {
display: table-cell;
}
.right { width: 100px; }
Here is code pen sample: http://codepen.io/be-codified/pen/qdRRBY
Input field should be stretchable, button should be fixed positioned on right.
Thank you in advance.
// edit
I can not use table tag because layout needs to be responsive.

I gave the input a width of calc(100% - 110px) and the button a float:right which resulted in the following. Is that what you need? The input type you want to use is, as far as I know, not stretchable by the user.
CSS
.container {
display: table;
width: 100%;
background-color: red;
}
.left, .right {
display: table-cell;
}
.right {
width: 100px;
float: right;
}
input.left {
width: calc(100% - 110px); //This makes sure the input area is as wide as possible, while also leaving space for the button. Play with the exact measurements to get what you need.
}

I suggest you to put the form elements into <div>, so don't change their default display properties, and then set the left input box to 100% width as needed.
.container {
display: table;
width: 100%;
background-color: red;
}
.left, .right {
display: table-cell;
}
.right {
width: 100px;
}
.left input {
width: 100%;
box-sizing: border-box;
}
<div class="container">
<div class="left"><input type="text" /></div>
<div class="right"><button>Some button</button></div>
</div>
In fact, both left and right can have dynamic width, so right column always get the minimum width based on the button length.
.container {
display: table;
width: 100%;
background-color: red;
}
.left, .right {
display: table-cell;
white-space: nowrap;
}
.left {
width: 100%;
}
.left input {
width: 100%;
box-sizing: border-box;
}
<div class="container">
<div class="left"><input type="text" /></div>
<div class="right"><button>Some button</button></div>
</div>

Here is full responsive solution.
HTML
<div class="container">
<div class="input-flied-box">
<form>
<input type="text" required="required" placeholder="Right Some thing" />
<button type="submit" class="submit-button">Send</button>
</form>
</div>
</div>
CSS
/* RESPONSIVE CSS */
.container{
width: 100%;
}
.input-flied-box{
width: 100%;
}
.input-flied-box input{
padding: 6px 12px 6px 12px;
}
.submit-button{
top: inherit;
right: inherit;
position: relative;
margin-bottom: 15px;
}
#media (min-width: 768px){
.container{
width: 750px;
}
.input-flied-box{
width: 600px;
}
.input-flied-box input{
padding: 6px 101px 6px 12px;
}
.submit-button{
top: 14px;
right: 14px;
position: absolute;
margin-bottom: 0;
}
}
#media (min-width: 992px){
.container{
width: 960px;
}
}
#media (min-width: 1200px){
.container{
width: 1170px;
}
}
/* RESPONSIVE CSS END */
*:after,
*:before{
box-sizing: border-box;
}
*{
box-sizing: border-box;
}
.container:after,
.container:before{
display: table;
content: " ";
clear: both;
}
.container{
margin-left: auto;
margin-right: auto;
}
.input-flied-box {
background-color: #666666;
margin-left: auto;
margin-right: auto;
padding-left: 15px;
padding-right: 15px;
position: relative;
}
.input-flied-box input {
background-color: #ffffff;
border: 1px solid #cccccc;
height: 40px;
margin-bottom: 15px;
margin-top: 15px;
width: 100%;
border-radius: 4px;
}
.submit-button {
background-color: #fc3850;
border: medium none;
border-radius: 4px;
color: #ffffff;
font-family: Arial;
line-height: 1;
padding: 13px 30px;
text-transform: uppercase;
}
https://jsfiddle.net/bL3wgrv9/

Related

Content spills out of DIV's bottom

Content of two DIVs spills out of the bottom.
This problem arises not with all browsers. Chrome, IE, Edge - works fine but Firefox, Safari and Chrome for mobile (Android) reflects this problem.
Screenshot: chrome for Android (tablet device)
What's wrong with the code?
html {
height: 100%;
}
body {
background-image: url("background.jpg");
background-size: cover;
background-position: center center;
background-repeat: repeat;
height: 100%;
font-family: 'Times New Roman', Times, sans-serif;
font-size: 16px;
}
#open-hours {
float: left;
}
#contacts {
float: right;
}
.ins {
width: 4%;
height: 4%;
}
hr {
background-color: black;
}
#first-row-1 {
width: 362px;
height: 264px;
margin-right: -4px;
}
#first-row-1 img {
width: 100%;
height: 100%;
}
#first-row-2 {
width: 360px;
height: 262px;
border: 1px solid black;
vertical-align: top;
}
#first-row-2 h4 {
margin-top: 5px;
}
#first-row-1,
#first-row-2,
#second-row-1,
#second-row-2 {
display: inline-block;
}
#first,
#second,
h2 {
text-align: center;
}
#first-row-2 ul,
#second-row-1 ul {
text-align: left;
}
#logo {
width: 358px;
height: 34px;
}
#logo img {
width: 68px;
height: 34px;
}
#second-row-1 {
width: 360px;
height: 262px;
border: 1px solid black;
vertical-align: top;
margin-right: -4px;
}
#second-row-2 {
width: 362px;
height: 264px;
}
#second-row-2 img {
width: 100%;
height: 100%;
}
#second {
margin-top: -4px;
}
#media only screen and (max-width: 766px) {
#first-row-1,
#second-row-2,
#hide,
.ins,
.free-space {
display: none;
}
#open-hours,
#contacts {
float: none;
text-align: center;
}
#first-row-2,
#second-row-1 {
border: 1px solid black;
margin: 0 auto;
display: block;
width: 100%;
}
#second {
margin: 0px;
}
span {
display: block;
}
h2 {
font-size: 18px;
}
h4 {
margin: 5px 0px -10px 0px;
}
#logo {
margin: auto;
}
}
#media only screen and (max-width: 393px) {
#logo {
display: none;
}
#first-row-2,
#second-row-1 {
min-width: 285px;
}
}
<div>
<div id="open-hours">пн-пт 10.00-20.00</div>
<div id="contacts">
<img class="ins" src="phone_pic.png"> text
<img class="ins" src="envelope_pic.png"> <span>text</span>
</div>
<br class="free-space">
<hr>
<br class="free-space">
<h2>Успешный опыт продаж <span id="hide">кондиционеров и климатической техники</span> с 2007 года</h2>
<div id="first">
<div id="first-row-1">
<img src="photo_1.jpg">
</div>
<div id="first-row-2">
<h4>Мы предлагаем широкий спектр оборудования</h4>
<ul>
<li>бытовые кондиционеры</li>
<li>кондиционеры для коммерч. применения</li>
<li>тепловые насосы</li>
<li>осушители воздуха</li>
<li>мультизональные VRF системы</li>
<li>системы бытовой, полупромышленной и промышленной вентиляции</li>
<li>приточно-вытяжные агрегаты</li>
<li>тепловые завесы</li>
</ul>
<div id="logo">
<img src="logo.gif">
<img src="logo.png">
<img src="log.png">
<img src="logo.png">
<img src="logo.jpg">
</div>
</div>
</div>
<div id="second">
<div id="second-row-1">
<h4>Оплата</h4>
<ul>
<li>наличный расчет - в пункте выдачи или по факту доставки продукции</li>
<li>безналичный расчет - оплата физическими и юридическими лицами</li>
</ul>
<h4>Доставка</h4>
<ul>
<li>самовывоз</li>
<li>собственным транспортом компании</li>
<li>почтовыми, курьерскими службами Украины</li>
</ul>
</div>
<div id="second-row-2">
<img src="photo_2.jpg">
</div>
</div>
</div>
Try to replace height of first row and second row divs to min-height and height to auto
#first-row-1{
width: 362px;
height:auto;
min-height: 264px;
margin-right: -4px;
}
#first-row-2{
width: 360px;
height:auto;
min-height: 262px;
border: 1px solid black;
vertical-align: top;
}
I tried to fix your issue without making too many changes, but really the issue is, that you are setting fixed height to child elements and they overflows their parents. I'd suggest to make the layout responsive to save yourself headaches in the future when you'll want to write longer paragraphs.
Without changing the code too much, you could
do following changes to the first and second divs
display: flex;
Desired width, e.g. 2*362
margin: auto;
Following to first-row-1, first-row-2 and the same for second row
delete width and height attributes (or change height to min-height for design purposes)
flex: 1 0 0;

Response Header Issue

I have this code and I want the css code with a max-width: 780px, the .second in a line alone because it is the logo, and the .first and .third on the line below. I don't know how to do it.
Normally, this elements are Ordered in one line with a wider width than 780px. The normal order: first, second, third
The order I want with a max-width: 780px:
.................second..............
........first........|.......third......
<header>
<div class="first">
</div>
<div class="second">
</div>
<div class="third">
</div>
</header>
header {
background: #FFF;
width: 100%;
height: 160px;
}
.SearchBar {
width: 30%;
height: 130px;
display: inline-block;
float: left;
text-align: center;
}
.SearchBar:before {
/* create a full-height inline block pseudo=element */
content: ' ';
display: inline-block;
vertical-align: middle;
/* vertical alignment of the inline element */
height: 100%;
}
.SearchBar>p {
padding-right: 0;
padding-left: 0;
display: inline-block;
}
.SearchBar>p>input {
background: url("../images/search_icon.png") no-repeat scroll 0 0 transparent;
background-position: 90% 50%;
width: 230px;
height: 50px;
border: 1px solid #c8c8c8;
font-family: FuturaLight;
text-indent: 20px;
font-size: 18px;
}
.SearchBar>p>input:enabled {
cursor: text;
}
.logo {
width: 40%;
height: 130px;
display: inline-block;
margin: auto;
text-align: center;
}
.logo:before {
/* create a full-height inline block pseudo=element */
content: ' ';
display: inline-block;
vertical-align: middle;
/* vertical alignment of the inline element */
height: 100%;
}
.logo a {
display: inline-block;
vertical-align: middle;
/* vertical alignment of the inline element */
}
.shoppingcar {
width: 30%;
height: 130px;
display: inline-block;
float: right;
text-align: center;
}
.shoppingcar:before {
content: ' ';
display: inline-block;
vertical-align: middle;
height: 100%;
}
.cartletter {
padding-right: 0;
padding-left: 0;
display: inline-block;
font-family: FuturaLight;
}
<header>
<div class="subheader"></div>
<div class="SearchBar">
<a> FIRST</a>
</div>
<div class="logo">
<a> SECOND</a>
</div>
<div class="shoppingcar">
<p class="cartletter">
<a> THIRD</a>
</p>
</div>
</header>
hmm, well since there's no css code and jsfiddle, I'm assuming this can do the trick ? try it on and let me know please ?
#media all and (max-width: 780px) {
.second {
display:inline-block;
}
.first {
display:inline;
float:left;
}
.third {
display:inline;
float:right;
}
}

Vertical div expansion w/o fixed heights

Before you roll your eyes and move on, I know how to solve this problem by using a fixed height and absolution positioning with top: and bottom:, but I want to solve it without using fixed heights. I want to learn more about CSS so I'm trying to solve this a different way.
I have set up a typical navbar running across the top, and then a scrolling content div below.
However! How do I fit the bottom scrolling div container to the remaining space without using absolute coordinates? I can't do position: absolute, because then I'd need to know the height of the navbar to set "top:". And I can't do "bottom: 0" because I'd have to specify a height.
Here's the JS filddle:
http://jsfiddle.net/8dugffz4/1/
The class of interest is ".result". I currently have the height fixed, which I don't want.
Thanks, y'all.
PT
CSS:
* {
font-family: Helvetica, Sans;
border: 0px;
margin: 0px;
padding: 0px;
}
.navBar {
width: auto;
overflow: auto;
border-bottom: 1px solid #bbb;
}
.pageBar {
float: right;
}
.pager {
cursor: pointer;
float: left;
border: 1px solid #bbb;
width: 2em;
height: 2em;
line-height: 2em;
text-align: center;
margin: 5px;
margin-left: 0px;
background: #eee;
color: #bbb;
}
.pager:hover {
background: #777;
border: 1px solid black;
color: white;
}
.fliph {
-ms-transform:scale(-1,1); /* IE 9 */
-moz-transform:scale(-1,1); /* Firefox */
-webkit-transform:scale(-1,1); /* Safari and Chrome */
-o-transform:scale(-1,1); /* Opera */
}
.results {
background: gray;
width: 100%;
height: 200px;
overflow: scroll;
}
.line {
height: 10em;
line-height: 10em;
border: 1px solid red;
}
HTML:
<body>
<div class='navBar'>
<div class='pageBar'>
<div class='pager'>◁</div>
<div class='pager'>1</div>
<div class='pager fliph'>◁</div>
</div>
</div>
<div class='results'>
<div class='line'>Line1</div>
<div class='line'>Line2</div>
<div class='line'>Line3</div>
<div class='line'>Line4</div>
</div>
</body>
Here's a solution that uses display: table and can actually achieve fluid heights:
http://jsfiddle.net/8dugffz4/8/
And a minimalistic snippet in case you want to see specifically what I did:
* {
margin: 0;
padding: 0;
}
html,
body {
height: 100%;
}
#table {
display: table;
height: 100%;
width: 100%;
}
#table > div {
display: table-row;
}
#navbar {
height: 45px;
opacity: .5;
}
#navbar > div {
height: 100%;
background: black;
}
#results {
height: 100%;
}
#results > div {
height: 100%;
overflow: auto;
background: green;
}
<div id="table">
<div id="navbar">
<div></div>
</div>
<div id="results">
<div></div>
</div>
</div>
If you're just looking for an alternative to the position: absolute method, you could use the height: 100% method:
html, body { height: 100%; }
body { box-sizing: border-box; padding-top: 45px; }
.navBar { height: 45px; margin-top: -45px; }
.results { height: 100%; }
Like so: http://jsfiddle.net/8dugffz4/7/

divs move when resizing the page

I have a timeline on a site I'm trying to recreate and when I resize the window to mobile, the divs get separated. I'm a little far into the site and am very cautious about what I need to do to make this work. The timeline has icons (which have their own div) & a icon background (which have their own div too) but I think I need to wrap them around in one larger div to make this work, but not sure how.
See images here for a before I resize and after I resize:
See how the icons get separated from the background?
Html code for each item in timeline:
<div class="timeline_item">
<div class="timeline_time"><p><em>1 hr ago</em></p></div>
<div class="icon_background"></div>
<div class="timeline_icon "><i class="ss-icon">doc</i></div>
<div class="timeline_text"><p>You read the article </p> </div>
</div>
CSS:
.timeline_item {
width: 100%;
padding-bottom: 17%;
}
.timeline_item .timeline_time {
float: left;
width: 20%;
}
.timeline_item .timeline_icon {
float: left;
width: 1%;
}
.timeline_item .timeline_text {
float: left;
width: 65%;
padding-left: 3%;
}
.timeline_icon {
margin-left: -4%;
margin-top: 2.5%;
}
Without access to a proper Jsfiddle Demo, here's one suggestion with a reduced HTML structure which uses pseudo-elements.
You could use an icon-font, sprite or whatever where I have used a single letter.
Codepen Demo
HTML
<div class="timeline">
<article class="timeline_item">
<div class="timeline_time">
<p>1 hr ago<p>
</div>
<div class="timeline_text" data-event-type="doc"><p>You read the article </p> </div>
</article>
<article class="timeline_item">
<div class="timeline_time">
<p>1 hr ago<p>
</div>
<div class="timeline_text" data-event-type="alert"><p>You have a 'Do Not Miss' Meeting scheduled for tomorrow 9a.m.</p> </div>
</article>
<article class="timeline_item">
<div class="timeline_time"><p>1 hr ago<p>
</div>
<div class="timeline_text" data-event-type="video"><p>You watched a video</p> </div>
</article>
</div>
CSS
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
margin: 0;
padding: 0;
}
.timeline {
width:50%;
margin: 1rem auto;
border:1px solid lightgrey;
}
.timeline_item {
display: table;
width:100%;
}
.timeline_time,
.timeline_text {
display: table-cell;
padding:1rem 2rem;
}
.timeline_time {
width:25%;
text-align: right;
border-right:1px solid lightgrey;
}
.timeline_text {
position: relative;
}
[data-event-type]:before {
position: absolute;
content:"";
width:32px;
height:32px;
line-height: 32px;
text-align: center;
color:white;
left:0;
top:0;
border-radius: 50%;
transform:translate(-50%,50%);
}
[data-event-type="doc"]:before {
content:"D";
background: #00f;
}
[data-event-type="alert"]:before {
content:"A";
background: #f00;
}
[data-event-type="video"]:before {
content:"V";
background: #0f0;
}
The techniques shown here might help you wit your current issue(s).
There are, of course, alternatives to this layout method, including floats and actual tables. some of those will require 'fixes' to achieve the 'equal heights' that is native to CSS tables.
Since there was no complete html or css, this is a mobile first approach that requires fairly decent css skills to follow, but it starts off in a logical way for small viewports and adjusts fluidly. The min-width is where the layout for larger view ports starts. The styles before this are global (shared by all view port sizes).
DEMO: http://jsbin.com/zerijo/1/
http://jsbin.com/zerijo/1/edit
CSS:
/*demo only body */
body {
font-family: sans-serif;
background:#fff;
padding:5%;
}
/* ---------- timeline styles ------------ */
.timeline_wrapper:after, .timeline_item:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
.timeline_wrapper, .timeline_item {
display: inline-block
}
* html .timeline_wrapper, * html .timeline_item {
height: 1%
}
.timeline_wrapper, .timeline_item {
display: block
}
.timeline_wrapper,
.timeline_wrapper div,
.timeline_wrapper *:before,
.timeline_wrapper *:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.timeline_wrapper {
position: relative;
padding-top: 10px;
line-height: 1.5;
}
.timeline_wrapper:before {
position: absolute;
top: -5px;
bottom: 10px;
left: 15px;
content: "";
height: 100%;
display: block;
border-right: 1px solid #777;
width: 1px;
z-index: -1;
}
.timeline_wrapper p {
margin: 0
}
.timeline_icon i {
background: red;
display: block;
border-radius: 50%;
width: 30px;
height: 30px;
line-height: 32px;
text-align: center;
font-size: 15px;
color: #fff;
float: left;
}
.timeline_text {
float: left;
width: 100%;
padding: 0 0 0 40px;
}
.timeline_time {
padding-left: 40px
}
.timeline_item {
width: 100%;
position: relative;
}
.timeline_item:not(:last-child) {
padding-bottom: 30px;
}
#media (min-width:480px) {
.timeline_wrapper {
position: relative;
padding-top: 10px;
}
.timeline_wrapper:before {
left: 27%
}
.timeline_item > div {
float: left;
position: relative;
}
.timeline_time {
width: 22%;
text-align: right;
padding: 0;
left: -10%;
}
.timeline_icon {
width: 10%;
min-height: 50px;
left: 22%;
top:-5px;
}
.timeline_icon i {
margin: 0 auto;
float: none;
}
.timeline_text {
float: left;
width: 100%;
margin-left: -37%;
padding: 0 0 0 37%;
}
}
HTML -- structured differently for mobile then adjusted position at the min-width:
<div class="timeline_wrapper">
<div class="timeline_item">
<div class="timeline_icon">
<i class="your-icon"></i>
</div>
<div class="timeline_time">
<p><em>1 hr ago</em></p>
</div>
<div class="timeline_text">
<p>Lack of peppering one's sentences with gerunds.Lack of peppering one's sentences with gerunds. Lack of peppering one's sentences with gerunds. You read the article </p>
</div>
</div>
<div class="timeline_item">
<div class="timeline_icon">
<i class="your-icon"></i>
</div>
<div class="timeline_time">
<p><em>1 hr ago</em></p>
</div>
<div class="timeline_text">
<p>You read the article Lack of peppering one's sentences with gerunds. Lack of peppering one's sentences with gerunds.Lack of peppering one's sentences with gerunds.Lack of peppering one's sentences with gerunds.</p>
</div>
</div>
<div class="timeline_item">
<div class="timeline_icon">
<i class="your-icon"></i>
</div>
<div class="timeline_time">
<p><em>1 hr ago</em></p>
</div>
<div class="timeline_text">
<p>You read the article.</p>
</div>
</div>

Stretch a div to fit content in all screen size

HTML
<div class="whole">
<div class="fst"></div>
<div class="sec"></div>
<div class="thd"></div>
</div>
CSS
.whole {
width: 100%;
height: 20px;
}
.whole div {
height: 20px;
display: inline-block;
position: relative;
}
.fst {
float: left;
width: 20px;
background: blue;
}
.sec {
background: red;
}
.thd {
float: right;
width: 20px;
background: blue;
}
Is there a way to stretch the div.sec to fit with the area left by div.fst and div.thd in any screen size? The width of div.fst and div.thd is fix in pixel.
Is there any solution with only css?
Really appreciate your helps!
Please see my fiddle http://jsfiddle.net/vHHcf/
This seems to be what you want.
jsFiddle example
Given that you said .fst and .thd have fixed widths, you can use calc() to subtract the 40px value from 100%.
.sec { width:calc(100% - 40px); }
Updated CSS
.whole {
width: 100%;
height: 20px;
}
.whole div {
height: 20px;
display: inline-block;
position: relative;
}
.fst {
float: left;
width: 20px;
background: blue;
}
.sec {
background: red;
width:calc(100% - 40px);
}
.thd {
float: right;
width: 20px;
background: blue;
}