When using bootstrap to build the base of a website it creates some weird black, the black color is the body's color, margin on the right side of the header.
HTML:
<section id="header">
<div class="row">
<div class="content-wrapper">
<div class="col-md-6">
<div class="left">
<img src="#" alt="">
</div>
</div>
<div class="col-md-6">
<div class="right">
<nav>
<ul>
<li>a</li>
<li>b</li>
<li>c</li>
</ul>
</nav>
</div>
</div>
</div>
</div>
</section>
<section id="featured">
<div class="row">
<div class="col-md-4 box yellow">
</div>
<div class="col-md-4 box blue">
</div>
<div class="col-md-4 box red">
</div>
</div>
<div class="row">
<div class="col-md-4 box green">
</div>
<div class="col-md-4 box gray">
</div>
<div class="col-md-4 box white">
</div>
</div>
</section>
CSS:
body {
background: #000;
}
.content-wrapper {
max-width: 1100px;
margin: 0 auto;
}
.left {
float: left;
}
.right {
float: right;
}
section#header {
background: white;
height: 150px;
}
nav ul li {
display: inline-block;
}
.yellow {
background: yellow;
}
.red {
background: red;
}
.blue {
background: blue;
}
.green {
background: green;
}
.gray {
background: gray;
}
.white {
background: white;
}
.box {
height: 250px;
}
Here's a jsfiddle: http://jsfiddle.net/awu2cp6a/
The black on the right side is the background color.
The reason you only see it there is, because .row has margin-left/right: 15px;. If you remove/overwrite this to 0px, the black disappears or you add the row class to the element with the image.
EDIT
So if you would have an image, it would be OVER the black area, but because there is no image that fits in the full size, it's not displaying. Have you tryed give your section the row class?
Related
I am trying to make text appear (with some styling) upon hover. I tried to use display:none; and then with hover display:block; but this hasnt worked.
<div class="container-fluid sub-head">
<div class="row">
<div class="col-md left">
<div class="title">Title</div>
<div class="overlay">
<div class="overlay-content">
<p>
some text
</p>
<p>more text.</p>
</div>
</div>
</div>
<div class="col-md right">
<div class="title">other title</div>
</div>
</div>
</div>
.row {
background: #f8f9fa;
margin-top: 20px;
}
.col-md {
border: solid 1px #6c757d;
height: 100px;
}
.overlay {
height: 100%;
display:none;
}
.overlay:hover {
display: block;
}
fiddle is here;
http://jsfiddle.net/2dyvLf5o/14/
If you want to see content of p element (more text), you should define a class name for this element and set hover style to it`s parent div, I also put title inside overlay div
enter code here
.row {
background: #f8f9fa;
margin-top: 20px;
}
.col-md {
border: solid 1px #6c757d;
}
.overlay{
height:150px
}
.hidden-content {
display: none;
}
.overlay:hover .hidden-content{
display: block;
}
<div class="container-fluid sub-head">
<div class="row">
<div class="col-md left">
<div class="overlay">
<h1 class="title">Title</h1>
<div class="overlay-content">
<p>
some text
</p>
<p class="hidden-content">more text.</p>
</div>
</div>
</div>
<div class="col-md right">
<h1 class="title">other title</h1>
</div>
</div>
</div>
Use :hover on a parent element, like this:
.row {
background: #f8f9fa;
margin-top: 20px;
}
.col-md {
border: solid 1px #6c757d;
height: 100px;
}
.overlay {
height: 100%;
display: none;
}
.row:hover .overlay {
display: block;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="container-fluid sub-head">
<div class="row">
<div class="col-md left">
<div class="title">Title</div>
<div class="overlay">
<div class="overlay-content">
<p>
some text
</p>
<p>more text.</p>
</div>
</div>
</div>
<div class="col-md right">
<div class="title">Other title</div>
</div>
</div>
</div>
I'm trying to make a website with multiple sections and I'm encountering an issue in adding padding to the sections. I try to put the padding in the container, but it doesn't affect the individual divs. If I try to do it to the divs, it does it inside and the borders still touch. If I try and put the divs in more divs, it just doesn't go well. Whats going wrong? I'll show you my relative code:
.container {
width: 100%;
height: auto;
padding-top: 5%;
padding-right: 2%;
padding-left: 2%;
}
.secbox {
float: left;
width: 48%;
height: auto;
border: 5px solid red;
padding-top: 2%;
}
<div class="container">
<div class="secbox"> </div>
<div class="secbox"> </div>
<div class="secbox"> </div>
<div class="secbox"> </div>
<div class="secbox"> </div>
<div class="secbox"> </div>
</div>
<div class="container">
<div class="sec">
<div class="secbox"> </div>
<div class="secbox"> </div>
<div class="secbox"> </div>
</div>
<div class="sec">
<div class="secbox"> </div>
<div class="secbox"> </div>
<div class="secbox"> </div>
</div>
</div>
.container {
width: 100%;
height: auto;
border: 5px solid red;
display:table
}
.sec{
width:50%;
float:left;
box-sizing:border-box;
}
.secbox {
border: 5px solid red;
height: 20px;
margin:5px
}
Sample : Demo Link
I have been writing some code for a website, and I'm not able to vertically center text. I have read multiple answers on StackOverflow and other sites about how to vertically center html (mainly using the display:table and display:table-cell methods and the top:50%, transformY method), however, I am not able to implement either of these methods successfully. I have attached my code here, hoping that someone will be able to spot an error of my mine which is causing the code to not work. (In this code, I have used the top:50%, transformY method of vertically centering text). Any help would be greatly appreciated.
HTML:
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="stylesheet.css">
<title>Game Timer and Scorekeeper</title>
</head>
<body>
<div class="container-fluid">
<div class="row" id="heading">
<div class="col-xs-12">
<div class="positioner">
<h1>Game Timer and Scorekeeper</h1>
</div>
</div>
</div>
<div class="row" id="top-labels">
<div class="col-xs-3 labels teamlabel" id="a-label">
<div class="positioner">
<h2>Team A</h2>
</div>
</div>
<div class="col-xs-6 labels" id="gameclock-label">
<div class="positioner">
<h2>Game Clock</h2>
</div>
</div>
<div class="col-xs-3 labels teamlabel" id="b-label">
<div class="positioner">
<h2>Team B</h2>
</div>
</div>
</div>
<div class="row" id="thirdrow">
<div class="col-xs-3 pointsclock teampoints" id="pointsA">
<div class="positioner">
<h1>POINTS A</h1>
</div>
</div>
<div class="col-xs-6 pointsclock" id="gameclock">
<div class="positioner">
<h1>GAME CLOCK</h1>
</div>
</div>
<div class="col-xs-3 pointsclock teampoints" id="pointsB">
<div class="positioner">
<h1>POINTS B</h1>
</div>
</div>
</div>
<div class="row" id="fourthrow">
<div class="col-xs-3 ptcontclock ptcontrol" id="ptcontrolA">
<div class="positioner">
<h2>CONTROL A</h2>
</div>
</div>
<div class="col-xs-6 ptcontclock" id="questionclock">
<div class="positioner">
<h2>QUESTION CLOCK</h2>
</div>
</div>
<div class="col-xs-3 ptcontclock ptcontrol" id="ptcontrolB">
<div class="positioner">
<h2>CONTROL B</h2>
</div>
</div>
</div>
</div>
</body>
</html>
CSS:
.container-fluid {
width: 100vw;
height: 100vh;
}
#heading {
height: 15vh;
border: 2px solid;
}
#top-labels {
height: 10vh;
border: 2px solid;
width: 100vw;
}
#top-labels .labels {
border-right: 2px solid;
border-left: 2px solid;
}
#thirdrow {
height: 40vh;
border: 2px solid;
width: 100vw;
}
#thirdrow .pointsclock {
height: 40vh;
border-right: 2px solid;
border-left: 2px solid;
}
#fourthrow {
height: 35vh;
width: 100vw;
}
#fourthrow .ptcontclock {
border-right: 2px solid;
border-left: 2px solid;
height: 35vh;
}
.positioner{
height:100%;
width:100%;
position: relative;
top: 50%;
transform: translateY(-50%);
}
You can try this.
HTML
<main>
<div>
I'm a block-level element with an unknown height, centered vertically
within my parent.
</div>
</main>
CSS
body {
background: #f06d06;
font-size: 80%;
}
main {
background: white;
height: 300px;
width: 200px;
padding: 20px;
margin: 20px;
display: flex;
flex-direction: column;
justify-content: center;
resize: vertical;
overflow: auto;
}
main div {
background: black;
color: white;
padding: 20px;
resize: vertical;
overflow: auto;
}
<main>
<div>
I'm a block-level element with an unknown height, centered vertically within my parent.
</div>
</main>
check this link for reference https://css-tricks.com/centering-css-complete-guide/
I have a header it contains two divs [ left div and right div ] and offset 4-cols before them . What i want is to make the right div at the middle of the header .
.header
{
background-color: #FFF;
padding: 15px;
}
.header .left img { width: 90%; }
.header .right > div { display: inline-block; }
.header .right span { color: #0095AE }
.header .right > span:first-child { font-size: 22px; }
.header .right > div p
{
font-weight: bold;
font-size: 13px;
margin:0;
padding: 0;
color: #0095AE
}
.header .right > div p:first-child { text-align: right }
<div class="header">
<div class="row">
<div class="col-md-4 col-md-offset-4 ">
<div class="left">
<img class ="logo" src="images/logo.png">
</div>
</div>
<div class="col-md-4 ">
<div class="right">
<span>By</span>
<img src="images/crescent.png" >
<div>
<p> الهلال الأحمر الأردني </p>
<p> JORDAN RED CRESCENT </p>
</div>
</div>
</div>
</div>
</div>
This how it looks , I tried padding 50% but doesn't work as what i want.
enter image description here
Not sure how exactly you want it. But from what i understand ,you can make use of display:flex here
check this snippet
.header {
background-color: #FFF;
padding: 15px;
}
.row {
display: flex;
justify-content: center;
}
.col-md-4 {
display: flex;
}
.col-md-4:last-child {}
<div class="header">
<div class="row">
<div class="col-md-4 col-md-offset-4 ">
<div class="left">
<img class="logo" src="images/logo.png">
</div>
</div>
<div class="col-md-4 ">
<div class="right">
<span>By</span>
<img src="images/crescent.png">
<div>
<p>الهلال الأحمر الأردني</p>
<p>JORDAN RED CRESCENT</p>
</div>
</div>
</div>
</div>
</div>
Hope this helps
How to put banners side by side using HTML/CSS? Ideally with different sizes as shown below?
One simple way would be to display the banners inline-block, and assign them the required width.
.banner {
display: inline-block;
}
.banner-sm {
width: 32%;
}
.banner-lg {
width: 65%;
}
.banner {
height: 100px;
background: #DDD;
padding: 0; margin: 0;
}
<div class="row">
<div class="banner banner-lg"> </div>
<div class="banner banner-sm"> </div>
</div>
<div class="row">
<div class="banner banner-sm"> </div>
<div class="banner banner-sm"> </div>
<div class="banner banner-sm"> </div>
</div>
<div class="row">
<div class="banner banner-sm"> </div>
<div class="banner banner-lg"> </div>
</div>
Either use some grid system, or the bare CSS float property, pseudo example shown below:
.banner1 {
float: left;
width: 100px;
height: 20px;
margin: 4px;
border: 1px solid #777;
}
.banner2 {
float: left;
width: 200px;
height: 20px;
margin: 4px;
border: 1px solid #777;
}
.banner3 {
float: left;
width: 50px;
height: 20px;
margin: 4px;
border: 1px solid #777;
}
.clearfix {
clear: both;
}
<div class="banner1">banner</div>
<div class="banner1">banner</div>
<div class="clearfix"></div>
<div class="banner2">banner</div>
<div class="clearfix"></div>
<div class="banner3">banner</div>
<div class="banner3">banner</div>
<div class="banner3">banner</div>
<div class="banner3">banner</div>
<div class="clearfix"></div>
Good luck
You can use Twitter Bootstrap to get grid system and other useful layout functionality:
.row div {
height: 30px;
background: #aaa;
border: 1px solid #ddd;
}
* {
box-sizing: border-box;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='row'>
<div class='col-xs-8'></div>
<div class='col-xs-4'></div>
</div>
<div class='row'>
<div class='col-xs-4'></div>
<div class='col-xs-4'></div>
<div class='col-xs-4'></div>
</div>
<div class='row'>
<div class='col-xs-4'></div>
<div class='col-xs-8'></div>
</div>
<div class='row'>
<div class='col-xs-4'></div>
<div class='col-xs-8'></div>
<div class='col-xs-8'></div>
<div class='col-xs-4'></div>
</div>
If you are familiar with twitter-bootstrap then use its Grid system otherwise using inline-block will help you.
div {
border: 1px solid #ddd;
height: 200px;
margin: 5px;
display: inline-block;
box-sizing:border-box;
}
<section style="width:650px">
<div style="width:415px;"></div>
<div style="width:200px;"></div>
<div style="width:200px;"></div>
<div style="width:200px;"></div>
<div style="width:200px;"></div>
<div style="width:200px;"></div>
<div style="width:415px;"></div>
</section>
you can use CSS3 flex-box concept
.flex-container {
display: -webkit-flex;
display: flex;
width: 400px;
height: 250px;
background-color: lightgrey;
flex-direction:column;
}
.flex-item {
background-color: cornflowerblue;
width: calc(100% - 20px);
height: 100px;
margin: 10px;
display:flex;
justify-content:space-between;
}
.sub{
height:100%;
background:white;
box-sizing:border-box;
}
.one{
width:75%;
border:1px solid green;
}
.two{
width:25%;
border:1px solid red;
}
.subb{
width:33%;
background:white;
height:100%;
}
<div class="flex-container">
<div class="flex-item">
<div class="sub one">sub 1 </div>
<div class="sub two">sub 2 </div>
</div>
<div class="flex-item">
<div class="subb s3">sub 3 </div>
<div class="subb s4">sub 4 </div>
<div class="subb s5">sub 5 </div>
</div>
</div>
You can use Bootstrap to do this.
Bootstarp is a Powerful css framework which enables web developer's
to do stuff like these(dividing screens etc).
Bootstrap is very easy to learn and implement.
You can start Learning Bootstrap here