How to make a div responsive - html

How can I change the position of a div smoothly, responsive?
HTML:
<div class="icon">
<i class="fa fa-search toggle_icon"></i>
</div>
<div class="sidenav">
<center>
<input id="provider-json" />
</center>
</div>
CSS:
.icon {
position: absolute;
top: 30%;
left: 0;
width: 50px;
height: 50px;
background: #d54042;
}
.sidenav {
position: absolute;
top: 30%;
left: 52px;
height: 50px;
width: 200px;
border-top-right-radius: 8px;
border-bottom-right-radius: 8px;
background: #d54042;
background: -webkit-linear-gradient(left, #D54042 , #D56769);
background: -o-linear-gradient(right, #D54042, #D56769);
background: -moz-linear-gradient(right, #D54042, #D56769);
background: linear-gradient(to right, #D54042 , #D56769);
}
#provider-json {
margin-top: 6px;
padding: 10px 5px;
border-radius: 3px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
border:solid 1px #ccc;
-moz-box-shadow: inset 0 0 4px rgba(0,0,0,0.2);
-webkit-box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.2);
box-shadow: inner 0 0 4px rgba(0, 0, 0, 0.2);
outline-color: #d54042;
}
.toggle_icon {
font-size: 2.5em;
color: white;
padding: 3px 3px 2px 5px;
}
I would like to change verticaly the position of .icon and .sidenav.
When i make the screen smaller it should go smoothly up to top: 0;
I tried this:
#media screen and (max-width: 480px) {
.icon, .sidenav {
top: 5%;
}
}
But this works only when the screen is 480px wide.

To give that a smooth transition, make use of css transition as below,
#media screen and (max-width: 480px) {
.icon, .sidenav {
top: 0;
transition:0.6s ease; /*Add this*/
}
}
This move icons and search bar to top at screen resolution below 480px;, check this jsFiddle

As per your question "change the place smoothly" I am giving you some idea about relative and absolute positioning.
According to reference "Absolute location is a place's exact spot on a map, while relative location is an estimate of where a place is in relation to other landmarks." What this means relative takes parent div into consideration but absolute is totally absolute.
<div class="container">
<div class="icon">
<i class="fa fa-search toggle_icon"></i>
</div>
<div class="sidenav">
<center>
<input id="provider-json" />
</center>
</div>
</div>
Now, refine your code by keeping container with relative positioning and other with absolute. Relative should always wrap the absolute. Also take some reference from online tutorials like w3schools with better example. You will be cleared with concept.

Related

How to make an image overlay the bottom shadow of the containing element

I want the legs of the girl to appear on the "border" or box-shadow. I want the image 5px down.
Here's the JsFiddle: https://jsfiddle.net/9rwuz4Lq/2/
body {
background: black;
}
main {
background: rgba(255, 255, 255, 0.85);
padding: 25px;
border-radius: 10px;
overflow: auto;
box-shadow: 0px 5px 0px rgba(255, 255, 255, 0.45);
}
main h2 {}
main img {
width: 25%;
float: left;
margin-bottom: -25px;
margin-right: 25px;
}
#media only screen and (max-width: 400px) {
main img {
display: none;
}
}
<main>
<img src="https://i.imgur.com/SwZDvlS.png">
<h2>Title</h2>
<P>BLABLA</P>
<P>BLABLA</P>
</main>
You can actually get away with just position: relative the image and giving it your -5px offset. Check this updated fiddle.
Full disclosure: I did tweak your layout a bit so you don't have to deal with floats, but the basic concept still applies.
main img {
position: relative;
bottom: -5px;
width: 25%;
margin-right: 25px;
z-index: 2;
}
You have to make the image to be position absolute in the main div and the position of the main tag to be position relative.
Then you have to set the top and left Pixels .

weird border placement

I have found some weird CSS bug.
I have a <div> container with some text and a Font-Awesome icon inside. The <div> container is styled so that it has a small border. The weird thing is that the border seems to "think" that the <div> is only half the height of what it actually is.
This occurs only in Chrome mobile (Android) but not in Chrome desktop (not tested in safari and co...)
HTML
<div class="sidebar">
Lade Daten... <li class="fa fa-spin fa-spinner"></li>
</div>
CSS
#media only screen and (max-width: 860px)
{
.sidebar {
position: relative;
width: auto;
margin: 0 20px;
}
}
.sidebar {
position: absolute;
background: rgb(255, 255, 255);
border-radius: 5px;
margin-left: 20px;
padding: 20px;
border: 1px solid rgba(0, 0, 0, 0.9);
width: 335px;
box-shadow: 2px 2px 5px;
}
body {
margin: 0;
background: rgb(60,60,60);
font-size: 16px;
font-family: 'Share Tech Mono', Arial;
}
Try putting height: (px you want it) in your #media query

Creating a “flat long shadow” for text in CSS with less CSS

Note: This question is similar to this question; however, it is different and thus is being asked as a separate question to the one just linked.
I am trying to create a flat long shadow in CSS for the text in a logo. The original way I found to do it is based on Matt Lambert's tutorial. The way Matt proposes to do it would require a lot of CSS (although, kudos to him, it does work and goodness knows I didn't figure that out). So thus that led me to ask for a way to do that with less CSS. #vals figured out how to do that with this.
Now I'm attempting to make a flat-long-shadow (does anyone have a shorter abbreviation for this? how about the acronym: "FLS?") for the text of a logo (i.e. this); however, it isn't going so well...
As you can see from this fiddle I made, I sort of combine the two techniques... but, while it's not atrocious, it doesn't work perfectly...
Here is the same fiddle in a snippet:
/* shadow color: #2d5986 */
html, body {
height: 100%;
}
body {
display: flex;
flex-flow: column wrap;
overflow: hidden;
}
div {
min-height: 128px;
min-width: 128px;
background-color: #369;
color: white;
font-size: 4em;
display: flex;
align-items: center;
justify-content: center;
position: relative;
overflow: hidden;
}
span {
/* background-color: #47a; */
position: relative;
text-align: center;
text-shadow: #2d5986 1px 1px,
#2d5986 2px 2px,
#2d5986 3px 3px,
#2d5986 4px 4px,
#2d5986 5px 5px,
#2d5986 6px 6px,
#2d5986 7px 7px,
#2d5986 8px 8px,
#2d5986 9px 9px,
#2d5986 10px 10px,
#2d5986 11px 11px,
#2d5986 12px 12px,
#2d5986 13px 13px,
#2d5986 14px 14px;
}
.shadow:before, .shadow:after {
content: "";
position: absolute;
right: 0px;
bottom: 15px;
z-index: 1;
transform-origin: bottom right;
}
.shadow:before {
height: 40px; /* increased height */
width: 100%;
left: 0px;
transform: skewX(45deg);
box-shadow: 1px 40px 0px 0px #2d5986; /* 1px in x direction to avoid small gap between shadows */
}
/* .shadow:after {
width: 10px; increased width
height: 100%;
top: 25px;
transform: skewY(45deg);
box-shadow: 10px 0px #2d5986;
} */
<div>
<span class="shadow">
A
</span>
</div>
<div>
<span class="shadow">
a
</span>
<span class="shadow">
b
</span>
</div>
<div>
<span class="shadow">
A B
</span>
</div>
<div>
<span class="shadow">
A B C
</span>
</div>
The main problem is the fact that we are now working with text-shadow instead of box-shadow, and as such the :before and :after pseudo classes don't work (although I attempted to make them work by attaching them to the <span>... and then made the width: 100%).
If there was a way to set the width and height of the text-shadow itself (which is achieved on a box-shadow by using the :before and :after pseudo classes), I feel this would be a piece of cake; however, all my research has not found how to do this for a text-shadow.
Does anyone know a way to make a flat long shadow for text with minimal CSS - potentially by somehow changing the width and height of the text-shadow?
Thank you.
Though this is no css-only answer, you might give it a try.
Basically, you create the according css in the browser via a short javascript snippet. The upside is, that it makes you very flexible - changing only two parameters instead of several tens of lines of css.
function addDropShadow(element,width,color){
let css = "";
for (var i = 1;i<width;i++){
css += `${color} ${i}px ${i}px,`;
}
css += `${color} ${width}px ${width}px`;
element && (element.style.textShadow = css);
}
let element = document.querySelector(".icon");
let color = "rgb(18, 128, 106)";
addDropShadow(element,15,color);
.container { padding: 50px; background: rgb(34,45,58); } .icon { font-family: "Helvetica Neue", helvetica, arial, sans-serif; font-weight: bold; color: #fff; background-color: rgb(22, 160, 133); height: 150px;width: 150px; font-size: 75px;line-height: 150px; text-align: center; display: block; overflow: hidden; }
<div class="container"><div class="icon">YO</div></div>
I don't think there is a good CSS only approach.
The only posibility that I can think of is creating pseudos with the same text as the base, and use to reduce the amount of shadows to one third:
Notice that the pseudo itself counts as a shadow because it has the color changed to the color of the shadow
.sample {
font-size: 70px;
position: relative;
text-shadow: 1px 1px red, 2px 2px red, 3px 3px red, 4px 4px red, 5px 5px red,
6px 6px red, 7px 7px red, 8px 8px red, 9px 9px red;
}
.sample:after, .sample:before {
content: attr(data-text);
z-index: -1;
color: red;
position: absolute;
}
.sample:after {
left: 10px;
top: 10px;
}
.sample:before {
left: 20px;
top: 20px;
}
<div class="sample" data-text="Sample">Sample</div>

How to create a border gap illusion

This is the illusion that I am attempting to create:
Notice that my designer wants the border cut off in the middle of the div, this is what I need to know how to do. I don't think overlapping with a z-index will work because of how the HTML is laid out.
This is the HTML code of which the structure may not be changed for maximum device compatibility, however, if adding an element is the solution, I believe that may be done:
<div id="nav_icons_con" class="mopn">
<div id="inner_nav_container" class="show_inner_nav">
<div class="nav_link_container">Home</div>
</div>
</div>
Here is the basic current CSS code:
#nav_icons_con {
z-index: 1;
cursor:pointer;
height: 5.005em;
width: 5.005em;background-image:url(background.png);
background-size:70%;
background-repeat:no-repeat;
background-position:center;
margin:.385em .385em 0 0;
}
#nav_icons_con.mopn{
background-color:#FFF;
border:2px solid #83C5E6;
border-bottom:none;
box-shadow:5px 5px 10px #666;
}
#inner_nav_container, .inner_nav_container{
cursor:pointer;
display:none;
position:absolute;
top:5.39em;
right:.385em;
width:12.5em;
white-space:normal;
background-color:#FFF;
border:2px solid #83C5E6;
border-top:none;
box-shadow:5px 5px 10px #666;
}
#inner_nav_container.show_inner_nav, .inner_nav_container.show_inner_nav{display:block;}
The typical way to do this is to position the tab element over the sub element, so as to cover up that section of the border. However, the use of box-shadow complicates this.
One way is to add another element inside the root element, so that the root element can still cast the shadow, but the element inside is positioned above. See my code below, for a basic example.
Working Example:
.icon {
width: 50px;
height: 50px;
position: relative;
/*Create the shape for the shadow.*/
border: 5px solid #83C5E6;
box-shadow: 5px 5px 10px #666;
}
.icon-content {
background: #fff;
position: relative;
/*Move back over the border.*/
top: -5px;
left: -5px;
/*Make tall enough to cover the top border.*/
width: 50px;
height: 55px;
/*Add border, except on the bottom.*/
border: 5px solid #83C5E6;
border-bottom: 0;
/*Position up a layer.*/
z-index: 1;
}
.nav {
position: absolute;
left: -5px;
top: 100%;
width: 400px;
padding: 1em;
background: #fff;
border: 5px solid #83C5E6;
box-shadow: 5px 5px 10px #666;
}
<div class="icon">
<div class="icon-content">
</div>
<div class="nav">
<div class="item">Home</div>
</div>
</div>

Div shifted to the right only in Firefox

The breadcrumbs part of the page is shifted to the right (in Firefox) with no apparent reason.
HTML:
<div class="region region-header">
<section id="block-easy-breadcrumb-easy-breadcrumb" class="block block-easy-breadcrumb">
<section class="content">
<div id="breadcrumbs-one">
</section>
</section>
</div>
CSS:
#breadcrumbs-one
{
border-width: 1px;
border-style: solid;
border-color: #FFFFFF #FFFFFF #E7E7E7;
box-shadow: 0 0 2px rgba(0, 0, 0, 0.2);
overflow: hidden;
width: 100%;
}
Here is the link to site:
http://www.vegus.lv/kursi
It's not in english.
Hope you can help.
try this please add clear:left on this below class
.region-header {
clear: left;
left: -19px;
position: relative;
top: -1px;
width: 953px;
}
OR
add float:left on this below class
.region-header {
float: left;
left: -19px;
position: relative;
top: -1px;
width: 953px;
}
I assume the issue is in #main. when you change your margin to -7px auto 40px; The things work.
Also, if you do not want to make changes to #main, you need to change the padding of #header, #footer CSS with 10px 10px 8px; values respectively.
There are 1px issues that have a conflicting inheritance or structural differences that tend to change the layout styles of some elements if not calculated properly.
Hope this helps.
Just add in CSS float :left.
#breadcrumbs-one {
border-width: 1px;
border-style: solid;
border-color: #FFFFFF #FFFFFF #E7E7E7;
box-shadow: 0 0 2px rgba(0, 0, 0, 0.2);
overflow: hidden;
width: 100%;
float: left;
}