-1

I'm new in css and write this code for that purpose:
JSFIDDLE HERE!
want to achieve to this in resolution 1024:

screen: 1,024px
margins-left-right: 50px
columns: 58px
gutter: 12px


in my code can not set 50px margin for screen left and right ,how can i solve this problem?thanks all.
for more explain div col-1 margin left col-3 menu and margin right from screen.

Lini Susan V
  • 1,135
  • 1
  • 8
  • 25
ahbar ahbar
  • 11
  • 1
  • 5

5 Answers5

1

You can use media query to set different css rules for different screen sizes. Please refer following links.

Community
  • 1
  • 1
Lini Susan V
  • 1,135
  • 1
  • 8
  • 25
0

There are tons of resources on this sort of thing, for instance, see w3schools

.mystyle {
    margin: 0px 50px 0px 50px
}

or

.mystyle {
    margin-left: 50px,
    margin-right: 50px
}
0

Add your div inside a parent/wrapper container and provide margin to the container.

I would suggest you to go through the CSS Box model article at MDN.

Refer code:

$(document).ready(function() {

  var screenSize = screen.width;
  //alert('type='+jQuery.type(screenSize));
  if (screenSize == 1024) {
    $(".col-1").css("width", "58px");
    alert('width success!');

    $(".col-1").css("margin", "12px;");
    alert('margin success!');



  }

});
* {
  box-sizing: border-box;
}

.parent {
  margin: 0 50px;
}

.row::after {
  content: "";
  clear: both;
  display: table;
}

[class*="col-"] {
  float: left;
  padding: 15px;
}

.col-1 {
  width: 58px;
  background-color: chocolate;
  margin: 12px;
}

html {
  font-family: "Lucida Sans", sans-serif;
}

.header {
  background-color: #9933cc;
  color: #ffffff;
  padding: 15px;
}

.menu ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
}

img {
  display: block;
  margin-left: auto;
  margin-right: auto;
}

.menu li {
  padding: 8px;
  margin-bottom: 7px;
  background-color: #33b5e5;
  color: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
}

.menu li:hover {
  background-color: #0099cc;
}

body {
  background-color: darkgray;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="parent">
  <div class="header">
    <h1>Chania</h1>
  </div>

  <div class="row">

    <div class="col-3 menu">
      <ul>
        <li>The Flight</li>
        <li>The City</li>
        <li>The Island</li>
        <li>The Food</li>
      </ul>
    </div>

    <div class="col-1">
      <img src="https://assets.bwbx.io/images/users/iqjWHBFdfxIU/i7T6Dp0ts0sQ/v1/-1x-1.jpg" />
    </div>
    <div class="col-1">B</div>
    <div class="col-1">C</div>
    <div class="col-1">D</div>
    <div class="col-1">E</div>
    <div class="col-1">F</div>
    <div class="col-1">G</div>
    <div class="col-1">H</div>
    <div class="col-1">I</div>
    <div class="col-1">J</div>
    <div class="col-1">K</div>
    <div class="col-1">L</div>

  </div>
</div>
nashcheez
  • 5,067
  • 1
  • 27
  • 53
0

if you want custom margin on all four sides, it works clockwise i.e upper ,right,lower,left

 .custommargin{ margin: 0px 0px 0px 0px }

if you want to give same margin to upper,lower side and same to right,left side

.custommargin{ margin: 0px 0px }

if same margin on all 4 sides

.custommargin{ margin: 0px}
Saqib Javed
  • 120
  • 9
0

Instead of using $(document).ready(function(){}) use $(window).resize(function(){}) so that every time you resize your screen the function will load again.

Example:

$(window).on('resize', function(){
      var win = $(this); //this = window
      if (win.width() == 1024) { /* ... */ }
});

Reference: jQuery on window resize

Community
  • 1
  • 1
user3771102
  • 558
  • 2
  • 8
  • 27