I have this page where all the div's seem to work and then all of the sudden my last one breaks. I have two divs in my CSS, one being centeredRight and one centeredLeft. They are lined up down the page. But my last div on the left seems to get pushed to the right.
Here is my CSS.
.centeredlistleft {
width: 300px;
margin: 0 auto;
text-align: left;
border: 2px solid;
float: left;
margin-bottom: 25px;
padding-right: 10px;
}
.centeredlistright {
width: 300px;
margin: 0 auto;
text-align: left;
border: 2px solid;
float: right;
margin-bottom: 25px;
padding-right: 10px;
}
.body {
margin: 0 auto;
padding: 0;
text-align: center;
color: purple;
background-color: pink;
}
And here is my HTML.
<div id="sandrcontainer" class="body" style="width:700px">
<div id="onsieforbaby" class="centeredlistleft" >
<h3> Onesie for Baby </h3>
<ul>
<li>
Price
<ul>
<li>$10.00</li>
</ul>
</li>
<li>
Description
<ul>
<li>It's a boy onesie for a new baby boy. Carter onesies are used. Can ask for specific size. Can also make one for girls using pink.</li>
</ul>
</li>
</ul>
</div>
<div id="largetennistowel" class="centeredlistright">
<h3> Large Tennis Towel </h3>
<ul>
<li>
Price
<ul>
<li>$14.00</li>
</ul>
</li>
<li>
Size
<ul>
<li>16 x 26 (Inches)</li>
</ul>
</li>
<li>
Description
<ul>
<li> Cotton fleece. Very soft. Washes Well. Can be personalized. Check out the photo gallery for examples. Ask seller what color towels are available at time of order.</li>
</ul>
</li>
</ul>
</div>
</div>
<div id="sandrcontainer2" class="body" style="width:700px">
<div id="largegolftowel" class="centeredlistleft">
<h3> Large Golf Towel </h3>
<ul>
<li>
Price
<ul>
<li>$14.00</li>
</ul>
</li>
<li>
Size
<ul>
<li>16 x 26 (Inches)</li>
</ul>
</li>
<li>
Description
<ul>
<li> Golf towel. Elegant. Large white towel. Cotton fleece. Very soft. Can be personalized. Check out photo gallery for examples. Ask seller what color towels are avaiable at time of order. This towel has a grommet and can be hung on golf bags. Could also make this on fingertipe towel for guest bath or on linen towel for that elegant look.</li>
</ul>
</li>
</ul>
</div>
<div id="terrysmalltowel" class="centeredlistright">
<h3> Terry Small Towel </h3>
<ul>
<li>
Price
<ul>
<li>$11.00</li>
</ul>
</li>
<li>
Size
<ul>
<li>11 x 18 (Inches)</li>
</ul>
</li>
<li>
Description
<ul>
<li> With fringe. Made of 100% cotton loop terry. Can be personalized. Check out photo gallery for examples. Ask seller what color towels are avaiable at time of order.</li>
</ul>
</li>
</ul>
</div>
</div>
<div id="sandrcontainer3" class="body" style="width:700px">
<div id="contactmerands" class="centeredlistleft" >
<p> Please make sure to send me an email before any orders. I may not have the color towel you want but can always order more </p>
</div>
<div id="smallfingertip" class="centeredlistright" >
<h3> Small Fintertip Holiday Towel </h3>
<ul>
<li>
Price
<ul>
<li>$11.00</li>
</ul>
</li>
<li>
Size
<ul>
<li>11 x 18 (Inches)</li>
</ul>
</li>
<li>
Description
<ul>
<li> Terry small towel with decorated cat for xmas. Made of 100% cotton loop terry. Can be personalized. Check out photo gallery for examples. Ask seller what color towels are available at time of order.</li>
</ul>
</li>
</ul>
</div>
</div>
TLDR - ctrl f for "Contactmerands" and please explain to me why this box is getting pushed to the bottom RIGHT of the large golf towel box. It should appear under the large golf towel box just like the rest of the divs.
If you would like to see what I mean you can go to my school web portal where I have the page posted HERE.
When an element is floated, it is essentially removed from the flow of the document. Thus, when a parent element's children are all floated, the parent collapses upon itself as it doesn't have any defined dimensions.
To solve this, you could set either overflow:hidden or overflow:auto on the parent elements. This essentially forces it to contain the children elements, therefore preventing it from collapsing.
Add the following CSS and your problem is solved:
#sandrcontainer,
#sandrcontainer2,
#sandrcontainer3 {
overflow: hidden;
}
Sometimes changing the overflow property will conflict with existing CSS. You could alternatively use the pseudo element clearfix:
.clearfix:after {
content: '';
clear: both;
display: table;
}
You must clear your floats in order to achieve the desired effect.
I suggest using a valid clearfix for this.
You need to declare this in CSS:
.clearfix:after {
clear:both;
content:".";
display:block;
font-size:0;
height:0;
visibility:hidden;
}
.clearfix { display:block; }
Now wrap all your elements that should float next to each other in a DIV and apply the clearfix class:
<div class="clearfix">
<!-- put your divs here //-->
</div>
<!--put your last div here //-->
Related
How do I make the background color touch each end. I am fairly new to html and CSS below I have the code that I input for the background. Please let me know exactly what I need to change in my code. I know some of it needs to be changed I just don't know exactly what I need to change.
.black {
background-color: black;
font-size: 20px;
}
<div class="black">
<hr>
<h2 class="white">Documentation Examples</h2>
<a>
<ul class="documentations">
<li>
Savings or Checkings Accounts
</li>
<li>
Stocks, Dividends, Bonds or Debentures
</li>
<li>
Life Insurance Accounts
</li>
<li>
Escrow Accounts
</li>
<li>
Negotiable Instruments, Certified Checks, Money Orders, or Travelers Checks.
</li>
<li>
Safe Deposit Box Contents
</li>
<li>
Business Accounts
</li>
<li>
Corporation/Business Entity/Partnership
</li>
<li>
Governmental Agency Accounts
</li>
<li>
Miscellaneous Accounts
</li>
</ul>
</nav>
</a>
<br>
<br>
<br>
</div>
enter image description here
Nest your code in a body and use margin: 0; in your stylesheet. See below.
.black {
background-color: black;
font-size: 20px;
}
body {
margin: 0;
}
li {
color: white;
}
<body>
<div class="black">
<hr>
<h2 class="white">Documentation Examples</h2>
<a>
<ul class="documentations">
<li>
Savings or Checkings Accounts
</li>
<li>
Stocks, Dividends, Bonds or Debentures
</li>
<li>
Life Insurance Accounts
</li>
<li>
Escrow Accounts
</li>
<li>
Negotiable Instruments, Certified Checks, Money Orders, or Travelers Checks.
</li>
<li>
Safe Deposit Box Contents
</li>
<li>
Business Accounts
</li>
<li>
Corporation/Business Entity/Partnership
</li>
<li>
Governmental Agency Accounts
</li>
<li>
Miscellaneous Accounts
</li>
</ul>
</nav>
</a>
<br>
<br>
<br>
</div>
</body>
div tag always have margin and you have to remove it with margin : 0. and if you want to display black background-color on your entire screen you have to give height: 100vh
.black {
background-color: black;
font-size: 20px;
color: white;
height: 100vh;
}
.body {
margin: 0;
padding: 0;
}
Your code is correct, but you need to wrap the css in <style type="text/css">...</style> tags.
This should be in the <head>...</head> tag on your page:
<head>
<!-- title and other things go here -->
<style type="text/css">
.black {
background-color: black;
font-size: 20px;
}
</style>
</head>
You should remove all the paddings and margins by adding margin:0 and padding:0. Like this:
body {
padding: 0;
margin: 0;
}
This would remove all the paddings and margin so the background will be fully covered.
I've been trying to use
<ul style="text-align:center">
<li> 1794 - born in Berkeley, UK </li>
<li> 1821 - began his training as a doctor </li>
</ul>
Unfortunately, neither bullets and text align correctly, I've tried using divs and it still doesn't work.
This is what is happening:
This is what I want:
Try this simple code snippet
ul {
display: table;
margin: 0 auto;
}
<ul class="list">
<li class="list-item">1794 - born in Berkeley, UK</li>
<li class="list-item">1821 - began his training as a doctor</li>
</ul>
If you want to keep the list centered in the page/parent element, but have the list items aligned to the left, wrap the ul tag in a block container that has a text-align: center;, and set the ul as a display: inline-block; and text-align: left;.
Did you want this? https://codepen.io/anon/pen/WdyVPJ
Code
HTML
<ul class="list">
<li class="list-item">1794 - born in Berkeley, UK</li>
<li class="list-item">1821 - began his training as a doctor</li>
</ul>
CSS
ul {
text-align: left;
}
li {
text-align: center;
}
That's because you have to center the internal elements (<li>) while aligning to the left the external element (<ul>)
<ul style="text-align:left">
<li style="text-align:center"> 1794 - born in Berkeley, UK </li>
<li style="text-align:center"> 1821 - began his training as a doctor </li>
</ul>
Check the result here: https://jsfiddle.net/L1xmkof6/
I'm trying to figure out how to both place a caption beneath a picture and move text down. I'm trying to move the text that contains the second unorganized list down.
The figcaption with the text "Crazy Baby" appears on the top right of the picture it's supposed to be under. My understanding was figcaption would accomplish that although I'm clearly doing something wrong.
<div class="container">
<div class="jumbotron">
<div class="text-center">
<h1>The Golden Babies of 3 Orchard Lane</h1>
<p style="font-size: 30px;"><em>The Snady and Baby Maya</em></p>
<img src="http://oi63.tinypic.com/2ijkend.jpg" alt=" haha, sucks" class="Sandy">
<figcaption> <em>Snady Babushka</figcaption> </em>
<font size="5">
<ul>
<strong> Sandy loved</strong>
<li>Her red ball</li>
<li>Hiding in her jungle</li>
<li> Crossing her paws in an X</li>
<li> And most of all her big brother, Jonah </li>
</ul>
</font>
<br>
</div>
<img src="http://oi68.tinypic.com/8yb2f4.jpg" align="left" alt="I'm so sorry you can't see my baby face" class="Maya">
<figcaption><em>Crazy Baby</figcaption></em>
<font size="5">
<ul id="cap">
<div class="text-center">
<strong>Maya Loves</strong>
<li>Tennis balls</li>
<li>People more than dogs</li>
<li>Greeting someone as they enter the house</li>
<li> And of course, her big brother, Jonah</li>
</ul>
</div>
</font>
</div>
</div>
Without seeing your CSS, this is what I'd recommend trying. First thing I would do it make sure you tags are placed in the correct order. In your unordered list, you have the div starting inside the tag, but ending outside of it.
<ul id="cap">
<div class="text-center">
<strong>Maya Loves</strong>
<li>Tennis balls</li>
<li>People more than dogs</li>
<li>Greeting someone as they enter the house</li>
<li> And of course, her big brother, Jonah</li>
</ul>
</div>
Should look like this
<div class="text-center">
<ul id="cap">
<strong>Maya Loves</strong>
<li>Tennis balls</li>
<li>People more than dogs</li>
<li>Greeting someone as they enter the house</li>
<li> And of course, her big brother, Jonah</li>
</ul>
</div>
Then what you can do it with that div, give it a certain width, say the width of the image. Then float both the image and the list, left.
.text-center {
width: 100px; (Just an example)
}
.text-center img,
.text-center ul {
float: left;
}
I have an issue with a website I'm making. There are 2 lists inside of boxes all the text seems to be centered with the bullets out on the far left side of the text. I checked this on my local host and no issues were found there. But when I upload it to my web server the issue happens. I would like the text centered but the bullets closer to the text. Attached is the CSS and HTML for the boxes. Also a link to the file with the issue link (It's live but not linked publicly yet)
.centerDivR {
width: 80%;
height: 500px;
margin: 0 auto;
}
.rulesspace {
width: 4%;
height: 300px;
float: left;
}
.news2 {
width: 46%;
height: 300px;
background-color: rgba(192, 192, 192, 0.6);
float: left;
padding: 4px;
}
.rulesa {
width: 46%;
height: auto;
float: left;
padding: 4px;
}
.rulesb {
width: 46%;
height: auto;
float: left;
padding: 4px;
}
<div style="text-align: center; font size:12pt;"><span class="body">Server Rules||Route Specific Rules
||Local Information
||Train & Destination Tags<br></div></span>
<hr>
<div class="centerDivR">
<div class="rulesa">
<div style="text-align: center;">
<span class="h2"><i>General Rules:</i></span>
<br>
<br>
</div>
<ul>
<li>No Advertiseing other servers</li>
<li>Four Strike Policy
<ol>
<li>1st Warning</li>
<li>2nd Warning</li>
<li>2 Week Ban</li>
<li>Perminate Suspension</li>
</ol>
</li>
<li>Please keep foul language to a minimum</li>
<li>Be considerate of other players</li>
<li>Discussion or distribution of pirated or illegally acquired software is strictly prohibited</li>
</ul>
</div>
<div class="rulesspace"></div>
<div class="rulesb">
<div style="text-align: center;">
<span class="h2"><i>Multiplayer Server Rules:</i></span>
<br>
<br>
</div>
<ul>
<li>No spanwing trains with out dispatcher permission</li>
<li>No flipping switches while DS is on duty with out proper permission</li>
<li>No passing red signals without G or P plates</li>
<li>If a signal has stop indication but contains a G or P plate, stop, and ask DS to proceed at restricted speed</li>
<li>Flipping switches & dropping signals without proper permission while a train is approaching is strictly prohibited.</li>
<li>Hump Yard tags/settings are not to to be changed except by an Administrator.</li>
<li>For the UP and BN trackage, call signals LOWER than clear.
<br>(Clear Varients may be called)</li>
<li>Obey all Speed limits</li>
<li>Do not leave mainline switches open</li>
<li>Special trains (circus trains, OCS trains, etc. may be run only with administrator permission)</li>
<li>Running a track intended for traffic moving opposite your direction may be run ONLY with track warrant accompanying.</li>
<li>If you need to leave with other players on the same trackage, you may step away and hold the main for 15 minutes.
<br>If the limit is reached, your train will be saved and deleted for you to resume later.</li>
</ul>
</b>
</div>
</div>
You might have some mis-matched <div> elements or other markup errors, please valid your HTML and fix them.
If you do set the list items to be center aligned (or inherited from the containers). Try this:
li {
list-style-position: inside;
}
jsFiddle
body {
text-align: center;
}
li {
list-style-position: inside;
}
<ul>
<li>No Advertiseing other servers</li>
<li>Four Strike Policy
<ol>
<li>1st Warning</li>
<li>2nd Warning</li>
<li>2 Week Ban</li>
<li>Perminate Suspension</li>
</ol>
</li>
<li>Please keep foul language to a minimum</li>
<li>Be considerate of other players</li>
<li>Discussion or distribution of pirated or illegally acquired software is strictly prohibited</li>
</ul>
I have two headers enclosed inside one div. The div background color fills the first header but not the second. Why is this? I would assume that putting two divs inside one div would cause them to inherit the background color. I have done this before without problems. Thank you.
<div id="contain">
<header id="head_1">
<img src="images/Logos/Actlogo.png"/>
<p> P.O. Box 4524 </br>
Wattville </br>
</br>
(203) 444 - 4444 </br>
www.Acts4Peace.com
<p>
</header>
<!-- menu and statement -->
<header id="head_2">
<p>Keeping Families Warm in Winter</p>
<ul> <!-- main menu -->
<li> Furniture
<ul> <!-- submenu -->
<li> Couches </li>
<li> Chairs </li>
<li> Tables </li>
</ul>
</li>
<li> Clothing
<ul> <!-- submenu -->
<li> Women </li>
<li> Men </li>
<li> Kids </li>
</ul>
</li>
<li> Kitchen
<ul> <!-- submenu -->
<li> Utensils </li>
<li> Blenders </li>
<li> Baking </li>
</ul>
</li>
</ul>
</header>
#contain { /* main wrapper */
width: 1200px;
background-color: tan;
margin: auto;
}
#head_1 p { /* mailing address floated right */
float: right;
text-align: right;
font-size: 11pt;
}
#font-face {
font-family: cursive;
src: url(C:/Windows/Fonts/Cursive standard.ttf);
}
#head_2 p { /*second header paragraph, business mission*/
float: right;
font-family: "cursive standard";
font-size: 26pt;
}
Instead of using the header tag twice, I would put the two elements in separate divs, withing one . Then change the background of either , or the two divs inside.
<div id="contain">
<header>
<div id="head_1">
<img src="images/Logos/Actlogo.png"/>
<p> P.O. Box 4524 </br>
Wattville </br>
</br>
(203) 444 - 4444 </br>
www.Acts4Peace.com
<p>
</div>
<!-- menu and statement -->
<nav>
<p>Keeping Families Warm in Winter</p>
<ul> <!-- main menu -->
<li> Furniture
<ul> <!-- submenu -->
<li> Couches </li>
<li> Chairs </li>
<li> Tables </li>
</ul>
</li>
<li> Clothing
<ul> <!-- submenu -->
<li> Women </li>
<li> Men </li>
<li> Kids </li>
</ul>
</li>
<li> Kitchen
<ul> <!-- submenu -->
<li> Utensils </li>
<li> Blenders </li>
<li> Baking </li>
</ul>
</li>
</ul>
</nav>
</header>
</div>
#contain { /* main wrapper */
width: 1200px;
background-color: tan;
margin: auto;
}
#head_1 p { /* mailing address floated right */
float: right;
text-align: right;
font-size: 11pt;
}
#font-face {
font-family: cursive;
src: url(C:/Windows/Fonts/Cursive standard.ttf);
}
nav p { /*second header paragraph, business mission*/
float: right;
font-family: "cursive standard";
font-size: 26pt;
}
header {
background-color:#;
}
Although I can't recreate your issue (perhaps the window in JSFiddle isn't big enough), from your comment to Adam Ciardelli it appears this is a float issue. You can set overflow:hidden on .contain or use a clearfix:
#contain { /* main wrapper */
width: 1200px;
background-color: tan;
margin: auto;
overflow: hidden;
}
FIDDLE