I am now learning HTML and I have put a relative div in my code.
There are 2 more divs before that one but they don't collide, sadly the first two still take space above the relative one and I want it to be on top of the page.
My code :
.foo {
font-family: 'Tahoma';
font-size: 30px;
color: #fff;
background-color: black;
height: 180px;
width: 280px;
text-align: center;
position:relative;
left:540px;
border:5px solid #fff;
top:-50px;
}
.lastpage {
position:relative;
text-align:left;
width:20%;
}
.index {
position:relative;
text-align:left;
width:20%;
}
body {
background-color:lightgray;
text-align:center;
align-content:center;
color: #990099;
font-family: 'Tahoma';
font-size: 15px;
}
<div class="foo">
<br><br>F O O - B A R
</div>
<div class="lastpage">
<form method=get action="http://www.boomy.web44.net/CURRY.html/">
<button type="submit">Last Page</button>(2/2)
</form>
</div>
<div class="index">
<form method=get action="http://www.boomy.web44.net//">
<button type="submit">Index</button>
</form>
</div>
I want the "Foo bar" div to go up and be on the same level as the two buttons
I changed your CSS code :
.foo
{
float:right;
margin-right: 540px;
font-family: 'Tahoma';
font-size: 30px;
color: #fff;
background-color: black;
height: 180px;
width: 280px;
text-align: center;
position:relative;
border:5px solid #fff;
top:-50px;
}
.lastpage
{
position:relative;
text-align:left;
width:20%;
float:left;
}
.index
{
float:left;
position:relative;
text-align:left;
width:20%;
}
I added float:right and margin-right to your foo class and float:left to your lastpage and index class.
I think it should work for you !
Try adding the display: inline-block rule to make the divs appear on the same line, or float. By default, a div is block display and two divs won't come on the same line.
Another way of doing this is using the float: left property on the lastpage div to make it stay to the left and align it and the other div on the same line.
Does this solve your problem?
Related
I'm trying to make a navbar that fits the length of another div where I'm listing some data. I want it to be fixed to the top of the page no matter where you scroll. I have it like that, but when you resize the window from the right side and make it smaller, it'll eventually go off the page. I'm pretty sure it has something to do with the fact that I'm translating it over 50% and it's not caring if it's going off screen, so is there some sort of way to easily counteract that? I'd like it to behave the way the table does. When it's about to go off screen, stop moving it over. Thanks for any help
Here is a demonstration:
http://box.endurehosting.com/contents/public/Screen-recorder-fri-jan-03-2020-21-31-14.webm
Here's the live website:
https://dev.theromdepot.com/archive.php?home
Here is my HTML:
<div id="nav-bar">
<input id="search" placeholder="Search" type="input"></input>
</br>
</br>
<div id="title-bar">
<p>Name</p>
<p>Count</p>
</div>
</div>
Here is my CSS (I'm using SCSS)
$mainBackground: #1d1f21;
$textHoverColor: #919191;
#font-face {
font-family: 'Muli';
src: url('../fonts/muli.ttf') format('truetype');
}
body {
background-color:$mainBackground;
}
a {
color:white;
text-decoration: none;
transition: color .2s;
&:hover {
color:$textHoverColor;
transition: color .2s;
}
}
#nav-bar {
position:fixed;
width:25%;
min-width:800px;
left: 50%;
transform: translateX(-50%);
background-color:grey;
padding:10px;
z-index:1;
#search {
&::placeholder {
opacity:1;
}
position:relative;
border:none;
border-radius:2px;
padding:5px;
font-size: 20px;
line-height: 10px;
&:focus {
box-shadow:2px 2px 5px darkgrey;
}
}
#title-bar{
position:relative;
color: white;
p {
display:inline-block;
font-size: 16px;
font-weight: 600;
letter-spacing: 2px;
padding-bottom: 5px;
}
}
}
#list {
margin:auto;
width:25%;
min-width:800px;
color:white;
#results {
position:relative;
top:100px;
width:100%;
.row {
font-family: Muli;
font-size: 14px;
word-spacing: 2px;
position:relative;
width:100%;
height:18px;
padding-top:5px;
p {
display:inline-block;
position:absolute;
&:nth-child(1) {
// left:5%;
}
&:nth-child(2) {
left:51%;
}
&:nth-child(3) {
left:67%;
}
&:nth-child(4) {
margin:0;
left:82.5%;
}
}
}
}
}
The problem is your min-width property, which won't let it shrink under 800px. So when you are sizing the window down and passing 800px, the navbar stays the same width.
One solution could be using media queries in order when you reach the screen-width of 800pxs, you give the css property another value.
If that min-width attribute is not needed, since you are setting the width, you can just remove it and it will work.
I have a silly problem.
I want two texts to stay in the same line, but one text-align: left; and the other one text-align: center;
What's the correct way to do that?
.number{
text-transform:uppercase;
letter-spacing:1px;
text-align:left;
display:inline;
width: 50px;
margin-top:-10px;
float:left;
font-size:18px;
}
.menutitle{
display:block;
text-transform:uppercase;
letter-spacing:1px;
text-align:center;
font-size:18px;
margin-bottom:31px;
}
<span class="number">00</span><span class="menutitle">TEXT</span>
You can do this with Flexbox
.element {
display: flex;
}
.menutitle {
flex: 1;
text-align: center;
background: lightgreen;
}
<div class="element">
<span class="number">00</span>
<span class="menutitle">TEXT</span>
</div>
When including text in a div , i found a slight margin on top of the text.How to get rid of the margin ?
<html>
<style>
#box{
width:200px;
height:100px;
font-size:50px;
background-color:#ff0000;
color:#ffffff;
}
</style>
<body>
<div id="box">TEXT</div>
</body>
</html>
<html>
<style>
#box{
width:200px;
height:100px;
font-size:50px;
background-color:#ff0000;
line-height:38px; /* reduce line height for desired results */
color:#ffffff;
}
</style>
<body>
<div id="box">TEXT</div>
</body>
</html>
You need to change the line-height. I have it set here to have no space.
#box{
width:200px;
height:100px;
font-size:50px;
line-height: 33px;
background-color:#ff0000;
color:#ffffff;
}
You may use line-height indeed to reduce gap on top and beneath the text, but maybe you should use em values to have this more reliable.
#box {
width: 200px;
height: 100px;
font-size: 50px;
background-color: #ff0000;
line-height: 0.65em;
color: #ffffff;
box-shadow: 0 0 3px black;
}
div:hover {
font-family: courier;
}
span {
vertical-align: top;
font-family: courier;
}
<div id="box">TEXT<span>text</span>
</div>
This community has already been a big help. I have one noob question. I did do a search, but didn't turn up this situation, so apologies if this has been asked before.
I have a "nav" div currently sitting in a wrapper div. Nested in my nav div are three child elements that I want to position left, center, and right accordingly. I tried floating the three elements but they're all stacking on one side. I would like the logo div on the left, header in the center, and phone number on the right.
I know these can be positioned more precisely with absolute positioning, but since I'm trying to keep the layout as fluid as possible, is there another way?
Here is my HTML
<div class="wrapper">
<div class="nav">
<div class="logo"><em>BLI </em></div>
<div class="header"><em>California's Leader in Workers' Compensation</em></div>
<div class="phonenumber">Call us:<br>
909-256-0525</div>
</div>
And my CSS:
.wrapper{
min-width:1200px;
position:relative;
width:100%;
overflow:auto;}
.nav{
color:#FFFFFF;
font-size:1.563em;
font-weight:bold;
float:left;
font-family: Arial;
background-color:#C7C2C2;
width:100%;
height:80px;
display:inline;
}
.logo{
font-family: Georgia, "Lucida Bright", "DejaVu Serif", Georgia, serif;
font-weight: bold;
font-size: 2em;
width: 50px;
color: #0E2B5E;
top: 9px;
clear: both;
float: left;
}
.header{
text-shadow:black 0.1em 0.1em 0.2em;
padding-top:40px;
clear:both;
width:300px;
text-align:center;
float:left;
}
.phonenumber{
text-shadow: black 0.1em 0.1em 0.2em;
float: left;
font-size: 1em;
padding: 5px;
}
Any general responsive design tips would also be appreciated.
Thanks!
You can use display:table; on the wrapper and display:table-cell; on all its child elements.
This treats the wrapper div as if it were a table element with the width of 100%, and all its child elements as table cells. (http://www.w3schools.com/cssref/pr_class_display.asp)
.wrapper{
width: 100%;
height:auto;
display:table;
background-color:gray;
}
.logo{
display:table-cell;
text-align:left;
width:33%;
}
.header{
display:table-cell;
text-align:center;
width:33%;
}
.phonenumber{
display:table-cell;
text-align:right;
width:33%;
}
By making the wrapper 100% and its children 33%, its now responsive too!
I cleared out your current styling to make it easier for you to read.
Fiddle: http://jsfiddle.net/mLmcfrup/
Here i can solved your problem and it is fully Responsive css code and it is working in all browser's and change width according to browser size.It can be used in mobile, pc and other resolution. I hope it helps you.
Live Working Demo
HTML Code:
<div class="main">
<div class="left">left</div>
<div class="middle">middle</div>
<div class="right">right</div>
</div>
CSS Code:
.main
{
width:100%;
position:relative;
}
.left
{
width:20%;
float:left;
position:relative;
background-color:red;
}
.middle
{
width:60%;
float:left;
position:relative;
background-color:green;
}
.right
{
width:20%;
float:left;
position:relative;
background-color:blue;
}
Result:
To place the inner divs side-by-side, and keeping it fluid, use the css display properties table and table-cell.
.nav {
display: table;
width: 100%;
}
.nav > div {
display: table-cell;
}
Remove all the floats and stuff, and let the nav work like a table, placing it's children side by side like inline cells...
Here's a simple example of how it works (without all of your styling): http://jsfiddle.net/1co0qLx9/
Here are 2 best solutions of your concern.
I have created 2 fluid layouts based on your code.
First with "float" so that you could easily relate and implement quickly.
URL:- http://sandeepparashar.com/stackoverflow/fluid-layout-with-float.html
Second with "box-flex". Becasue float has been out dated and you would get a chance to know about new CSS3 properties. Also box flex has no width restriction.
URL:- http://sandeepparashar.com/stackoverflow/fluid-layout-with-box-flex.html
CSS Code with Float layout:
.wrapper {}
.nav {
width:100%;
vertical-align:middle;
box-sizing:border-box;
color: #FFFFFF;
font-size: 1.563em;
font-weight: bold;
font-family: Arial;
background-color: #C7C2C2;
height: 80px;
}
.logo {
font-family: Georgia, "Lucida Bright", "DejaVu Serif", Georgia, serif;
font-weight: bold;
font-size: 2em;
color: #0E2B5E;
float:left;
width:100px;
padding-top:10px;
}
.header {
text-shadow: black 0.1em 0.1em 0.2em;
text-align: center;
margin:0 200px 0 100px;
padding-top:25px;
}
.phonenumber {
text-shadow: black 0.1em 0.1em 0.2em;
font-size: 1em;
padding: 5px;
float:right;
width:200px;
padding-top:10px;
}
HTML DIV position changes with Float layout:
<div class="wrapper">
<div class="nav">
<div class="phonenumber">Call us:<br>
909-256-0525</div>
<div class="logo"><em>BLI </em></div>
<div class="header"><em>California's Leader in Workers' Compensation</em></div>
</div>
</div>
CSS3 Code with Box Flex layout:
.wrapper {}
.nav {
display:box;
display:-webkit-box;
display:-ms-flexbox;
display:-moz-box;
box-orient:horizontal;
-webkit-box-orient:horizontal;
-ms-box-orient:horizontal;
-moz-box-orient:horizontal;
-webkit-box-align:center;
-ms-flex-align:center;
-moz-box-align:center;
width:100%;
vertical-align:middle;
box-sizing:border-box;
color: #FFFFFF;
font-size: 1.563em;
font-weight: bold;
font-family: Arial;
background-color: #C7C2C2;
height: 80px;
}
.logo {
font-family: Georgia, "Lucida Bright", "DejaVu Serif", Georgia, serif;
font-weight: bold;
font-size: 2em;
color: #0E2B5E;
}
.header {
box-flex:1;
-webkit-box-flex:1;
-ms-flex:1;
-moz-box-flex:1;
display:block;
text-shadow: black 0.1em 0.1em 0.2em;
text-align: center;
}
.phonenumber {
text-shadow: black 0.1em 0.1em 0.2em;
font-size: 1em;
padding: 5px;
}
If required more help, Please most welcome :)
I am trying to make facebook style comment post area but css is not working. What I'm trying to do. When increased the height of the textarea i want to submit button move down at the same time. When you write a few lines in the textarea, you'll see the submit button does not go move down at the same time.
HTML
<div class="stcommenttext">
<form method="post" action="">
<div class="comtextarea">
<div class="yorumyazalani">
<textarea name="comment" class="comment" maxlength="200" id="" rows="2" cols="50" value="Add your comment here...."></textarea>
</div>
<div class="comgonder">
<input type="submit" value="" id="" rel="" class="comment_button wallbutton" />
</div>
</div>
</form>
</div>
CSS
.comment {
border:1px solid #fff;
width:425px;
margin-left:3px;
margin-top:3px;
font-family:'lucida grande', tahoma, verdana, arial, sans-serif;
font-size:12px;
resize:none;
background-color:#f4f4f4;
}
.comtextarea {
float:left;
width:494px;
margin-left:3px;
height:auto;
border:1px solid #d8dbdf;
background-color:#fff;
}
.comtextarea textarea {
min-height:30px;
}
.yorumyazalani {
float:left;
width:auto;
height:auto;
}
.comgonder {
float:right;
width:auto;
height:auto;
bottom:0px;
margin-left:-5px;
}
.wallbutton {
float:left;
background-color: #fff;
min-width: 32px;
padding: 4px;
text-align: center;
background-position: left bottom;
background-repeat: repeat-x;
border: 1px solid #fff;
color: white !important;
cursor: pointer;
font-size: 12px;
font-weight: bold;
margin-top: 7px;
padding: 5px;
margin-left:5px;
text-decoration:none;
background-image:url(https://scontent-a-fra.xx.fbcdn.net/hphotos-frc1/t1.0-9/10291103_828742610487379_816788942451910142_n.jpg);
background-repeat:no-repeat;
background-position:left;
outline:none;
}
Here is the DEMO
You can fix this in a couple of simple steps:
Set position: relative; on .comtextarea. Now each child can relate to it's container.
Set position: absolute; on .comgonder. Now you can position this element in relation to .comtextarea.
Set bottom: 5px; and right: 5px; on .comgondor. It now follows the right corner of .comtextarea.
Codepen Fork
Try this CSS for the button:
.comgonder {
width: auto;
height: auto;
margin-bottom: 8px;
vertical-align: bottom;
display: inline-block;
}
And this for the textarea:
.yorumyazalani {
width: auto;
height: auto;
vertical-align: top;
display: inline-block;
}
This will make your 2 form elements inline (instead of floating them) and allow the button to be aligned based on the bottom of the textarea, instead of the top.
Updated Demo: http://codepen.io/anon/pen/CdxDI
.comtextarea
{
position: relative;
}
.comgonder
{
position: absolute;
right: 0px;
bottom: 0px;
}
You can change the right/bottom offsets for better spacing/alignment if you like