Response Header Issue - html

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;
}
}

Related

HTML/CSS - Dealing With Contents That Refuse To Vertically Center

I've been messing with a bunch of code that refuses to center within my divs that are floated left and right. For my left one, a span and an image are stuck in the bottom left, while on the right, normal text is stuck on the top-right.
Here's what it currently looks like.
As for my code, here it is. If I can get help on what I could maybe do to fix it, I'd appreicate it.
HTML:
<div class="header">
<div class="allSelector">
<!-- <span (click)="showAll()"><img src={{imgSource}} /> {{expandContractStatement}}</span> -->
<img src={{imgSource}} (click)="showAll()"/><span (click)="showAll()" class="selectorInsides">{{expandContractStatement}}</span>
</div>
<div class="legend">
Incidents
Tasks
CRs
Problems
</div>
</div>
CSS:
.header {
background-color: gray;
color:black;
font-size: 24pt;
line-height: 24pt;
height: 6%;
max-height: 6%;
overflow: hidden;
vertical-align: middle;
}
.allSelector {
width: 50%;
max-height: 100%;
height: 100%;
float: left;}
.selectorInsides { /*Threw this in because of some issues before*/
overflow: hidden;
}
.allSelector > img {
height: 80%;
object-fit: contain;
}
.legend {
line-height: 24pt;
max-height: 100%;
height: 100%;
width: 50%;
float: right;
margin: 0;
text-align: right;
vertical-align: middle;
}
It's hard to tell if this answer is sufficient since a minimal, reproducible example wasn't provided, but you use Flexbox to vertically align elements.
/* Vertically align elements */
.header,
.allSelector,
.legend {
display: flex;
align-items: center;
}
.selectorInsides {
/* Adjust the spacing between image and text as needed */
margin-left: 8pt;
}
/* Vertically align elements */
.header,
.allSelector,
.legend {
display: flex;
align-items: center;
}
.header {
background-color: gray;
color: black;
font-size: 24pt;
line-height: 24pt;
height: 6%;
max-height: 6%;
overflow: hidden;
vertical-align: middle;
}
.allSelector {
width: 50%;
max-height: 100%;
height: 100%;
float: left;
}
.selectorInsides {
/*Threw this in because of some issues before*/
overflow: hidden;
/* Adjust the spacing between image and text as needed */
margin-left: 8pt;
}
.allSelector>img {
height: 80%;
object-fit: contain;
}
.legend {
line-height: 24pt;
max-height: 100%;
height: 100%;
width: 50%;
float: right;
margin: 0;
text-align: right;
vertical-align: middle;
}
<div class="header">
<div class="allSelector">
<!-- <span (click)="showAll()"><img src={{imgSource}} /> {{expandContractStatement}}</span> -->
<img src="https://via.placeholder.com/32" (click)="showAll()" /><span (click)="showAll()" class="selectorInsides">Expand All</span>
</div>
<div class="legend">
Incidents Tasks CRs Problems
</div>
</div>

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;

stack the 2nd element first and then the 3rd element

I have three divs. I want them to be in one line so I used inline-block. When I resize the window the third element (nav) stacks and then the 2nd element (searchBar). I want the 2nd element stacks first and then the 3rd one. For undoing, the 3rd element and then the 2nd element.
body {
margin: 0px;
padding: 0px;
}
header {
width: 100%;
min-eight: 48px;
position: fixed;
background: #ffffff;
padding-bottom: 5px;
border-bottom: 2px solid #fed700;
}
nav {
width: 489.7px;
height: 18px;
background: red;
display: inline-block;
}
#searchBar {
width: 330px;
height: 16px;
background: blue;
display: inline-block;
white-space: nowrap;
}
#logo {
width: 220px;
height: 32px;
background: green;
display: inline-block;
}
<header>
<div id=logo>logo
</div>
<div id=searchBar>searchBar
</div>
<nav>nav
</nav>
</header>
You could use an inline-block wrapper with a min-width, wrapping the nav and searchBar. That would give the result you wanted in with the code sample supplied, but might cause problems in the real world, depending on your requirements.
body {
margin: 0px;
padding: 0px;
}
header {
width: 100%;
min-height: 48px;
position: fixed;
background: #ffffff;
padding-bottom: 5px;
border-bottom: 2px solid #fed700;
}
.wrapper {
min-width: 50%;
display: inline-block;
}
nav {
width: 489.7px;
height: 18px;
background: red;
display: inline-block;
}
#searchBar {
width: 330px;
height: 16px;
background: blue;
display: inline-block;
white-space: nowrap;
}
#logo {
width: 220px;
height: 32px;
background: green;
display: inline-block;
}
<header>
<div id=logo>logo
</div>
<div class="wrapper">
<div id=searchBar>searchBar
</div>
<nav>nav
</nav>
</div>
</header>

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

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/

Image disrupts div positions

I have three divs in a row, all with display: inline-block. The left one (green) contains an image. Because of that image, two other divs (blue and yellow) and the div below them (grey) are all positioned lower by height of the image.
Why does an image in one div affect positions of other divs in an inline-block row? How can I avoid it?
* {
margin: 0;
padding: 0;
border: 0;
}
body {
background: black;
}
div {
display: inline-block;
width: 300px;
height: 70px;
}
div.wrapper {
width: 900px;
height: 100px;
margin: 0 auto;
background: red;
display: block;
font-size: 0;
}
div.div1 {
background: green;
}
div.div2 {
background: blue;
}
div.div3 {
background: yellow;
}
div.div4 {
display: block;
width: 900px;
height: 30px;
background: grey;
}
<body>
<div class="wrapper">
<div class="div1">
<img src="" width="25px" height="25px">
</div>
<div class="div2">b</div>
<div class="div3">c</div>
<div class="div4">d</div>
</div>
</body>
Try float:left; display:block; instead of inline-block for div's: Demo
CSS:
.div1, .div2,.div3 {
display: block;
float:left;
width: 300px;
height: 70px;
}
There already is discussons about inline-block-elementes still have weird heights (like here): Why does inline-block cause this div to have height?
Honestly, instead of solving those, i would adress this issue with floats:
* {
margin: 0;
padding: 0;
border: 0;
}
body {
background: black;
}
div {
/*display: inline-block;*/ /* Not necessary when using floats! */
width: 300px;
height: 70px;
}
div.wrapper {
width: 900px;
height: 100px;
margin: 0 auto;
background: red;
display: block;
font-size: 0;
}
div.div1 {
background: green;
float: left; /* Added float left here */
}
div.div2 {
background: blue;
float: left; /* Added float left here */
}
div.div3 {
background: yellow;
float: left; /* Added float left here */
}
div.div4 {
display: block;
width: 900px;
height: 30px;
background: grey;
}