css width with an inline-block element - html

I'm trying to make a layout like this. All the banners have static dimensions and a bottom margin. And the article needs padding. The problem is the value of the width property of article. After locating the banners, I want to give the rest of the entire page width to article element. Here is my code:
#SidePane {
display: inline-block;
float: left;
}
.SideBanner {
display: block;
width: 250px;
height: 157px;
margin: 0 0 5px 0;
}
#SiteEye {
width: ???????????????????????;
height: 700px;
padding: 10px;
color: #4F2412;
background-color: #F9F6F4;
display: inline-block;
}
<div id="SiteCenter">
<div id="SiteEye">
<h1>title</h1>
<p>p1</p>
<p>p2</p>
</div>
<div id="SidePane">
<a href="">
<img class="SideBanner" src="images/banners/b1.jpg" alt="banner1" />
</a>
<a href="">
<img class="SideBanner" src="images/banners/b2.jpg" alt="banner1" />
</a>
<a href="">
<img class="SideBanner" src="images/banners/b3.jpg" alt="banner1" />
</a>
<a href="">
<img class="SideBanner" src="images/banners/b4.jpg" alt="banner1" />
</a>
</div>
</div>

You may use calc method:
width: calc(100% - 250px);
See can i use calc? before using it for it's browser compatibility.

RE: Comment on Bhojendra's answer
There is another way, it involves using box-sizing:border-box;, one of the most useful additions to CSS, like, ever!
I've also updated your images to use a top padding on all except the first one because you were causing some white-space at the bottom of the page with the previous method.
* {
box-sizing:border-box; /* Make all height/width inclusive of padding and border */
}
body {
margin:0;
padding:0;
}
#SidePane {
display: inline-block;
float: left;
}
.SideBanner {
display: block;
width: 250px;
height: 175px;
padding: 5px 0 0 0;
}
#SidePane a:first-child .SideBanner {
padding:0;
}
#SiteEye {
width: calc(100% - 250px);
height: 700px;
color: #4F2412;
background-color: #F9F6F4;
display: inline-block;
padding:10px;
}
<div id="SiteCenter">
<div id="SiteEye">
<h1>title</h1>
<p>p1</p>
<p>p2</p>
</div>
<div id="SidePane">
<a href="">
<img class="SideBanner" src="http://placehold.it/250x170" alt="banner1" />
</a>
<a href="">
<img class="SideBanner" src="http://placehold.it/250x170" alt="banner1" />
</a>
<a href="">
<img class="SideBanner" src="http://placehold.it/250x170" alt="banner1" />
</a>
<a href="">
<img class="SideBanner" src="http://placehold.it/250x170" alt="banner1" />
</a>
</div>
</div>

Related

Why do my images get smaller when I give them a margin-left or float them left?

This is the css for my social media bar. It's supposed to be on the right side of my page. When I use margin or float the images get really small.
.facebook {
width: 72.8%;
height: auto;
margin-left: -9%;
margin-top: 14%;
}
.insta,
.twitter {
width: 49.2%;
height: auto;
}
.social {
list-style-type: none;
position: fixed;
margin-left: 95%;
}
<div class="social">
<img src="https://facebookbrand.com/wp-content/themes/fb-branding/prj-fb-branding/assets/images/fb-art.png" class="facebook" alt="Facebook Logo">
</div> <br> <br> <br> <br>
<div class="social">
<img src="https://www.freeiconspng.com/uploads/-van-nederland-elgie-gaat-haar-ontwikkeling-posten-op-twitter-24.png" class="twitter" alt="Twitter Logo">
</div> <br> <br> <br>
<div class="social">
<img src="https://midflokkurinn.is/wp-content/uploads/2017/11/250ig.png" class="insta" alt="Instagram Logo">
</div>
The parent div has a standard with and height, if you give the child margins, it makes the space that it has smaller and smaller.
For example if you give something a height of 50px and a margin of 30xp its left with (50px - 30px) = 20px space to fill itself in.
U should give the images a height, for example
.facebook, .insta, ,twitter {
height: 50px;
width: 50px;
}
and then you can give it whatever margin you want.
You should wrap these in a container and set the positioning on that. Spacing the icons to the right with 95% left margin just isn't going to give you nice results. Set your a tags to display block and give your images consistent dimensions and you'll be set. Finally, using br tags is not good practice for spacing. It will give you nightmares if you ever need to adjust that spacing, say on mobile views for example. You'll want to use padding or margins instead. Here is an example:
#social-container {
position: fixed;
top: 10px;
right: 0px;
width: 20px;
}
.social {
display: block;
margin-bottom: 10px;
}
.social:last-child {
margin-bottom: 0px;
}
.social a {
display: block;
}
.social img {
display: block;
width: 20px;
height: 20px;
}
<div id="social-container">
<div class="social">
<a href="#">
<img src="https://facebookbrand.com/wp-content/themes/fb-branding/prj-fb-branding/assets/images/fb-art.png" class="facebook" alt="Facebook Logo">
</a>
</div>
<div class="social">
<a href="#">
<img src="https://www.freeiconspng.com/uploads/-van-nederland-elgie-gaat-haar-ontwikkeling-posten-op-twitter-24.png" class="twitter" alt="Twitter Logo">
</a>
</div>
<div class="social">
<a href="#">
<img src="https://midflokkurinn.is/wp-content/uploads/2017/11/250ig.png" class="insta" alt="Instagram Logo">
</a>
</div>
</div>

HTML Hover icon

I'm designing a very basic website only with HTML and CSS.
In the design, I added some icons, which are images. These images I've added them in my HTML. I want to create a hover effect with another image. Any thoughts?
Here is my HTML and CSS
.icon-group {
width: 100%;
margin: 0 auto;
text-align: center;
padding-bottom: 15px;
}
.view-icon,
.edit-icon,
.delete-icon {
width: 50px;
height: 50px;
display: inline-block;
padding: 10px;
}
<div class="card one">
<img class="avatar" src="images/avatar-01.jpg" alt="Foto Felipe Kaiser">
<p class="name">Felipe Kaiser</p>
<p class="position">Periodista</p>
<hr>
<div class="icon-group">
<div class="view-icon">
<a href="#">
<img src="images/view-icon.png" alt="Icono ver">
</a>
</div>
<div class="edit-icon">
<a href="#">
<img src="images/edit-icon.png" alt="Icono editar">
</a>
</div>
<div class="delete-icon">
<a href="#">
<img src="images/delete-icon.png" alt="Icono delete">
</a>
</div>
</div>
</div>
To add a different behaviour of css while hovering any item, you have to define this behaviour and add :hover to the container id/class. In your exemple, it may be :
.icon-group {
width: 100%;
margin: 0 auto;
text-align: center;
padding-bottom: 15px;
}
.icon-group:hover {
background-color: grey;
}
for exemple

Responsive images not flowing correctly

I have a layout and i'm trying to add in a row of images that will sit underneath the 'just arrived' section and no matter what i try the images keep flowing underneath each other.
Can anyone see what im doing wrong? Thanks!
That's because <li> elements are display: block by default. Give them float: left and you're all set.
.wrap {
float: left;
}
I have written a small code for you. check this.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
</head>
<style type="text/css">
body{
margin: 0;
padding: 0;
height: auto;
}
div.imagecontainer
{
width: 100%;
height: auto;
}
div.imagecontainer ul {
width: 100%;
height: 100%;
padding:0;
}
div.imagecontainer ul li{
list-style-type: none;
width: 20%;
height: 200px;
float: left;
}
div.imagecontainer ul li img
{
width: 100%;
height: 100%;
}
</style>
<body>
<div class="imagecontainer">
<ul>
<li><img src="https://cdn.shopify.com/s/files/1/1006/9816/files/Home-LisaKay.jpg?13639724066688423445"></li>
<li><img src="https://cdn.shopify.com/s/files/1/1006/9816/files/Home-LisaKay.jpg?13639724066688423445"></li>
<li><img src="https://cdn.shopify.com/s/files/1/1006/9816/files/Home-Blaithin_f3f568d3-849a-4271-a640-b2517965adda.jpg?16480572688008041262"></li>
<li><img src="https://cdn.shopify.com/s/files/1/1006/9816/files/Home-LisaKay.jpg?13639724066688423445"></li>
<li><img src="https://cdn.shopify.com/s/files/1/1006/9816/files/Home-LisaKay.jpg?13639724066688423445"></li>
</ul>
</div>
<script type="text/javascript">
$(window).resize(function(){
//alert("resizing");
var windowWidth = $(window).width();
if(windowWidth < 600)
{
$("div.imagecontainer ul li").css({"width":"100%","height":"400px"});
}
else
{
$("div.imagecontainer ul li").css({"width":"20%","height":"200px"});
}
});
</script>
</body>
</html>
but I used small jquery. you can change the conditions and I used all css ans js internally.
other thing is width and heidht and other things are depend on your need change those(number of images you decide to put in a line), as your need.
I think this may not 100% fit to your need.I recommend to use bootstrap.
copy past and try this.hope this will help to you.
They are flowing underneath each other because each image is wrapped with a block element, in this case a <div>. Remove the div or set it's display value to inline-block.
The smaller images have each a display value of list-item which positions the items like a vertical list as well.
inline-block
.wrapper {
text-align: left;
}
.wrapper a {
display: inline-block;
}
<div class="wrapper">
<a href="#">
<img src="http://placehold.it/300x200" alt="">
</a>
<a href="#">
<img src="http://placehold.it/300x200" alt="">
</a>
<a href="#">
<img src="http://placehold.it/300x200" alt="">
</a>
<a href="#">
<img src="http://placehold.it/300x200" alt="">
</a>
</div>
display block and floats
/* Clearfix */
.wrapper::after {
content: ''
clear: both;
display: table;
}
.wrapper a {
display: block;
float: left;
}
img {
/* Fixes whitespace below each image */
display: block;
}
<div class="wrapper">
<a href="#">
<img src="http://placehold.it/300x200" alt="">
</a>
<a href="#">
<img src="http://placehold.it/300x200" alt="">
</a>
<a href="#">
<img src="http://placehold.it/300x200" alt="">
</a>
<a href="#">
<img src="http://placehold.it/300x200" alt="">
</a>
</div>
Flexbox
Use this if you don't need to support old versions of Internet Explorer (<11).
/* Clearfix */
.wrapper {
display: flex;
flex-wrap: wrap;
}
.wrapper a {
width: 50%;
}
img {
/* Stretch the image for demo purposes */
width: 100%;
/* Fixes whitespace below each image */
display: block;
}
<div class="wrapper">
<a href="#">
<img src="http://placehold.it/300x200" alt="">
</a>
<a href="#">
<img src="http://placehold.it/300x200" alt="">
</a>
<a href="#">
<img src="http://placehold.it/300x200" alt="">
</a>
<a href="#">
<img src="http://placehold.it/300x200" alt="">
</a>
</div>

Picture on full width screen

I would like to cover the image on of my page the full width of the screen. (so not the whole screen but only the width) and if possible I would also like if the image shrinks if the screen gets smaller. I never did this before so i don't really know how I can make this? Can anybody help me?
this is how my page currently looks like
#charset "UTF-8";
body {
background-color: #ADF1F5;
}
html, body{
margin: 0;
padding: 0;
}
#Anouk {
text-align: center;
margin: 0 auto;
padding: 0;
}
#Anouk img{
display: block;
}
#header {
height: 80px;
background: #000000;
}
li {
display: block;
float: left;
}
li a {
color: #FFFFFF;
height: 80px;
}
#contact {
float: right;
}
<div id="Anouk">
<img src="logo/Hout.png" width="1000px" alt="Logo" />
</div>
<div id="header">
<div id="menu">
<!--Home-->
<li id="home">
<a href="index.html">
<img src="Iconen/Home.png" height="80px" alt="home" onmouseover="this.src='Iconen/Home2.png'" onmouseout="this.src='Iconen/Home.png'" />
</a>
</li>
<!--Over Mij-->
<li id="over">
<a href="over.html">
<img src="Iconen/Over.png" height="80px" alt="home" onmouseover="this.src='Iconen/Over2.png'" onmouseout="this.src='Iconen/Over.png'" />
</a>
</li>
<!--Portfolio-->
<li id="portfolio">
<a href="portfolio.html">
<img src="Iconen/Portfolio.png" height="80px" alt="home" onmouseover="this.src='Iconen/Portfolio2.png'" onmouseout="this.src='Iconen/Portfolio.png'" />
</a>
</li>
<!--Contact-->
<li id="contact">
<a href="contact.html">
<img src="Iconen/Contact.png" height="80px" alt="home" onmouseover="this.src='Iconen/Contact2.png'" onmouseout="this.src='Iconen/Contact.png'" />
</a>
</li>
</div>
</div>
You need to set your img to width="100%" or set a css class on the image for whatever %.
And you need to add:
margin: 0px;
padding: 0px;
To The body because some Browsers (like chrome) are having a standard margin and padding.
PS: I wanted to comment but I cant because my Reputation is to low :(

Where to put the sizing css? In li, a, or img?

I am making an mobile web app, and I ran into this problem.
Currently my code is structured as follows:
<ul class="app-lst">
<li class="item-1">
<a href="#">
<img src="img1.jpg" alt="img">
</a>
</li>
<li class="item-2">
<a href="#">
<img src="img2.jpg" alt="img">
</a>
</li>
... etc.
</ul>
CSS:
.item-1 {
width: 90%;
height: 10%;
}
.app-lst li a {
background-color: red;
}
.app-lst li a img {
}
Below image is the result I am trying to get. As you can see from the code above, Each boxes are <li>, and under it, there is <a> and under the link there is the content.
How would I go about with this for CSS?
-Should i adjust the box's size by putting width and height on <li> or <a>?
-Should i set the box's color by putting background-color on <a>?
-And finally, the image does not adjust to fit inside the parent <a>, so it extends the whole box if the image is larger. I tried putting "max-width: 100%" on the image, but no luck.
Also, since it is a mobile design I am controlling all the sizes with percentages. is this a good practice or should I do it with pixels?
Thank you so much in advance for your help!
You will need to use your <ul> as a container that is set to 100% height/width, and then size your <li> elements based on that. Then finally, make your <img> elements 100% height and width.
HTML
<ul class="app-lst">
<li class="item-1">
<a href="#">
<img src="http://placehold.it/150x150" alt="img"/>
</a>
</li>
<li class="item-2">
<a href="#">
<img src="http://placehold.it/150x150" alt="img"/>
</a>
</li>
<li class="item-3">
<a href="#">
<img src="http://placehold.it/150x150" alt="img"/>
</a>
</li>
<li class="item-4">
<a href="#">
<img src="http://placehold.it/150x150" alt="img"/>
</a>
</li>
<li class="item-5">
<a href="#">
<img src="http://placehold.it/150x150" alt="img"/>
</a>
</li>
</ul>
CSS
.app-lst {
display: block;
height: 500px;
list-style-type: none;
margin: 0;
padding: 0;
}
.app-lst li {
display: inline-block;
float: left;
margin: 0;
padding: 0;
}
.item-1, .item-2 {
height: 75%;
}
.item-1 {
width: 75%;
}
.item-2 {
width: 25%;
}
.item-3, .item-4, .item-5 {
height: 25%;
}
.item-3 {
width: 10%;
}
.item-4 {
width: 20%;
}
.item-5 {
width: 70%;
}
.app-lst li img {
height: 100%;
width: 100%;
}
JSFiddle: http://jsfiddle.net/b6x1byfp/