I have this JsFiddle, and I can not figure out why the buttons extend outside of the divs.
How can I get them to be inside of the divs?
Here is the CSS
.btn-link {
font-variant: small-caps;
text-decoration: none;
font-size: 1.2em;
padding: 8px 15px 12px 15px;
border-radius: 3px;
background-color: #7dc36b;
color: #ffffff;
}
div.left-nav {
float: left;
width: 200px;
}
div.left-nav > div {
clear: both;
width: 100%;
border: solid 1px red;
}
Here is the HTML:
<div class="left-nav">
<div>new story
</div>
<div>My Stories
</div>
</div>
You can specify display:inline-block; on the buttons, so the div expands to hold the anchors completely.
.btn-link {
font-variant: small-caps;
text-decoration: none;
font-size: 1.2em;
padding: 8px 15px 12px 15px;
border-radius: 3px;
background-color: #7dc36b;
color: #ffffff;
display:inline-block;
}
Fiddle
div.left-nav > div {
overflow: auto; /* removed clear: both; */
width: 100%;
border: solid 1px red;
}
div.left-nav > div > a {
display: inline-block;
}
http://jsfiddle.net/ZjvZu/10/
Hey hope this works for you : -
demo
<div class="left-nav">
<div class="btn">new story
</div>
<div class="btn">My Stories
</div>
CSS:-
.btn-link {
font-variant: small-caps;
text-decoration: none;
font-size: 1.2em;
padding: 8px 15px 8px 15px;
border-radius: 3px;
background-color: #7dc36b;
color: #ffffff;
}
div.left-nav {
float: left;
width: 200px;
}
div.left-nav > div {
clear: both;
width: 100%;
border: solid 1px red;
}
.btn{
padding:8px 15px 8px 15px;
}
Related
I am having difficulty aligning the divs in the middle of the page. Hence I have used absolute positioning to place them in the middle.But when I try to do media queries its difficult to place them in the middle. Please any help is appreciated.
nav>ul {
position: absolute;
top: 114px;
text-align: center;
;
}
nav>ul>li {
list-style: none;
float: left;
}
nav>ul>li>a {
text-decoration: none;
font-family: 'Abel', sans-serif;
color: #fff;
font-size: 18px;
font-weight: bold;
padding: 10px 45px 10px 45px;
background: #20639B;
border-left: 3px solid #34F532;
}
.color2 {
height: 0px;
border-bottom: 45px solid #20639B;
}
<div class="color2">
<div class="header">
<nav>
<ul>
<li> Privacy</li>
<li> Terms of Use</li>
<li>Copyright</li>
<li>Trademark</li>
<li>Logos</li>
<li>Pay Transparency</li>
</ul>
</nav>
</div>
</div>
You were close. Just remove position: absolute from nav>ul, and remove the float: left from nav>ul>li and replace it with display: inline-block.
nav>ul {
padding-top: 10px;
text-align: center;
}
nav>ul>li {
list-style: none;
display: inline-block;
}
nav>ul>li>a {
text-decoration: none;
font-family: 'Abel', sans-serif;
color: #fff;
font-size: 18px;
font-weight: bold;
padding: 10px 45px 10px 45px;
background: #20639B;
border-left: 3px solid #34F532;
}
.color2 {
height: 0px;
border-bottom: 40px solid #20639B;
}
<div class="color2">
<div class="header">
<nav>
<ul>
<li> Privacy</li>
<li> Terms of Use</li>
<li>Copyright</li>
<li>Trademark</li>
<li>Logos</li>
<li>Pay Transparency</li>
</ul>
</nav>
</div>
</div>
Flexbox can be one way to go. Here a quick JS Fiddle that shows you how you can achieve what you want: https://jsfiddle.net/58u76mrn/13/
nav {
display: flex;
justify-content: center;
flex-wrap: wrap;
width: 100vw;
}
nav a {
text-decoration: none;
font-family: 'Abel',sans-serif;
color: #fff;
font-size: 18px;
font-weight: bold;
padding: 10px 45px 10px 45px;
background: #20639B;
border-left: 3px solid #34F532;
}
.color2 {
height: 0px;
}
Check this js fiddle
https://jsbin.com/geqovukozo/edit?css,output
nav{
position:absolute;
top:50%;
width:100%;
transform:translateY(-50%);
}
nav>ul {
text-align: center;
font-size:0;
}
nav>ul>li {
list-style: none;
display:inline-block;
}
nav>ul>li>a {
display:block;
text-decoration: none;
font-family: 'Abel', sans-serif;
color: #fff;
font-size: 18px;
font-weight: bold;
padding: 10px 45px 10px 45px;
background: #20639B;
border-left: 3px solid #34F532;
}
.color2 {
border-bottom: 45px solid #20639B;
}
Use positions with transform property in this case. and instead of float:left; use display:inline-block;
The links were all horizontally aligned until i put one of them in it's own div to change it's color when i'm on the page it is linking to.
Now i can't get him to go back in line.
<div class="navigation">
Mes productions
DJ
<a target="_blank" href="./CV.pdf">Mon CV</a>
<div id="contact">
Me contacter
</div>
</div>
.navigation {
padding: 40px 0px;
position: relative;
text-align: center;
width: 100%;
font-size: 30px;
}
.navigation a {
background: black;
border: 1px solid grey;
border-radius: 7px;
color: white;
display: inline-block;
margin: 100px 35px;
padding: 14px;
text-decoration: none;
opacity: 0.75;
font-family: impact;
}
.navigation a:hover {
background: white;
border: 1px solid black;
color: black;
}
#contact a {
background: white !important;
color: black !important;
display: inline-block !important;
}
You need to set display: inline-block on #contact, not #contact a.
Check this out I tried to center this inline-block but it is not working :( . I read couple of answer about similar issue but the solution; adding width and centering text is not working. Bellow is the codes. above is the codepen.
HTML:
body {
background: #34495e;
padding: 50px 0px;
}
.left.end {
border-bottom: 8px solid #8e44ad;
}
.right.end {
border-bottom: 8px solid #d35400;
}
.container {
background: #ecf0f1;
min-height: 480px;
width: 700px;
max-width: 100%;
margin: 0px auto;
}
.container h1 {
margin: 0px;
padding: 0px;
}
.right,
.left {
display: inline-block;
padding: 15px;
Font-weight: bold;
font-size: 20px;
color: #fff;
float: left;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.left {
width: 20%;
background: #2c3e50;
border-bottom: 1px solid #34495e;
}
.right {
width: 80%;
background: #16a085;
border-bottom: 1px solid #1abc9c;
}
.hright,
.hleft {
display: inline-block;
font-weight: bold;
font-size: 20px;
color: #fff;
float: left;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.hleft {
width: 20%;
background: #c0392b;
border-bottom: 1px solid #e74c3c;
line-height: 100px;
text-align: center;
}
.hright {
width: 80%;
background: #27ae60;
border-bottom: 1px solid #2ecc71;
padding-left: 10px;
line-height: 100px
}
.download {
width: 220px;
text-align: center;
margin: 0px auto;
-webkit-border-radius: 4;
-moz-border-radius: 4;
border-radius: 4px;
-webkit-box-shadow: 0px 2px 0px #000000;
-moz-box-shadow: 0px 2px 0px #000000;
box-shadow: 0px 2px 0px #000000;
font-family: Georgia;
font-size: 20px;
background: #2980b9;
padding: 25px 30px 25px 30px;
display: inline-block;
}
.download a {
color: #ffffff;
text-decoration: none;
}
.footer {
text-align: justify;
padding: 16px;
background: #2c3e50;
color: #7f8c8d;
}
<div class="container">
<div class="hleft">Back</div>
<div class="hright">
<h1>Drive Nuts</h1>
</div>
<div class="left">Size</div>
<div class="right">ID</div>
<div class="left">ID</div>
<div class="right">Datas</div>
<div class="left end">Hits</div>
<div class="right end">Datas</div>
<div class="download">DOWNLOAD NOW
</div>
<div class="footer">footer</div>
</div>
In order for text-align to work you need to specify it on a container, that container, in turn, will have centered text. Right now you have set text-align: center on the actual element you want centered.
EDIT:
Sample css:
.download {
text-align: center;
}
.download a {
color: #ffffff;
text-decoration: none;
width: 220px;
margin: 0px auto;
-webkit-border-radius: 4;
-moz-border-radius: 4;
border-radius: 4px;
-webkit-box-shadow: 0px 2px 0px #000000;
-moz-box-shadow: 0px 2px 0px #000000;
box-shadow: 0px 2px 0px #000000;
font-family: Georgia;
font-size: 20px;
background: #2980b9;
padding: 25px 30px 25px 30px;
display: inline-block;
}
This makes it so your .download-element works as awrapper telling everyting inside it to be centered. Than it applies your styling of the button to the <a/>-tag only.
EDIT 2:
For everyone recommending additional wrapper divs. Please don't. The link already has a wrapper and this HTML has the correct amount of elements (I would even argue one too many). It still has about 100% too many css-classes...
Unrelated to the question: This layout really looks like a table. No point in avoiding the <table/>-tag if the content is actually supposed to be a table of data.
Updated code
Give text-align: center to a parent element.
HTML
<div class="center">
<div class="download">DOWNLOAD NOW</div>
</div>
CSS
.center {
text-align: center
}
Wrap your download button in a container, and give the container the
text-align:center;
property:
body {
background: #34495e;
padding: 50px 0px;
}
.left.end {
border-bottom: 8px solid #8e44ad;
}
.right.end {
border-bottom: 8px solid #d35400;
}
.container {
background: #ecf0f1;
min-height: 480px;
width: 700px;
max-width: 100%;
margin: 0px auto;
}
.container h1 {
margin: 0px;
padding: 0px;
}
.right,
.left {
display: inline-block;
padding: 15px;
Font-weight: bold;
font-size: 20px;
color: #fff;
float: left;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.left {
width: 20%;
background: #2c3e50;
border-bottom: 1px solid #34495e;
}
.right {
width: 80%;
background: #16a085;
border-bottom: 1px solid #1abc9c;
}
.hright,
.hleft {
display: inline-block;
font-weight: bold;
font-size: 20px;
color: #fff;
float: left;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.hleft {
width: 20%;
background: #c0392b;
border-bottom: 1px solid #e74c3c;
line-height: 100px;
text-align: center;
}
.hright {
width: 80%;
background: #27ae60;
border-bottom: 1px solid #2ecc71;
padding-left: 10px;
line-height: 100px
}
.download {
width: 220px;
text-align: center;
margin: 0px auto;
-webkit-border-radius: 4;
-moz-border-radius: 4;
border-radius: 4px;
-webkit-box-shadow: 0px 2px 0px #000000;
-moz-box-shadow: 0px 2px 0px #000000;
box-shadow: 0px 2px 0px #000000;
font-family: Georgia;
font-size: 20px;
background: #2980b9;
padding: 25px 30px 25px 30px;
display: inline-block;
}
.download a {
color: #ffffff;
text-decoration: none;
}
.footer {
text-align: justify;
padding: 16px;
background: #2c3e50;
color: #7f8c8d;
}
.download-container{
text-align:center;
}
<div class="container">
<div class="hleft">Back</div>
<div class="hright">
<h1>Drive Nuts</h1>
</div>
<div class="left">Size</div>
<div class="right">ID</div>
<div class="left">ID</div>
<div class="right">Datas</div>
<div class="left end">Hits</div>
<div class="right end">Datas</div>
<div class="download-container">
<div class="download">DOWNLOAD NOW
</div>
</div>
<div class="footer">footer</div>
</div>
I just tried to create nested elements, but the inner element (subcategory) gets always bigger, then the parent element (category).
Please have a look at this JSFiddle:
JSFiddle: http://jsfiddle.net/d7vhpcmt/
HTML:
<div id="content" class="clearfix">
<section class="category boxed">
<section class="box_1"><header class="trigger trigger_aktiv"><h2>Category</h2></header>
<div class="content">
<section class="box_1 boxed"><header class="trigger"><h2>Subcategory</h2></header>
<div class="content"></div>
</section>
</div>
</section>
</section>
</div>
CSS:
.category {
background-color: #f8f8f8;
padding: 20px;
margin-bottom: 10px;
width: 100%;
max-width: 1600px;
float: left;
margin-right: 10px; }
.category a {
color: #262626;
text-decoration: none;
border-bottom: 0;
background-color: transparent;
display: block;
width: 100%; }
.category h1 {
font-size: 2.0em;
margin: 0 0 0.5em 0;
font-weight: 300;
line-height: 1em;
color: #262626;
letter-spacing: -1px; }
.box_1 {
background-color: #E9E9E9;
margin-top: 5px;
border: 1px solid #E2E2E2;
display: block;
width: 100%; }
.box_1:hover {
background-color: #eee; }
.box_1 header {
padding: 5px 0 0 50px; }
.box_1 .content {
background-color: #f2f2f2;
height:100%;
padding: 0.2em 0 0 0; }
.box_1 .content p { margin: 0.5em 0.8em; }
.box_1 .content h3 {
font-size: 1.2em !important;
margin-left: 0.3em; }
.box_1 .content .box_1 {
margin: 5px; }
It's because you have given .box_1 it a width of 100% and .content .box_1 and margin of 5px; this means your box is going to be 100% + 10px - instead of using margin try add padding to the parent container, this way you don't need to keep adding 5px margin to all it's children:
.box_1 .content {
background-color: #f2f2f2;
height:100%;
padding: 0.2em 5px 0 5px;
}
Example
If you are not worry about IE8 then use calc in your box_1 class.
.box_1 {
background-color: #E9E9E9;
margin-top: 5px;
border: 1px solid #E2E2E2;
display: block;
width: calc(100% - 10px);
}
DEMO
The problem is in this piece of code:
.box_1 .content .box_1 {
margin: 5px;
}
You are applying a margin around the entire section containing the Subcategori. Just edit in this way:
.box_1 .content .box_1 {
margin: 5px 0;
}
In order to remove the margin right and left.
Here is the JSFiddle.
I am trying to get start a web site for fun but I am having issues with CSS styles and tags with aligning I have a container, horizontal nav, left Nav, right Nav, Header and footer.
They are all in the container element but I can not align them properly. The header and norz nav are fine and so are the footers. The problem I am having is that the left body and right do not align properly can any one help. below is the coding for the HTML
<body>
<div id="container">
<div id="header">
</div>
<div id="horizontalnav">
<div class="navlinks ">
<ul>
<li>Facebook</li>
<li>Gaia</li>
<li>Roblox</li>
<li>Adventure Quest</li>
<li>Anime Freak</li>
<li>Youtube</li>
</ul>
</div>
</div>
<div id="leftnav">
<p>Left Nav </p>
</div>
<div id="body">
</div>
<div id="rightnav">
<p>right Nav </p>
</div>
<div id="footer">
this is the footer
</div>
</div>
</body>
and now for the css yes i use the one off of 2createawebsite.com and try to manipulate it
#container {
width: 100%;
}
#header {
width: 89%;
height: 15%;
position: relative;
background-image: url(Header.jpg);
border-bottom: 2px solid #000000;
}
#header a {
color: #ffffff;
text-decoration: underline;
font-weight: bold;
font-family: Verdana;
font-size: 14px;
}
#header a:visited {
color: #000000;
text-decoration: underline;
font-weight: bold;
}
#header a:hover {
color: #cc0000;
text-decoration: none;
font-weight: bold;
}
#horizontalnav {
width: 89%;
height: 30px;
position: relative;
background-color: #F2D6AF;
border-bottom: 2px solid #000000;
}
.navlinks {
position: absolute; top: 4px; left:240px;
}
.navlinks ul {
margin: auto;
}
.navlinks li {
margin: 0px 18px 0px 0px;
list-style-type: none;
display: inline;
}
.navlinks li a {
color: #000000;
padding: 5px 12px 7px;
text-decoration: none;
font-size: 16px;
font-family: Verdana;}
.navlinks li a:hover{
color: #ffffff;
background-image: url(Header.jpg);
text-decoration: underline;
}
#header p {
color: #000000;
font-family: Arial;
font-weight: bold;
}
.smalltext {
font-size: 9px;
font-family: Arial;}
#leftnav {
float: left;
width: 10%;
height: 70%;
background-color: #F8AA3C;
border-right: 1px dashed #694717;}
#rightnav {
float: right;
width: 10%;
height: 70%;
background-color: #F8AA3C;
border-left: 1px dashed #694717;}
#body {
margin-left :0px ;
width : 50% ;
padding: 0px 0px 0px 0px;
}
#body p {
word-wrap : true ;
font-family : courier new ;
}
#footer {
clear: both;
background-color: #D1C0A7;
}
If you change #header and #horizontalnav to 100% this makes everything expand to the width of the page; I assume this is what you wanted to accomplish
#header {
/* existing code */
width: 100%;
}
#horizontalnav {
/* existing code */
width: 100%;
}
As for the left column, body column and right column, these can be set to inline-block (float is not needed then) and their widths can be set to 10%, 80%, 10% respectively. In general this should fix the layout.