This question already has answers here:
Image inside div has extra space below the image
(10 answers)
Closed 2 years ago.
I'm working on a front end project where I have created an "About us" section with some text and an image .
As you can see there is a small white gap under my image that I am trying to remove . I try adjusting margin , padding , height of the div element and the image but I am definitely missing something
My code :
#about-container{
width:100%;
height:auto;
background-color: white;
position: relative;
margin:0;
display:flex;
}
#about-container div{
margin:0;
padding:0;
height:auto;
}
#desc{
width:30%;
background-color:green;
}
#desc ul{
list-style-type: none;
margin:0;
padding:0;
}
#desc li{
padding:10px;
}
#about-img{
width:70%;
}
#about-img img{
width:100%;
height:500px;
}
<div id="about-container">
<div id="desc">
<h1> Our values </h1>
<ul>
<li>We care about our customer needs </li>
<li>We focus on the quality of our products & services offered </li>
<li>We invest in innovation and sustainable development </li>
<li>We care about the needs of society and vulnerable social groups</li>
</ul>
</div>
<div id="about-img">
<img src="IMAGES/about-img.jpg">
</div>
</div>
I would appreciate your help with this small task .
You can align them by using this CSS code:
#about-img img {
width: 100%;
height: 500px;
vertical-align: bottom;
}
Add vertical-align: top; to the image. Or simply add diaplay: block to the image
#about-container{
width:100%;
height:auto;
background-color: white;
position: relative;
margin:0;
display:flex;
}
#about-container div{
margin:0;
padding:0;
height:auto;
}
#desc{
width:30%;
background-color:green;
}
#desc ul{
list-style-type: none;
margin:0;
padding:0;
}
#desc li{
padding:10px;
}
#about-img{
width:70%;
}
#about-img img{
width:100%;
height:500px;
vertical-align: top;
}
<div id="about-container">
<div id="desc">
<h1> Our values </h1>
<ul>
<li>We care about our customer needs </li>
<li>We focus on the quality of our products & services offered </li>
<li>We invest in innovation and sustainable development </li>
<li>We care about the needs of society and vulnerable social groups</li>
</ul>
</div>
<div id="about-img">
<img src="https://www.w3schools.com/bootstrap/sanfran.jpg">
</div>
</div>
SOLUTION :
#about-container div{
margin:0;
padding:0;
height: 500px;
}
#about-img img{
width:100%;
height:100%;
}
Related
I'm trying to place an image behind my navigation bar and I want it fixed on the top right side of the page but I'm having a hard time trying to do so.
Here's what I want the page to look like:
This is my HTML:
<div class="navbarcn">
<div class="navbar">
<img src="bamboo.png">
<nav class="header">
<a class="active" href="javascript:;">HOME</a>
<a class="headl" href="menu.html">MENU</a>
<a class="headl" href="about.html">ABOUT</a>
</nav>
</div>
The CSS:
.navbarcn{
margin:0;
height:120px;
position:fixed;
width:100%;
}
.navbar{
float:right;
text-align:right;
width:100%;
height:200px;
}
.navbar img{
width:250px;
float:right;
}
.navbar a{
padding:10px;
text-decoration: none;
font-size:1.4em;
font-weight: bold;
}
First, you should not use an img for this kind of styling. Use CSS. (Here I have commented out the image).
<div class="navbarcn">
<div class="navbar">
<!-- <img src="bamboo.png"> -->
<nav class="header">
<a class="active" href="javascript:;">HOME</a>
<a class="headl" href="menu.html">MENU</a>
<a class="headl" href="about.html">ABOUT</a>
</nav>
</div>
Next, add some background properties to target your navbar.
.navbarcn{
margin:0;
height:120px;
position:fixed;
width:100%;
}
.navbar{
float:right;
text-align:right;
width:100%;
height:200px;
background-image: url(https://placekitten.com/100/50);
background-repeat: no-repeat;
background-position: top right;
}
/*.navbar img{
width:250px;
float:right;}
*/
.navbar a{
padding:10px;
text-decoration: none;
font-size:1.4em;
font-weight: bold;
}
Fiddle: https://jsfiddle.net/Lf4exsv7/
Using IMG vs CSS background-image: When to use IMG vs. CSS background-image?
Give .navbarcn background image
.navbarcn{
margin:0;
height:120px;
position:fixed;
width:100%;
background-image:url('bamboo.png');
}
.navnarcn's parent must explicitely have the css property position defined.
There are two solutions
Best way
.navbarcn{
background: url('path to your image')
}
Alternative way
.navbar img{
height: 35px
}
.navbarcn{
margin-top: -35px
}
using background would be a better solution but this is also fine
use absolute position for the image
.navbar{
position:relative;
}
img{
position: absolute;
top:5px;
right:5px;
display block;
z-index:-1;
}
Hi guys I'm starting to build my first site in html5+css3 beign responsive as a goal but I have a problem trying to add a video after the header. Thing is I need my video fills the total website width. I try with "width:100%" it doesn't works.
It works when I remove "display:flex;" of #body, but I think I will need this property since I'm planning to add flexible boxes inside of #body, and if I want put flexible boxes inside #body I need set it to "display:flex" right? Im new in html5&css3 so please correct me if I'm wrong.
If anybody could help me that would be great. Thanks!
HTML:
<!DOCTYPE html>
<html>
<head>
<link href="style.css" rel="stylesheet">
<link href='https://fonts.googleapis.com/css?family=Patua+One' rel='stylesheet' type='text/css'>
</head>
<body>
<header>
<div id="logo">
<img src="imagenes/logo.png"/>
</div>
<nav id="menuP">
<ul>
<li>ALL PRODUCTS</li>
<li>SERVICES</li>
<li>ABOUT</li>
<li>SAMPLES</li>
<li>QUOTE</li>
</ul>
</nav>
<nav id="menuS">
<ul>
<li id="account">ACCOUNT</li>
<li id="shop">SHOP</li>
<li id="contact">CONTACT</li>
</ul>
</header>
<section id="body">
<section id="slide">
<video loop id="videoSlide">
<source src="eu4_ost.webm" type="video/webm">
</video>
</section>
</section>
<footer>
</footer>
</body>
</html>
CSS
* {
margin:0px;
padding:0px;
}
header, section, footer, aside, nav, article, hgroup{
display:block;
}
html{
width:100%;
background:white;
height:100%;
font-family:Helvetica;
}
body {
display:flex;
background:gray;
justify-content:center;
max-width:2000px;
flex-direction:column;
}
/* -------------------------------- HEADER ------------------------------------ */
header{
width:100%;
background:#fabe06;
display: flex;
justify-content: center;
height:70px;
}
header nav ul{
list-style:none;
}
/* ----------------------------------- LOGO ------------------------------------- */
#logo{
margin:0px 0px 0px 32px;
width:260px;
display:flex;
align-items:center;
}
#logo img{
width:100%;
}
/* ----------------------------- MENU PRINCIPAL ---------------------------------- */
#menuP{
display:flex;
font-family:Patua One;
font-size:17px;
flex:2;
margin:0 50px;
justify-content:center;
align-items:center
}
#menuP ul li{
display:inline-block;
margin:0 15px;
}
#menuP ul li a{
text-decoration:none;
color:black;
}
/* ----------------------------- MENU SECUNDARIO ---------------------------------- */
#menuS{
flex:1;
display:flex;
justify-content:flex-end;
}
#menuS ul{
display:flex;
}
#menuS ul li a{
height:70px;
width:70px;
display:inline-block;
border-left:solid 1px;
border-color:#eab309;
text-indent:-99999px;
/*background:yellow;*/
}
#menuS ul li a{
}
header nav ul li#account a{
background-image:url(imagenes/account.png);
background-repeat:no-repeat;
background-size:contain;
background-position:center;
background-size:20%;
}
header nav ul li#shop a{
background-image:url(imagenes/shop.png);
background-repeat:no-repeat;
background-size:contain;
background-position:center;
background-size:25%;
}
header nav ul li#contact a{
background-image:url(imagenes/contact.png);
background-repeat:no-repeat;
background-size:contain;
background-position:center;
background-size:25%;
}
/*---------------------------- BODY -------------------------*/
#body {
width:100%;
background:yellow;
display:flex;
flex-grow:1;
}
#videoSlide{
width:100%;
}
Alright, so pretty simple, the thing is that even though the video has the width: 100% property, its parent does not. The percentage unit is used based on the parent's width or height, so if the parent is not full page width it won't work.
Just add this to your style.css:
#slide
{
width: 100%;
}
Also, just noticed you never closed the <nav> element .menuS so I'd do that if I were you to avoid further trouble.
Good luck.
Use two divs in the body and remove flex from body.
First div is video
Second is flex with main content
I've been having trouble applying clearfix to a number of divs, I've followed several tutorials, found here and here, but still my div named Bar will not expand to hold both the logo and nav divs.
Here is my markup, any and all advice would be greatly appreciated.
I have made the divs some strange colours to help see where they are ending and help with trying to see what is going on exactly.
<div id="bar" class="group">
<div id="nav">
<ul>
<li>Home</li>
<li>What We Do</li>
<li>Our Work</li>
<li>Our People</li>
<li>Contact Us</li>
</ul>
</div>
<div id="logo">
<img src="images/logo.png" title="" alt="" />
</div><!--Close Logo-->
CSS:
body{
margin:0;
}
.group:after {
content: "";
display: table;
clear: both;
}
#bar{
background-color: #e2871a;
width:100%;
}
/*NAVIGATION */
#nav{
color:#fff;
float:right;
margin-right:50px;
background-color:chartreuse;
}
#nav>ul{
list-style:none;
padding:0;
margin:0;
}
#nav>ul li{
display:inline;
}
#nav>ul a>li {
color:#fff;
padding-bottom:100px;
background-color:blue;
margin-right:15px;
}
#nav>ul a>li:hover{
border-bottom:3px solid white;
}
#logo{
float:left;
width:15%;
margin-left:5%;
background-color:red;
}
Problem is:
#nav>ul li{
display: inline;
}
Top/bottom padding or margin doesn't affect the height of inline elements relative to their parent. Make it block or inline-block
I have the following html and I am very confused about the following:
The .rowNumber & the .title will be the same height throughout all three boxes
The .rowNumberItems will not have the same amount of content in each column
How can I using CSS equal the columns so that my .button div is equal throughout all columns?
My columns are height:200px; by width:195px;
Example Column :
<div id="priceTable">
<div class="rowOne">
<p class="title">Name</p>
<ul class="rowOneItems">
<li>Custom Design</li>
</ul>
<div class="button">Buy Now</div>
</div> <!-- Column One -->
</div>
Current CSS:
#priceTable{
width:780px;
height:230px;
margin:0 auto;
overflow:hidden;
background:gray;
}
.rowOne, .rowTwo, .rowThree{
float:left;
height:225px;
width:195px;
margin:0 40px 0 0;
background:red;
}
#priceTable .title{
font-weight:bold;
text-align:center;
color:#000;
}
#priceTable .button{
background:green;
background:url('../images/button.png') no-repeat;
}
Fiddle: http://jsfiddle.net/iambriansreed/ZJhPq/
Add the following CSS:
.rowOne, .rowTwo, .rowThree {
position: relative;
}
#priceTable .button {
position: absolute;
bottom: 0;
}
Could you set the .rowNumberItems to certain height and overflow: hidden? Once the height of the rowNumberItems is fixed, the button locations would be equal.
.rowOneItems{height:200px;overflow:hidden;}
For example: http://jsfiddle.net/3bmrZ/
Since last week I am again trying to make a website after an absence of about 2 years. It went pretty well until I noticed that when I minimize the browser, the content does not stay in the wrapper.
I have been looking for solutions on this website and on google but I cant seem to find the right one. Most solutions mention problems with #float and overflow but I do not use float (hope that this is not the problem) and I have been playing with the overflow but I cant get it to work.
Below you can find the CSS and HTML code I used.
The HTML:
<div id="wrapper">
<div id="content">
<div id="header">
<div id="logo">
<img src="style/images/logo.gif" width="184" height="73" alt="logo" />
</div>
<div id="menu">
<ul id="navlist">
<li id="active">1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
</div>
</div>
<div id="main">
Title
subtitle
</div>
<div id="footer">
<div id="left_banner">
</div>
<div id="right_banner">
</div>
</div>
</div>
</div>
and the CSS
html, body, ul, li {
margin:0px;
padding:0px;
height:100%;
}
#wrapper {
text-align: center;
background:url(images/bg.gif);
background-repeat:repeat;
height:100%;
width: 100%;
overflow:auto;
}
#content {
background-color: #fff;
margin: 0px auto;
width: 780px;
height: 100%;
border-left:#fd5d78 4px solid;
border-right:#fd5d78 4px solid;
}
#header {
position:relative;
height:120px;
}
#logo {
position:absolute;
right:43px;
top:37px;
}
#menu {
position:absolute;
bottom:0px;
left:58px;
}
#main {
position:relative;
left:25px;
top:35px;
width:730px;
height:320px;
}
#footer {
position:relative;
width:730px;
left:25px;
top:70px;
background-color:#0F0;
clear:both;
}
#left_banner {
position:absolute;
left:0px;
width:349px;
height:134px;
border:#fd5d78 2px solid;
background-color:#FFF;
}
#right_banner {
position:absolute;
right:0px;
width:349px;
height:134px;
border:#fd5d78 2px solid;
background-color:#FFF;
}
Thanks a mil for your help.
Try adding display:block; to the #wrapper
jsfiddle
I know you said you don't use floats, but here is a solution using them. One of the biggest problems you had was you were setting the two footer banners to absolute positions, which throws off the 100% height on the parent div. With floats and overflow:hidden you are able to bring those divs back into the 100% calculation.
I had to make many changes to your css, so take what I have in the jsfiddle as your starting point.